could [you] assist me constructing a python expression using calculate value to solve a similar problem. I've attached two print screens of my current model. I'm selecting CAD Features based on their layer name and then using Feature Class to Feature Class to write out the CAD Features to a File Geodatabase based on the Layer Name. The problem that I have is that I need to remove invalid characters from the Layers Name. Here's some code for using Calculate Value to do this: Expression:
ValidateName(r"%Layer name%",r"%Output geodatabase%")
Code:
def ValidateName(fc,wks):
import arcpy
vName = arcpy.ValidateTableName(fc,wks)
return vName
The way to connect this up is to make the inputs preconditions (to ensure the input values are ready to go when you run Calculate Value [CV]) and then you can connect the output directly to the Feature Class to Feature Class tool. Depending on the required parameter type for the next tool you may have to set the output Data Type in Calculate Value. In this case, Feature Class to Feature class was happy to accept the default type (Any Value). In some situations (say, the name is part of a pathname or the tool validation doesn't accept a parameter type that CV supports) you cannot easiliy connect the CV output to the tool. In those cases, you connect the CV output with a precondition and use the CV output variable in the tool dialog parameter box (e.g. "MyOutput_%Validated_name%"). Calculate Value, as you have seen by now, is key to make the most of ModelBuilder. [ATTACH=CONFIG]21319[/ATTACH] Another approach to your problem is the Feature Class to Geodatabase (Multiple) tool, which does all this iteration and validation for you. (BTW, its source code really helped me get the hang of validation and iteration in Python when I was first learning.)
... View more