Hello,
The following code works fine when I copy and paste it to the python command window.
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] df.name
It produces the following errors when I run the script in the Python shell (F5) and similar errors if I try to use it as a script from a toolbox.
Traceback (most recent call last):
File "C:\gisdata\python\test.py", line 3, in <module>
mxd = arcpy.mapping.MapDocument("CURRENT")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\arcobjects\mixins.py", line 441, in __init__
super(MapDocumentMethods, self).__init__(mxd)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\arcobjects\_base.py", line 47, in __init__
for arg in args))
RuntimeError: Object: CreateObject cannot open map document
Is there something special I need to add/setup etc, to run in those other modes?
Never mind. I figured out that I didn't have the "Always run in foreground" check box selected as needed when using "CURRENT".
Thanks,
Scott
Thank you for the clarification, concerning CURRENT and REFERENCE FILE PATH!
@Freddie Gibson, I am writing a small automation to create a view, register the view in Geo database and publish it as a service. So far good with creating a view and register with Geo database but I am trying to save the mxd before publishing it and its not working out. I saving the registered view in following ways and not working
mxd = arcpy.mapping.MapDocument("C:\GIS\testfile.mxd") Error: AssertionError: Invalid MXD filename. ------------------------------------------------------------mxd = arcpy.mapping.MapDocument("CURRENT") Error : RuntimeError: Object: CreateObject cannot open map document
I get this error running from ArcMap 10.5 when when I insert my script tool into a ModelBuilder model. Both the original script tool and the ModelBuilder tool are set to run in the foreground. I do not get the error if I use the script tool outside of ModelBuilder.
Seth, I would recommend starting a new question post/thread. INclude a few more details, the exact error and if possible, the python code in question following https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?s...
also, you can tag other groups with the @ and the group name like @modelbuilder
I am writing a small automation to create a view, register the view in Geo database and publish it as a service. So far good with creating a view and register with Geo database but I am trying to save the mxd before publishing it and its not working out. I saving the registered view in following ways and not working
mxd = arcpy.mapping.MapDocument("C:\GIS\testfile.mxd")
Error: AssertionError: Invalid MXD filename.
------------------------------------------------------------
mxd = arcpy.mapping.MapDocument("CURRENT")
Error : RuntimeError: Object: CreateObject cannot open map document