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.
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.
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)
<type 'exceptions.TypeError'>: object of type 'MapDocument' has no len()
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
Solved! Go to Solution.
issue_codeos 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
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?
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.