Select to view content in your preferred language

Use inline variable %Name% (iterate layers) in clip

722
7
Jump to solution
01-29-2025 07:17 AM
CharelvanDijk
Emerging Contributor
 

I want to use the inline variable in Iterate Layers to give the output layer of a clip the same name as the input layer. I created a model for this. In the output layer, I use %Name%. I connected the Name from Iterate Layers to the clip as a precondition. However, the %Name% in the clip output keeps causing errors. Any ideas?

0 Kudos
1 Solution

Accepted Solutions
BobBooth1
Esri Regular Contributor

It looks as though the problem is that the feature class name you're producing contains spaces.

spaces_in_name.png

Try sanitizing them with ValidateTableName.

https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/working-with-geodatabases.htm

This post shows how you can use Calculate Value to do that:

https://community.esri.com/t5/geoprocessing-questions/arcgis-10-1-modelbuilder-validatetablename/m-p...

 

View solution in original post

0 Kudos
7 Replies
BobBooth1
Esri Regular Contributor

Is it writing to the same location as the source feature classes? It may be trying to overwrite... maybe use %Name%_clip or something like that for the output.

0 Kudos
CharelvanDijk
Emerging Contributor

Thank you for the response.
I changed the workspace and the name, but it's still not working...

0 Kudos
BobBooth1
Esri Regular Contributor

It looks as though the problem is that the feature class name you're producing contains spaces.

spaces_in_name.png

Try sanitizing them with ValidateTableName.

https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/working-with-geodatabases.htm

This post shows how you can use Calculate Value to do that:

https://community.esri.com/t5/geoprocessing-questions/arcgis-10-1-modelbuilder-validatetablename/m-p...

 

0 Kudos
CharelvanDijk
Emerging Contributor

That was exactly the problem... and the solution! Thank you so much for your help.
I wrote a guide for this issue, but it's only in Dutch (my English isn't that good).

BenCobbing1
Occasional Contributor

I have a similar sort of query:  I want to create a simple model that runs a few tools (buffer / intersect; or grid clip etc) - but crucially I would like to export each buffer intersect result as a separate feature class - with the name of the buffer area.  So in my example below - I have a town point dataset, with each town's name in the Label field.  I buffer this, then intersect it into a vegetation dataset, and then run Iterate Row or Iterate Feature tool, and then export each as a separate feature class.   This works for all town labels without spaces when I use the Name_%Value% option.  So it drops data where the town has a space in.  If I add another field - in this case Test, and give it a numeric ID, and run the same model, it works for all towns.   However, my question is - is there another placeholder (%Value%) that will allow exporting my town label data with the spaces included?   This might be a slightly clunky way of explaining things - but I am not a coder or anything like that. 

Yes there are workarounds to this - and yes I can easily create a second field and/or replace the spaces etc.  But what if I want each feature layer including the "space" values?   Just curious?   Is there another placeholder like %Value% that will allow this?

Screenshot 2025-08-07 110210.png

 

 

0 Kudos
BobBooth1
Esri Regular Contributor

Ben,

If you're saying you'd like the iterator to output feature class names with spaces when given a field with spaces, the answer is, it does! The problem is, such names are not valid geodatabase feature class names, so saving an output with such names fails. Spaces, certain special characters are not allowed in GDB feature class names.

https://support.esri.com/en-us/knowledge-base/what-characters-should-not-be-used-in-arcgis-for-field...

0 Kudos
BenCobbing1
Occasional Contributor

Hi Bob.  Many thanks for the reply - ok, so changed the model to export Shapefiles to a separate folder and it worked - and just like that.  lol.  Thank you - so noted:  No spaces in GDB feature class export file names.

Cheers

Ben