I would like to get away from it, but it was the only way I could think of to add a dynamic variable that the user could change. I'm getting errors with the code suggestions above to try and strip the file path. I get the following error:
>>> import arcpy
>>> import arcpy.mapping as map
>>> mxd = map.MapDocument("CURRENT")
>>> mapname = str(mxd.filepath).split('\\')[-1:]
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'MapDocument' object has no attribute 'filepath'
>>>
Just as you have suggested, I went ahead and gave literal values in place of the variables and I get the following:
... # Part 3:
... # Map to KML tool
...
... # Set current workspace
... # env.workspace = "C:\Users\cpotts\Desktop\Test_Folders"
...
... # Set local MapToKML variables
... inputMap = mxd
... outputKML = "output_test.kmz"
...
... # Execute MapToKML
... arcpy.MapToKML_conversion(inputMap, outputKML)
...
...
...
...
Runtime error
Traceback (most recent call last):
File "<string>", line 46, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 2278, in MapToKML
raise e
RuntimeError: Object: Error in executing tool
As per this LINK there are 10 conditions that are within the MapToKML tool, and I wonder if they're all required in order for the tool to run. If that is the case, hothw do you configure pyon to simply run with the defaulted value instead of having to set that parameter. When I run the tool manually, the data frame that it selects defaults to the only data frame in our map, which is again named identically to the map document, thus leading to the same issue as stated above where I still need to get the map name into a string so I can use it as a variable.
I suppose I could change our map template to have a static data frame name, which I could then hard code into the script since it would never change, but I don't want to do that unless I have to.
The image below shows the inputs that I use when I manually run the tool. I choose my mxd, it defaults to the only data frame in the map, I name the output file, and then I set the extent properties to match that of one of the feature classes. Every other input I leave as the default value.
Thanks again for all the help guys! I think we're getting closer to a solution . This is the first script that I have ever tried to construct to run ArcMap tools, so I'm definitely at the forefront of the beginners stage lol.