ArcGIS Pro 2.3 - How to truncate feature class with Calculate Value in ModelBuiler?

801
2
Jump to solution
02-26-2019 08:23 AM
VincentLaunstorfer
Occasional Contributor III

Hi,

I am using Calculate Value in Model Builder in ArcGIS Pro 2.3 in order to truncate a feature class full name and keep only the feature class name.

The following piece of code do not work. It looks like Python is not parsing my inline variable because there is some backslash \ character...

where "fullPath" is the in-line variable I am passing in and the backslash \ is to truncate the feature class proper name to the rest of the path

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

I think you issue is you need to pass a raw string to preserve the path delimeter:

fn(r"%FullPath%")

BUT: I suggest using the Parse Path tool, or, if you still want to use Python, instead of string searches I recommend the functions in the os.path module: os.path.basename() and os.path.dirname().

View solution in original post

2 Replies
curtvprice
MVP Esteemed Contributor

I think you issue is you need to pass a raw string to preserve the path delimeter:

fn(r"%FullPath%")

BUT: I suggest using the Parse Path tool, or, if you still want to use Python, instead of string searches I recommend the functions in the os.path module: os.path.basename() and os.path.dirname().

VincentLaunstorfer
Occasional Contributor III

Thanks. It is perfect!

The Parse Path tool help even gives syntax to work with os module directly in Python.

In ModelBuilder, the Parse Path tool is in the Uilities menu on the toolbar (and not in the toolbox) if anybody was looking for it.