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.

0

6 Answers 6

7

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.

1
  • 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. Commented Mar 8, 2017 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.

1
  • Adding my toolbox to the available toolboxes in ArcMap didn't get the output added to the data frame for me.
    – Erica
    Commented Feb 19, 2019 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?

0

When using the Data Management Tools -> Features -> Copy Features Tool , even if you set the output Feature Class to 'Model Parameter' and set the 'Add to Display' option, Model builder will not add it to the current map. The same is true for Data Management Tools -> General-> Copy Tool. This applies to 10.6 and 10.3 as I tested it. But WAIT , if you add one more tool to the process you can achieve the desired result.

Consider the model below Model 1

This model copies a SOURCE_DATA feature class to a newly created File GDB four times. Twice with the Copy Features Tool and Twice with the General Copy Tool. Even though the output feature classes:

  • CENTERLINES_2020_1
  • CENTERLINES_2020_2
  • CENTERLINES_2020_3
  • CENTERLINES_2020_4

are set as Model parameters and have Add to Display set, none show up in the current map when run. By adding the Data Management Tools -> Layers and Table Views -> Make Feature Layer tool to the end and setting it's output as a Model Parameter with Add to Display set, CENTERLINES_2020_2 and CENTERLINES_2020_4 are SUCCESSFULLY added to the current map when the model is run.

Likewise, maybe you want the SOURCE_DATA to be added to the map as well, but setting the proper flags on the SOURCE_DATA parameter directly doesn't work. You need to again use the Make Feature Layer Tool and add it's output to the map as in the model below. enter image description here

This strategy allows you to begin with an empty map, run a tool, and have the map populated with SOURCE and RESULT Layers simultaneously. as shown below enter image description here

As many other threads have stated, the difference between the Copy Features Tool and the General Copy Tool is that OBJECTID's are not guaranteed to be preserved with the Copy Features Tool. OBJECTID's ARE preserved if you use the General Copy Tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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