2

I am attempting to make a generic tool to move existing points to an already defined XY. What I want to do is have the user define the feature class, then the X field and Y field from that feature class, then run the Calculate Field with those X and Y fields. Below is what I have, but I know I am going about it the wrong way (fairly new to ModelBuilder). I can't find a way to associate those first Field Parameters with the feature class.

enter image description here

I know I can just use the same X and Y field names every time and it will work, but I want the tool to be as versatile as possible.

1 Answer 1

1

You basically have everything set up, you just need to connect your X and Y fields (already modelled as input parameters for your model) to the "Calculate Field" process/box. First, make absolutely sure that these variables are of type "Field" - this is essential. If this is not the case, you can either adjust the properties or create a new Variable of type Field, then set Display Properties to show them as "X Field" and "Y Field" if desired. But when these are the correct type, you'll be able to use model builder's Connect tool to click from each field, in sequence, as a modelled parameter, to the Calculate Field process. At the pop-up option dialog, select "Precondition". NOTE - this must be done BEFORE you connect your input table to the Calculate Field box, or you can't use these field variables in the calculation.

When you go back into the tool properties after setting this up, you'll have to reference your two new fields as input variables into the Expression function, like this: Update("%Field%", "%Field (2)%") assuming the field variables get the default naming, as shown below.

Your code block would be unchanged. This way, you can use your model as a tool/process as intended where those variable names might change, and would need to be specified each time it is run.

enter image description here

2
  • Hi Alec, I think I have everything set up the way you described, however when I go to run the model and fill in field parameters they are blank (no fields to choose from for the feature class). The two variables are correctly set as fields and I did everything in the order you specified. I can't add a picture on a comment I think - I can figure out a way to add one somewhere if necessary. Any thoughts?
    – TMac
    Nov 27, 2017 at 19:07
  • See the updated answer with image - I didn't mention the necessary way to reference the variables in the Expression function. Let me know if there are any issues.
    – AlecZ
    Nov 28, 2017 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.