I created a python script tool that creates a Thiessen Polygons. The tool runs fine. But how do I create it so that it automatically adds a new layer to the map? Right now, it only creates it in the geodatabase. I would have to manually drag and drop it into the map to get it to appear.
If the script is attached to a tool in arctoolbox, then the results should be added to the display (I assume that your featureclass is an output parameter).
If you are running the script as a standalone script, it probably won't automatically since there may be a disconnect between the scripting environment and the project... obviously if Pro is closed, it won't add it at all, which is where the arcpy.mp (aka mapping module) comes in and using 'CURRENT' for the aprx.
You can try
to see if that helps.
But the surefire way is to make your script run from a tool in a toolbox in ArcToolbox
Thank you for the response and resources. I believe my script is attached to the toolbox:
I tried "arcpy.MakeFeatureLayer_management". But there is no difference when I run the tool. However, if I run the same script through the python window, two of the same layers get displayed. One from analysis.CreateThiessenPolygons and the other from MakeFeatureLayer_management.
Is there a reason for this? The same script runs in the python window but doesn't display through the tool.
number, Label/Name Direction Data Type
0 Input_Features Input Feature_layer
1 Fields_to_copy Input (did you check 'Dependency (input_features)' so you can chose from a list of fields?
2 Output_Feature Output I always try Feature Class or Feature Layer when one or the other doesn't work. I always put output as the last parameter and it is the only output parameter.
I tried both Feature Class or Feature Layer. It didn't seem to make any difference. I was modelling the parameters after the default Thiessen Polygon tool in Pro.
Do you think it is a parameter setting that is preventing the layer from displaying automatically and not the script?