I have Python code that creates a file geodatabase on the user's local data directory, creates some features in the .gdb (involves copying features, merging, intersecting, etc.) and results in a feature class in that local .gdb that I then want to add to the current map document, to show the results of all the Python/arcpy processing for the user that ran the tool.
The issue is that in 10.2 arcpy.MakeFeatureLayer_management does not add my final feature class to the current map document's TOC, So I use arcpy.mapping.Layer to make a layer of my final product and then use arcpy.mapping.AddLayer to add the layer to the current map document. Works great.
But then the tool gets run on a different user's machine that's running ArcMap 10.1 and MakeFeatureLayer_management barks with an error '000733' - output layer is same as input layer. So I remove the arcpy.mapping code and just let MakeFeatureLayer_management work with the single parameter and now my results get added to the current map's TOC!
(this is all 32-bit python/geoprocessing)
The on-line documentation for 10.1 and 10.2 for MakeFeatureLayer_management don't mention any difference in behavior concerning whether the dataset's layer gets added to the current map document.
under Map Document Properties, is add the results of geoprocessing operations toggled on? on both machines and/or projects
Using geoprocessing options to control tool execution—Help | ArcGIS for Desktop
Hmmm... how to make sense of this question...
I'm guessing that you're referring to the "Add results of geoprocessing operations to the display" that is a check box on the Geoprocessing Options dialog box. There is no comparable setting in the "Map Document Properties" dialog box that I can see. Furthermore, "Geoprocesing Options" are not a property of a map document (.mxd), but are application/user settings. (I can demonstrate this to myself by using 2 separate .mxd documents (map documents) and turning off "Add results of geoprocessing..." while in one map document, closing that map document (without saving), opening a different .mxd and seeing that the geoprocessing option is now turned off; and likewise for turning it on.)
Our default installation is that "Add results of geoprocessing..." is turned on for every user/machine installation. And, it would surprise me *very* much if our users were sophisticated enough to go fiddling with the Geoprocessing Options. Turning that off or on is completely unnecessary for our workflow.
Notwithstanding, I did check my 10.2 installation (where I developed the Python script) and I checked the user's 10.1 installation (where the script was used) and both had "Add results of geoprocessing ...." checked on.
And, just in case you think to ask, the python script does not make any reference to the arcpy.env.addOutputsToMap setting (i.e. it neither reads it nor sets it).
OK... can't do the image thing on the iThingy.... but environment settings can be accessed via code. Any process that produces a result layer can be added to the display via the interface (through geoprocessing options or map document properties) or via code. You might want to check both settings, those in the geoprocessing options and those in the map document properties. For code, check...
specifically addOutputsToMap
to ensure (I hope) that results will get added regardless of the other two settings.
As for modelbuilder, then you should be able to access/ensure that environment parameters are set during model construction
thanks Darren for the correction
the env.addOutputsToMap applies to outputs created from the command line or from the tool dialog, not scripts.
Curtis, I had suggested that earlier but wasn't sure whether it applied to modelbuilder as it does to the other two.
It does. If you have a ModelBuilder output parameter that's a feature class, and you run the model as a tool, it gets added to the map.
This is a bit off the subject - specific to ModelBuilder:
* The add to map 'tag' you an assign to a model element only applies when running the model in edit mode.
* If my model creates a layer, I use the delete tool to zap it (with the output dataset as a precondition). (Layers don't get zapped as intermediate datasets (at least they haven't for me).)
How are you running the code? Is is with a script tool, a model, or the python window?
The code is running as a script tool in a 'regular' toolbox. Not in a 'Python toolbox'.
Within your script tool do you have the result layer object from the Make Feature Layer tool assigned to one of your output parameters?