3

I'm trying to create a tool in ModelBuilder that will take a new point from a user, create a feature class for this point and display it on a map.

What I've done is:

  1. I've created a feature class for a point-like feature in ArcCatalog.
  2. I've prepared a really simple model in ModelBuilder, that starts with a feature set variable (which takes the feature class as a schema and symbology file). The variable is marked as a parameter.
  3. Next I'm using the Copy Features tool that takes the variable as input and saves it as a feature class in my scratch workspace.
  4. The output feature class is marked as a parameter with the 'add to display' option.

After the module is run I get a shapefile in my scratch workspace. I can add it manually to TOC and it contains the selected point. However no matter what I do, I can't display it in TOC automatically after the model completes.

There is a known issue described in several places that doesn't allow to display newly created layers in TOC when model finishes with the 'add to display' option. However there's a quick workaround, which is to mark the output layer as parameter. In my case it doesn't work.

I'm using ArcGIS for Desktop 10.1 on Windows 7 x86_64.

8

I think the software behaviour you are observing may be by design and is documented in Displaying Model Data.

Add To Display has no effect outside ModelBuilder. When running a model tool from its dialog box or the Python window, the Add To Display setting will not be honored. To add model data variables to the display when running the model from its dialog box or the Python window, make the data variable a model parameter, then enable the Add results of geoprocessing operations to the display option from the Standard toolbar: Geoprocessing > Geoprocessing Options > Add results of geoprocessing operations to the display.

2

I had the same problem but with rasters produced by model. After spending quite a lot of time trying to make Add to Display work I finally decided to implement arcpy script to add output raster to ArcMap data frame. I think the same can be applied in your case. My solution is derived from the one found here.

So, make python script with code similar to this one

import arcpy
import os
import os.path
from os.path import split, join
from arcpy import env

rasterPath = arcpy.GetParameterAsText(0)
pathFileName = os.path.split(rasterPath)
rasterLayerName = pathFileName[1]
env.workspace = pathFileName[0]
result = arcpy.MakeRasterLayer_management(rasterLayerName, os.path.splitext(rasterLayerName)[0])
lyr = result.getOutput(0)
mxd = arcpy.mapping.MapDocument("CURRENT")
dataframe = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.mapping.AddLayer(dataframe,lyr,"TOP")

Make a model tool using the script and add it to your model. Make script tool have precondition on, in your case, Copy Features tool output.

Important: "Run Python script in process" option must be enabled. Same applies if you implement model with Calculate Value tool (similar to solution found in link I posted) instead of script tool - "Always run in foreground" must be enabled.

0

The tutorial document I found suggests making the output file a parameter in order to have it add to display automatically. See page 4 of tutorial document. Snippet below.

If you run the tool by clicking OK, the model will run. The output of the model (ClippedFC) will not be added to the ArcMap table of contents, even though Add To Display was checked for the output variable. The reason is that when a model is run from its tool dialog box, the Add To Display setting is ignored. To add the output to the display, you must make the output variable a model parameter.

  • This is the same as Polygeo's earlier answer, gis.stackexchange.com/a/67055/108. The tutorial document is new and different though, and would be helpful as a comment to the existing answer. – matt wilkie Mar 8 '17 at 21:29
0

I was running into the same problem until I added the model and toolbox to the available tools (right click on ArcToolbox > Add Toolbox > navigate to where your model is being saved, add). Run it from the toolbox window, and that's what worked for me.

  • Adding my toolbox to the available toolboxes in ArcMap didn't get the output added to the data frame for me. – Erica Feb 19 at 19:41
0

make sure you set the mxd in your script to "Current" ( mxd = arcpy.mapping.MapDocument("Current") ), open a MXD in ArcGIS, and start the script from your ArcGIS toolbox. Does it work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.