Select to view content in your preferred language

Map document has no len()

3029
16
Jump to solution
03-26-2020 06:21 AM
PSGeo
by
Regular 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
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

What do you get with

print (arcpy.AddMessage(mxdInicio.filePath))

View solution in original post

0 Kudos
16 Replies
DanPatterson_Retired
MVP Emeritus
issue_code = os.path.basename(mxdInicio)

Did you try to print  issue_code?  If it doesn't print anything, it can't be sliced on the next line since it has no length and you can only slice things that have a __len__ property

0 Kudos
PSGeo
by
Regular Contributor

indeed... the print (arcpy.AddMessage (mxdInicio)) gives me this:

<geoprocessing Map object object at 0x239FB400>

I assume that 'current' doesn't work even if make the tool to run in foreground.

do u agree?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

You appear to want to work with the MXD path, so why not just use the mxdPath variable that you have already defined and set?

0 Kudos
PSGeo
by
Regular Contributor

the mxd path is from the current mxd... how do I get it? if the :

arcpy.mapping.MapDocument('current')

apparently doesn't work for toolboxes.

I don't set it anywhere else in the script

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I have regularly used arcpy.mapping.MapDocument("CURRENT") in scripts for toolboxes.  The only issue I have had to watch for is when someone has opened a new MXD and not saved it yet because in that case MapDocument.filePath returns an empty string.

PSGeo
by
Regular Contributor

So what is wrong there in what i am doing?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What do you get with

print (arcpy.AddMessage(mxdInicio.filePath))

0 Kudos
DanPatterson_Retired
MVP Emeritus

apparently he didn't try... I highlighted those in my previous post

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Sometime the second time is the charm, or is it the third....

0 Kudos