Get Layer Base Name in ModelBuilder (For Calculating with Joins)

1107
3
01-25-2012 04:33 AM
RandyMcGregor
New Contributor III
I have several models that perform calculations with joins.

These calculations require you to enter the name of the joined table, then it's field name.

[FIELD] = [JOINEDTABLE.FIELD]

What I have done is to give "hard coded" names to output tables so they are always the same:

This makes it easier to do the calculation, but once in a while the table isn't deleted (model bombs) AND a lock gets placed on it so it can't be overwritten.

There are ways around this, of course, but what I would like to do is create unique table names, but I don't know how to extract just the table name in ModelBuilder (in Python os.path.basename(full table path) does the trick).

I tried [FIELD] = [%tablename%.FIELD], but of course that creates a calculation string like this:

[FIELD] =

I think I'm close, but just need a little nudge in the right direction.

Thank you for your time,
Tags (2)
0 Kudos
3 Replies
RandyMcGregor
New Contributor III
This turned out to be really easy.

There is a (new??) model only tool called, "Parse Pathname"

You supply a dataset, and select which "piece" of the dataset path name you want returned to you.

There are four options, easy to select from a drop-down in the tool. In my case, "name" is what I needed.

"Name" returns the name of the dataset, minus the file path or any extension. This is precisely what is needed to do a calculation on a join.
DuncanHornby
MVP Notable Contributor

Randy,

That tool has been around for years, it's one of those tools you see, wonder why you would ever use it and forget it even exists. Then just like you one discovers it and has a "oh that's what it is for!" moment. My most recent discover is the Join Field tool! For years I have been Adding a join, calculate then breaking the join...As Homer would say doh!

Duncan

0 Kudos
curtvprice
MVP Esteemed Contributor

If Join Field weren't so darn slow!