Map document has no len()

2354
16
Jump to solution
03-26-2020 06:21 AM
PSGeo
by
Occasional Contributor

well... I have been trying to use add-in to make simple button that had a date and current mxd name to features in the fcs in the gdb in use. still not working. I really don't understand how to use making addin.

I decided to give it a go using Arctoolbox  as it looks simpler. 

In first place with three input variables: date; file location (folder path); and file.

It works.

But I want to reduce the number of input variables. I was thinking to use 'current' and skip the file location and file manual input. The help on this says is that is not possible to use it in the background, therefore I made it run on foreground... however when I tried gave the following error. 

I need some guidance on this because maybe it is impossible to use toolbox for this or maybe there is a workaround... anything.

cheers

P

Python errors:
Traceback Info:
File "\\eusc.europa.eu\ATLAS\Home\psoares\Documents\python\filesupporttools\uploadcurrentMXD_vectors_TOOLBOX_version.py", line 93, in <module>
issue_code = os.path.basename(mxdInicio)

Error Info:
<type 'exceptions.TypeError'>: object of type 'MapDocument' has no len()

GP errors:

line 93 code is the following:

    # mxd and environment; and gdb sources and targets
    mxdInicio = arcpy.mapping.MapDocument('current')
    mxdPath = mxdInicio.filePath


    issue_code = os.path.basename(mxdInicio) ## line 93
    issue_code = issue_code[0:19]
    issue_code = issue_code.replace("_"," ")
    mxdPathList = mxdPath.split(os.sep)

    IssueGDB =  "\\".join(mxdPathList[:-1])
    print IssueGDB
0 Kudos
16 Replies
PSGeo
by
Occasional Contributor

Hi guys,

thanks for the: 

print (arcpy.AddMessage(mxdInicio.filePath))

with that i figure it out the problem:

    mxdInicio = arcpy.mapping.MapDocument('current')
    arcpy.AddMessage(mxdInicio.filePath)
    mxdPath = mxdInicio.filePath

    issue_code = os.path.basename(mxdPath)‍‍‍‍‍‍‍‍ # i figure it out that I was calling the wrong variable...

by the way, I took this time because the question came from the other side of the Atlantic

thanks guys, tool is finished.

cheers

Pedro

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It is common practice/courtesy to mark comments "Helpful" if people's comments are, well, helpful.  Looking over the discussion now, not a single comment has been marked Helpful.  Also, if one comment was particularly helpful, that one can be marked Correct to close out the discussion.  Or, the question can be marked "Assumed Answered".

PSGeo
by
Occasional Contributor

You are right and I apologize

0 Kudos
DanPatterson_Retired
MVP Emeritus

https://community.esri.com/message/918013-re-map-document-has-no-len?commentID=918013#comment-918013 

and next time please read the code samples, with the highlights... you could have been done much sooner

0 Kudos
DanPatterson_Retired
MVP Emeritus

ArcGIS Pro has it... you can even open a Jupyter Notebook in your project for quick testing and 'dir' away on objects to find out what they have.

Pro has some nifty features... don't know if they are available in arcmap

0 Kudos
PSGeo
by
Occasional Contributor

i have no arcgis pro

0 Kudos
DanPatterson_Retired
MVP Emeritus

Then add these lines to your script and devolve the project path relative to the running script in the toolbox.

import sys

script = sys.argv[0]

Then you can find the location of the script and if your project is located 'relative' to it, you should be able to construct the project name and location.

script

'C:\\Git_Dan\\npgeom\\_load_sample_.py'