Iterating tables and keeping their respective names

244
2
01-23-2024 05:57 AM
EmmaMartin
New Contributor

I have 12 CSV files, each containing data for the respective month of the year. They are all named respectively, i.e. January_2020, February_2020, March_2020 etc and are stored in a folder named 2020_monthly.

For the smooth running of the workflow, I first convert the CSVs into geodatabase tables. Naturally, I need these tables to retain the same names as their respective CSVs.

I then need to display all of these tables as points, converting them into feature classes in the geodatabase on the way. For the sake of organization and smooth workflow, I need the new feature classes to also keep the original Month_Year name. This is where I get stuck, as my ModelBuilder just produces one table/feature class and that’s it. What am I doing wrong?

EmmaMartin_0-1706018035126.png

EmmaMartin_2-1706018180523.png

 

 

0 Kudos
2 Replies
BobBooth1
Esri Contributor

Use Inline variable substitution:

https://pro.arcgis.com/en/pro-app/3.1/help/analysis/geoprocessing/modelbuilder/inline-variable-subst...

Make the GDB table name something like %Name%_MB

Then you'll get January_2020_MB, February_2020_MB tables out. 

curtvprice
MVP Esteemed Contributor

Two notes about inline variable substitution to generate output names:

If you need to get more fancy, for example, change special characters, add a filename extension, or specify a full path to put the output in a specific location, the way to do this is using Python string expressions in the Calculate Value tool. If it really gets complicated you can write a python function in that tool. 

If you do this in a loop, it's good practice to use precondition, connecting the Calculate Value tool to the tool that writes output using the calculated path -- to ensure the pathnames get calculated before you use them within the process chain.

Example Calculate Value Python expression, with a fix in case the Name has an embedded space, and a .dbf extension for writing in dbase format to a folder.

r"%Out Folder%\%Name%.dbf".replace(" ","_")

 

0 Kudos