Hello everyone,
I have a parameter named LocNo. It is used as a parameter in a model or two. Currently I have the user manually enter the LocNo value when the model starts. LocNo also happens to be the first 12 characters in the name of the mxd file.
Is there a way that I can grab the first 12 characters and use them as the value passed into the parameter?
For example here is a part of the model that shows how the LocNo is used:
If I can grab those first 12 characters from the filename and insert that into the parameter in the model I'm sure it would save on having some human error introduced.
Thanks for the help,
Chris
Solved! Go to Solution.
You can use a combination of Parse Path and Calculate value tool, which are model only tools so only accessible from within model builder. The input would have to be a variable of type ArcMap Document and the model would be:
In the example above I use the python expression "%Value%"[:5] to return the first 5 characters of the mxd name. The user would have to select an existing mxd, even if it is the one they already have open. Also note that the output of Parse Path, value, is a precondition to the Calculate value tool.
You can use a combination of Parse Path and Calculate value tool, which are model only tools so only accessible from within model builder. The input would have to be a variable of type ArcMap Document and the model would be:
In the example above I use the python expression "%Value%"[:5] to return the first 5 characters of the mxd name. The user would have to select an existing mxd, even if it is the one they already have open. Also note that the output of Parse Path, value, is a precondition to the Calculate value tool.
Thanks for the info Duncan!
Sent from my iPhone
Thought I'd provide a quick update. I've moved this functionality over to the following python script. Works well.
import os
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
locPath = str(os.path.basename(mxd.filePath))
LOC = locPath[0:12]
returnLOC = LOC.upper()
arcpy.SetParameterAsText(0, returnLOC)