Feature Class Not Added to Display / Table of Contents When a Variable Name is Used

4422
4
03-08-2013 11:14 AM
SethSobel
New Contributor II
I have a relatively complex model, where I would like to allow the user to input a Scenario Name as a parameter and have the model use that parameter to name the output feature classes appropriately. For example: Scenario1_Points; Scenario1_Lines; Scenario1_Polygons, etc. They would then be able to run the model a second time and create new outputs while the previous outputs do not get overwritten.

To do this, I have a string parameter, and when the output FC name is specified, it is C:\Tools\Model\Model_Output.gdb\%ScenarioName%_Points

This method works perfectly when the model is run within the Edit mode of ModelBuilder. However, when the model is saved and run as a tool, the layer is created, with the correct name, but the layer is not added to the map.

The model is being run from within ArcMap, not ArcCatalog. I have the Scenario Name input marked as a parameter and the output FC is marked as a parameter. Under the Geoprocessing menu, Display/Temporary Data, the "Add results of geoprocessing operations to the display" is checked. I have somewhat exhaustively searched the forums and Google, but can't find mention of variable names preventing data from being added to the table of contents.

I can confirm that the variable name is the issue, because when I remove the variable and hard code the FC name, the FC is added to the map correctly, even when the model is run as a tool. I have attached a toolbox with two very simple tools to demonstrate the issue. They are identical, except that one of them has a user input parameter, which is used to name the output. The other one has a hard-coded output name. They place the output in a GDB at C:\Tools\Bug_Test\Model_Output.gdb.

I am running ArcGIS Desktop 10 Service Pack 5 (Build 4400), ArcInfo license.

Similar threads that have not helped:
Thread: Modelbuilder as a tool is not the same as running the same model in modelbuilder?
http://forums.arcgis.com/threads/48066-Modelbuilder-as-a-tool-is-not-the-same-as-running-the-same-mo...

Thread: modelbuilder result won't add to TOC (cont.)
http://forums.arcgis.com/threads/7255-modelbuilder-result-won-t-add-to-TOC-%28cont.%29

modelbuilder result won't add to TOC
http://forums.esri.com/thread.asp?t=303855&f=1728&c=93

Displaying model data
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Displaying_model_data/002w0000003q0000...

Tutorial: Creating tools with ModelBuilder
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002w0000007v000000

Thread: Model builder won't add output of process
http://forums.arcgis.com/threads/41125-Model-builder-won-t-add-output-of-process?highlight=variable+...

A quick tour of creating tools with ModelBuilder
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_creating_tools_with_Mo...

Creating model parameters
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Creating_model_parameters/002w0000003z...

Tutorial: Executing tools in ModelBuilder
http://resources.arcgis.com/en/help/main/10.1/index.html#//00210000003v000000
4 Replies
curtvprice
MVP Esteemed Contributor

This method works perfectly when the model is run within the Edit mode of ModelBuilder. However, when the model is saved and run as a tool, the layer is created, with the correct name, but the layer is not added to the map.


This is how all tools (including script tools) work. If the output is not a parameter, it will not be added to the map. The "Add To Display" property of a Model Builder element only works when running the model in Edit mode.

With script tools, you can set the output as "Derived" so the output parameter exists, but doesn't show up in the tool dialog.

You may be able to get around this in 10.0 by using arcpy.mapping in a Calculate Value tool code block to add the layer to the current data frame.

Arc 10.0 help: AddLayer
0 Kudos
SethSobel
New Contributor II
This is how all tools (including script tools) work. If the output is not a parameter, it will not be added to the map.


Yep, I understand that. My sample model includes a parameter output. In the one that has a hard-coded name, the output is added to the map. In the one that includes a variable in the output name, the output is not added to the map. I think this is an ESRI bug.

You may be able to get around this in 10.0 by using arcpy.mapping in a Calculate Value tool code block to add the layer to the current data frame.


Your suggestion gave me a workaround for this issue for the time being. Thanks!
0 Kudos
curtvprice
MVP Esteemed Contributor
My sample model includes a parameter output. In the one that has a hard-coded name, the output is added to the map. In the one that includes a variable in the output name, the output is not added to the map. I think this is an ESRI bug.

Your suggestion gave me a workaround for this issue for the time being. Thanks!


You're very welcome. If you haven't filed support incident and gotten a NIM, please do -- this will greatly increase the chances of Esri getting the problem fixed.
0 Kudos
SurendranNeelakantan
New Contributor III

I have been facing  the same issue  for couple of years , and I have worked this out.  I have searched all the links you posted her. Finally I have a working solution. This solution is  similar to Curtis Price suggested.  Please try this Toolbox. This solves one more issue. You can hide the output parameter from user by using a wrapper model ( here  Use Test Model Main).

Hope this helps !

0 Kudos