I have an ArcMap 10.5 ModelBuilder model that contains within it a script tool referencing the 'CURRENT' mxd. Both the script tool and the ModelBuilder tool are set to run in the foreground. The script tool runs fine outside of ModelBuilder, but the ModelBuilder model that contains the script tool throws a runtime error at
mxd = arcpy.mapping.MapDocument("CURRENT")
The error message is:
Traceback (most recent call last):
File "T:\OSPR_Data\Ospr_Tools\GIS\ArcGIS\OSPR\Utilities\scripts\Seth\FlowModel 18 TBX.py", line 661, in <module>
main()
File "T:\OSPR_Data\Ospr_Tools\GIS\ArcGIS\OSPR\Utilities\scripts\Seth\FlowModel 18 TBX.py", line 657, in main
Part4()
File "T:\OSPR_Data\Ospr_Tools\GIS\ArcGIS\OSPR\Utilities\scripts\Seth\FlowModel 18 TBX.py", line 556, in Part4
mxd = arcpy.mapping.MapDocument("CURRENT")
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects\mixins.py", line 652, in __init__
super(MapDocumentMethods, self).__init__(mxd)
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects\_base.py", line 47, in __init__
for arg in args))
RuntimeError: Object: CreateObject cannot open map document
Is this a bug, or is there a way to reference the 'CURRENT' mxd in a script within ModelBuilder?
