[GIS] Parsing path and calculate value in model builder

arcgis-desktopgeoprocessingmodelbuilderpythontopology

I am experiencing an issue with the model only tool Calculate Value. I am attempting to use the Parse Path and Calculate Value model only tools to force a feature dataset into the Create Topology tool.

  1. The first parse path tool is taking the path
  2. The second parse path tool is taking the file (Feature dataset)
  3. The calculate value tool is combining the two strings and changing the data type to feature dataset using this expression ("%Path%"+"\%File%") (which will connect to the create topology tool)
  4. The problem is when combining the two strings, the calculate value tool is truncating a portion of the path name, specifically the number in the path name.

When running this model on a path with no numbers in it, it runs fine.

I also tried using the the calculate value tool again to replace the truncated characters with the correct ones, and still it breaks the model.

There is some issue with calculate value not accepting numbers in path names.

Can anyone help with this issue?

enter image description here

enter image description here

enter image description here

enter image description here

Best Answer

In Python, a backslash in a string always signals the presence of a special character. For example, a "\t" will be interpreted as a Tab.

I tested your "Calculate Values" expression in ModelBuilder with a path of "C:\Workspace\trash\temp.gdb\poly", and my result was "C:\Workspace rash emp.gdb\poly". Each "\t" was changed to a Tab.

To prevent python from interpreting characters after the backslash as a special character, add an "r" before the string. The version of the expression below calculated the correct string.

r"%Path%\%File%"
Related Question