Create a dependency for a field variable in ModelBuilder?

332
3
02-14-2024 02:13 PM
Labels (1)
RandyMcGregor_BMcD
New Contributor III

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
3 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

0 Kudos
RandyMcGregor_BMcD
New Contributor III

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