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
Solved! Go to Solution.
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
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?
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?
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
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.
So what is wrong there in what i am doing?
What do you get with
print (arcpy.AddMessage(mxdInicio.filePath))
apparently he didn't try... I highlighted those in my previous post
Sometime the second time is the charm, or is it the third....