Within a .pyt python toolbox I'd like to have a parameter of data type GPLinearUnit get a default value based on an input Feature Class (FC). The standard Buffer (Analysis) tool works as a great example of what I'm trying to imitate:
The closest I've been able to come is to set units in updateParameters based on the FC spatialReference.linearUnitName, but linearUnitName and GPLinearUnit units aren't the same and there are 50+ linear units. Anyone know a better way to do this or a reference/code somewhere I could at least pull the linearUnitName to GPLinearUnit from?
def getParameterInfo(self):
inFC = arcpy.Parameter(
displayname = "Input FC",
name = "inputFC",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "input")
units = arcpy.Parameter(
displayName = "Distance & Units",
name="Units",
datatype="GPLinearUnit",
parameterType="Required",
direction = "Input")
params = [inFC, units]
return params
def updateParameters(self, params):
if not params[1].altered and params[0].altered:
spRef=arcpy.Describe(params[0].valueAsText).spatialReference
if spRef.linearUnitName == "Foot_US":
params[1].values = "0 Feet"
return
I should also point out that this code defaults the distance to 0, where as the Buffer tool I'm imitating is able to set units without a distance.