Select to view content in your preferred language

drop down list for model builder

4529
7
03-31-2018 08:28 AM
ianmcintosh
Emerging Contributor

I was wondering if it is possible to create a drop down list that returns a layer files that the user can select to be used with apply symbology tool in model builder. I've tried to use parse path with string to create a value list, but that does not work. I thought the iterator over files would work but I couldn't make that work. I know this can be accomplished using a python script, but i'd like to do this in model builder.

0 Kudos
7 Replies
curtvprice
MVP Alum

The Model Builder way this is done is to add a model variable of type string (I'll name it 'key'), make it a model parameter, and set up a Value list filter of keywords, which you then can map to a layer file (each layer file included in the model) using the Calculate Value tool. (The r"" business there is required because the layer file model variables include \ characters we need to hide from Python)

Calculate Value tool parameters:

# expression: plyr("%key%",[r"%layerfile 1%",r"%layerfile 2%",r"%layerfile 3%"] )
# code block:
def plyr(key, lyrpaths):
  keys = ["BLUE", "YELLOW", "VIOLET"] # these were in your parameter filter
  lookup = dict(zip(keys, lyrpaths))
  return lookup[key]
# data type: layer file‍‍‍‍‍‍‍ (to connect to apply symbology)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
ianmcintosh
Emerging Contributor

I appreicate the comment and help. I added tehCaculate Value from the Utiliities of ArcPro.Model

I've also add the code block as. I wanted to use os.path.join to handle it a little more approiately but the tool didn't accept it.

for the parameters of the userLyr function I used "%LayerFile" which is a string variable in model builder but holds a value list for the user, and the "%layerFilePath%" which is derived from the parse path tool so that I can always retreive the relative path of each layer file where they will be stored. The only issue that I've found is that when running it, the model does not apply the symbology. I am not sure if this is a glitch of the tool or something. 

0 Kudos
curtvprice
MVP Alum

Some thoughts:

  • If you want to use os.path.join, you need to import os in your Calculate Value code block.
  • You should connect the Value element to Calculate Value so you can be certain the value is updated before Calculate Value uses it.
  • As for the tool not "working" I would look carefully at the messages you see when you run the model, you may see some things aren't getting set exactly how you need them to be.
0 Kudos
ianmcintosh
Emerging Contributor

Curtis Price,

I very much appreciate your assistance on this. I was able to figure out what I did wrong. I added the output of the Apply Symbology from Layer as a parameter and it finally worked.

curtvprice
MVP Alum

Ahh - this ensured the output was updated on the display.. that makes sense!

0 Kudos
ianmcintosh
Emerging Contributor

Thanks for the response. I am not sure how connecting the Value element to the Calculate Value works as part of the expression box or code block. The parsed path is used as an inline variable for the Calculate Value tool. Also, when I read the message from the output everything looks fine.

0 Kudos
curtvprice
MVP Alum

I am not sure how connecting the Value element to the Calculate Value works as part of the expression box or code block.

Here's how preconditions work to make sure tools in the model run in a particular order when they aren't directly connected as tool parameters:

A quick tour of using preconditions—Help | ArcGIS Desktop