Make Feature Layer within a model does not add the layer

423
14
Jump to solution
05-13-2021 01:15 PM
Labels (2)
RandyMcGregor3
New Contributor III

If I run Make Feature Layer as a tool, the new layer is added to my map. If I put the tool in a model and run the model ('Add to Display' is selected), The layer never appears.

If I open the model and run it, the layer is added to the map, but they are in an awkward group called 'ModelBuilder' and have a prefix I don't want them to have.

I would like to run the model as a tool and when I do that, nothing gets added to the map.

Is there something I can do to make the created layers visible?

Thank you,

Randy McGregor

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor

I believe it is by design, that a geoprocessing tool will not "add to display" when the multiple outputs are expected for a single variable. Split by Attributes GP tool is an example.

You could add a "Save to Layer File", save the layers inside a predefined workspace. Then Add the layers using Add Data option.

JayantaPoddar_0-1621021435133.png

 

View solution in original post

0 Kudos
14 Replies
JayantaPoddar
MVP Esteemed Contributor

Please set the output as a Model Parameter as well.

As per Run a model 

Note:
After the model tool runs successfully, only model outputs set as model parameters are added to the map.

RandyMcGregor3
New Contributor III

Excellent advice. I appreciate it. I have found it works maddeningly inconsistently, though. The model has an iterator, and I think that may introduce a wrinkle.

I want to create a  selection layer for each value in a field. Once, the first value appeared then disappeared when the model was done. Another time, only the final value appeared, but it did stay.

I fear the iterator may introduce complications to this? 

RandyMcGregor3_0-1621009828519.png

 

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Good to know. Could you also try using inline substitution for the output layer name?

0 Kudos
RandyMcGregor3
New Contributor III

Like this? 

RandyMcGregor3_0-1621011396450.png

 

Doesn't work :(. I did remove the iterator and the one output layer was added, so I think I've hit a snag with the iterator. Thank you very much for your help here!

Randy McGregor

 

0 Kudos
RandyMcGregor3
New Contributor III

I added a 'Save to Layer File' tool and that does create a *.lyrx file for each unique value. The model will not add those into the map either, but it does create something I can see and work with after the model has run.

Loading feature layers created within a model or a script into the TOC has always been difficult. I have an old python script that does it and it's got a LOT of steps. 

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Don't rename the Value. Rename the output layer in Make Feature Layer tool.

JayantaPoddar_0-1621012831576.png

 

JayantaPoddar_1-1621012936751.png

 

0 Kudos
RandyMcGregor3
New Contributor III

I appreciate your willingness to work through this. This is pretty much what I have been doing. I can get them to add to the TOC from within model in a 'ModelBuilder' group like you show here, when I open the model and run it, but not when run as a tool.

0 Kudos
RandyMcGregor3
New Contributor III

If I run the iterator first, so that it is 'stuck' on the final value it calculated and only processes that one, it will add the inputs to the map. If I reset the iterator so that it cycles through all the values, it will not add the layers to the map.

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

I believe it is by design, that a geoprocessing tool will not "add to display" when the multiple outputs are expected for a single variable. Split by Attributes GP tool is an example.

You could add a "Save to Layer File", save the layers inside a predefined workspace. Then Add the layers using Add Data option.

JayantaPoddar_0-1621021435133.png

 

View solution in original post

0 Kudos