Select to view content in your preferred language

Create a dependency for a field variable in ModelBuilder?

1490
5
02-14-2024 02:13 PM
Labels (1)
RandyMcGregor_BMcD
Frequent Contributor

I'm sure this is quite simple, but I'm missing something. I want to provide the option to select a field in a model. I have added a field variable, but I don't see any way to provide a layer to populate the fields.

RandyMcGregor_BMcD_0-1707948636685.png

In the tool's properties, I can see this as a parameter, but the 'Dependency' option is unresponsive.

RandyMcGregor_BMcD_1-1707948812662.png

How does one plug a layer into a field variable?

Thank you,

Randy McGregor

 

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

Model parameters—ArcGIS Pro | Documentation

Dependency
You can make a parameter dependent on another parameter. The typical use for this is to make one parameter that accepts an attribute field dependent on another parameter that is a feature class or table; the field parameter will include a drop-down list of attribute fields from the dependent parameter.

 

Which means that you have to provide the featureclass first


... sort of retired...
0 Kudos
EdMorris
Esri Contributor

Hello Randy

This has got me thinking because, just like you, I can not set the"dependency" up in a model - it is grayed out in the Model Properties dialog ; Parameters tab, just as you report.

I will see if I can make contact with the ModelBuilder team to see why this is and I will report back to this thread.

As a workaround.... how is your Python scripting? The dependency does work in a Python Script tool, for example:

1: Create a Python Script tool in a custom toolbox (Right click a custom toolbox or the project's default toolbox and choose New > Script)

2: Fill in the Name and Label text boxes on the General tab.

3: Click the Parameters tab.

4: Create 2 parameters as shown below:

EdMorris_0-1708010983673.png

Notice the data types.

5: For the attribute field parameter scroll until you see the Dependency property.

6: Click in the Dependency property for the Attribute field parameter and select the feature layer parameter name:

EdMorris_1-1708011175879.png

This should set up the dependency of the Field parameter to display the attribute fields of the chosen feature layer.

7: Press the OK button on the New Script dialog to create your script tool.

8: Double click the script tool to display the dialog. You should see 2 parameters:

9: Choose the input feature layer (or feature class) and the Choose attribute field parameter should then be populated!

EdMorris_2-1708011395146.png

I ask how are your Python skills as you would need to convert you model to a Python script to take advantage of the above. You would need to use arcpy.GetParameterAsText() to pass in the user choices on the dialog into your script.

I hope this helps.... thanks ed

RandyMcGregor_BMcD
Frequent Contributor

Thank you Ed,

 

I have quite a bit of experience with Python and have set up dependencies successfully with it. This was my first time trying to set one up with ModelBuilder 🙂

0 Kudos
dribrats
Occasional Contributor

Hi Ed, do you have any update on this functionality? I'm running ArcGIS Pro 3.5 and have found that I'm still not able to set up field dependencies. I've got a ton of experience with Python scripting, but for simple workflows, I prefer to use model builder because I'm building tools for a larger team and would like these simple workflows to be easily maintained by staff that aren't so familiar with scripting. It seems like this is a pretty core feature if Esri would like to offer Model Builder as a viable alternative to scripting in Python. Thanks for looking in to it!

RandyMcGregor_BMcD
Frequent Contributor

I have a model that asks for the route id field after the route features have been chosen. Should be a drop-down, but I can't get it to work as a dropdown, so you have to type the name of the field in. 

0 Kudos