Select to view content in your preferred language

Arcgis 10.1 modelbuilder - defining a field name in a expression to be a parameter

4238
11
04-03-2013 10:04 PM
yonatanrubinstein
Deactivated User
Hello,

I was asked if the following can be done in the modelBuilder (I know it's simple in python, but I was asked specifically on the modelBuilder):

The user has a expression in the model:   str(!city_code_int!).zfill(4)  (the "city_code_int" is the field name of an "long"-type field).

he wants to put only the field name "city_code_int" as a parameter in the model (and not the entire expression).

Is it possible to do such a thing in the 10.1 Model Builder?

Thanks in Advance.
0 Kudos
11 Replies
ZacharyHart
Honored Contributor
I think I understand what you're looking to do, and if I do understand correctly I think you want to use inline variable substitution.

So you want the model to allow a user defined input which is an attribute from the field  "city_code_int".

In this example let's say we have a landowner dataset and we want to create a model which simply updates a field called 'County'; the user only has to input the county name as a string value.

In MB create a variable: Insert>Create Variable  and choose string as the type.
Rename the variable 'County Name' and expose it as a model parameter.
In the calculate field tool, reference the variable using inline substitution: '%County Name%' (note that I've included single quotes to satisfy the field calculation.

Here's a quick example:

[ATTACH=CONFIG]23197[/ATTACH]

When the model is executed, all the user has to input is the string value of the county name.

I hope that answers your question, and if not sorry if I missed the point.
0 Kudos
DaleHoneycutt
Deactivated User
See "Example 3" in this help topic: Examples of inline model variable substitution.  There are other useful examples in this topic as well.
0 Kudos
yonatanrubinstein
Deactivated User
Hi Zachary, Hi Dale,

Thanks for answering. I did what both of you suggested, problem is that what I want is a more complex case.

I mean that when I put in the expression a single field without manipulations, it works good ( such as the case in what dale did, and example 3 in the help). But when I put in the expression a field with manipulations (such as str or zfill), the "simple user" running the model from the toolbox can change the full expression but not (as I would have wanted it) the field name only. If only there would be a modelbuilder tool that would let me take apart the expression, maybe I could have feeded the fieldname as a parameter for the expression.
0 Kudos
ZacharyHart
Honored Contributor
Hi Zachary, Hi Dale,

Thanks for answering. I did what both of you suggested, problem is that what I want is a more complex case.

I mean that when I put in the expression a single field without manipulations, it works good ( such as the case in what dale did, and example 3 in the help). But when I put in the expression a field with manipulations (such as str or zfill), the "simple user" running the model from the toolbox can change the full expression but not (as I would have wanted it) the field name only. If only there would be a modelbuilder tool that would let me take apart the expression, maybe I could have feeded the fieldname as a parameter for the expression.




I've looked at your example, you need to be exposing the variable as a parameter, not the whole expression. Can you please try to create a variable as I suggested? Insert the variable and call it (rename it) 'Field Name'; and expose it as a model parameter.   Then in your expression, reference that as %Field Name%.   Since you would presumably have a limited number of fields to choose from, we could then create a list so the user get's the name right every time.

To reiterate: if you expose your entire expression as a parameter, the user will be able to mess with it when the model is run.

[ATTACH=CONFIG]23232[/ATTACH]

[Note: if there will always be the same input to your model; you don't need to expose that as a parameter either, just hardwire it in]

EDIT: Ok looked at this once again. I forgot that with the calculate field tool you can create a variable from the field name itself. I'm pretty sure that this will work right here:

[ATTACH=CONFIG]23251[/ATTACH]

Ignore the thumbnail below.
0 Kudos
yonatanrubinstein
Deactivated User
Hi Zachary,


I tried doing as you suggested in the end, but as the data is taken from one field, calculated and inserted into another field, I can't use one "field name".

I tried playing with the "calculate value" tool and feeding the results into the "calculate field" as an expression(see jpg attached), and it looked promising, only the "calculate value" tool doesn't recognize the fields within the input table.
0 Kudos
ZacharyHart
Honored Contributor
In your 'field to be updated' parameter, are you also specifying %Field Name% ?
0 Kudos
yonatanrubinstein
Deactivated User
No. I think I tried it, but I ruled it out, as The "field to be updated" is a different field than the one I'm calculating from (%Field Name%), on which data I'm doing manipulations.
0 Kudos
ZacharyHart
Honored Contributor
Now i'm confused. I thought the point was to have the user enter in a field that they wanted a predefined expression to be applied to?
0 Kudos
yonatanrubinstein
Deactivated User
Now I'm confused. I thought the point was to have the user enter in a field that they wanted a predefined expression to be applied to?


Sorry. The point was to have the enter a field that they wanted a predefined expression to be applied to, But the output is to be written to a different field (which the user enters as well), and not the original field.
0 Kudos