Wednesday 4 September 2019

arcgis desktop - Using only part of inline variable substitution string in ModelBuilder?


I am using an inline variable substiution to alter a field name. I do this within an iteration model in model builder. The inline variable is the name of the feature class which I use as my input for each iteration. When I am altering the field name I would like to only use the first part of the inline variable. To explain this a bit better, here is the name structure of my feature classes:



  • SA_05_Walk_CBR

  • SA_10_Walk_CBR


  • SA_05_Bike_CBR

  • SA_10_Bike_CBR

  • SA_05_Driv_CBR

  • SA_10_Driv_CBR

  • SA_05_Walk_PJC

  • SA_10_Walk_PJC

  • SA_05_Bike_PJC

  • SA_10_Bike_PJC

  • SA_05_Driv_PJC

  • SA_10_Driv_PJC


  • etc.


(Note that all feature class names have the exact same amount of characters for each part of the names)


Within my iterator, these feature class names represent my inline variable substitution string (called "count_field" in my model, see picture).


When I use the iterator, I join all the SA_xx_xxxx with a point feature class where I use the last three letters of the feature class name as a wilcard (e.g. "star_CBR"). For my next iteration I do the exact same thing but then using "star_PJC" as my new wildcard. These iterations work fine without any problems and it is also the reason why my feature classes need to end with "*_xxx".


Next in my iteration, I alter a certain field name so that they can be differentiated within the table of the feature class. Currently I use this in-line variable subsitution to rename the field (e.g. "SJ_Count_%count_field%"). Also this process works fine. Here is a picture of the alter field window:


alter field window


(Please ignore the explanation mark; this picture is pure for a demo)


The thing what I want to do, however,is that it only uses part of the inline variable to alter my field name. The last 4 letters of my inline variable (e.g. "_CBR") can be removed within my new field name. So a field name would be called, for example, "SJ_Count_SA_05_Bike"


I have tried in renaming my field name again but I haven't found a way to remove the last 4 characters through an iteration. Anyone any ideas how I could do this in an efficient way? Using python within the alter field tool does not seem to be an option (as seen from alter field tool window picture). Here is a picture of my model:



join and alter field model through an iteration in model builder



Answer



Use the Calculate Value tool in model builder to drop the last 4 four characters of your Count_Field variable. Set the tool to be a precondition to the alter field tool to ensure it executes first.


Set your expression as shown below


Screen shot of Calculate Value Tool


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...