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?
Solved! Go to Solution.
It looks as though the problem is that the feature class name you're producing contains spaces.
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:
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.
It looks as though the problem is that the feature class name you're producing contains spaces.
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:
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?
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.
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