3

I am using ModelBuilder and trying to get a user defined field from a user defined polygon. From this, I want to later populate a different field with calculated values in a model.

Is there a way to get a list of fields from the user defined polygon and use that value to populate the other field?

How would I go about using the user defined field in a VB expression within the calculate value tool?

newfield = [%field%]?

nmpeterson
  • 8,276
  • 33
  • 59
Ian
  • 31
  • 1
  • 2
  • 2
    It might be helpful to post a screenshot of your model here. Have you looked at all into Python? – GISHuman Aug 11 '14 at 19:44
  • 1
    That expression should work, if you have a text parameter called "field". Have you tested it? – nmpeterson Aug 11 '14 at 22:05
  • 1
    Yes, that should work, but why? There is so much danger in doing it this way as you're not picking a field from the feature class you're entering a string - a chance for typo's. Can you explain a bit more about what you're trying to do and hopefully I can come up with something a bit more robust. – Michael Stimson Aug 11 '14 at 23:03
  • By a "user-defined polygon" are you meaning a Feature Set? And what do you mean by a "user-defined field"? Perhaps including some screenshots will make your question clearer. – PolyGeo Aug 12 '14 at 02:42

1 Answers1

6

If you want a field picker you have to code it in python.

The code is as follows:

# Import system modules
import arcpy

# Set the parameters
InputFeatureClass = arcpy.GetParameterAsText(0)
InputField = arcpy.GetParameterAsText(1)

arcpy.SetParameter(2, InputField)

And the tool is set as follows:

Input Feature Layer

  • Data Type: Feature Layer (You might be using a Feature Set)
  • Direction: Input
  • Multivalue: No

Inputs Fields

  • Data Type: Fields
  • Direction: Input
  • Multivalue: No
  • Obtained from: Input Feature Layer

Output Field

  • Data Type: Field
  • Direction: Output
  • Multivalue: No

It looks like this

Toolbox Script dialog

You should then be able to use this to return a field as a FIELD object, suitable for a input parameter to the Calculate Field tool. A model looks like this: Example Model

I hope that helps.

Mark Bryant
  • 1,435
  • 8
  • 7
  • What a clever solution. Too bad model builder doesn't inherently support the 'obtained from' option in the parameter settings.\ – CStarbird Mar 11 '16 at 01:16