Set Default GPLinearUnit to Input Units

4364
2
07-28-2014 11:52 AM
AndrewFulton
New Contributor

How would I go about setting the default GPLinearUnit parameter's units to the same as an input, or even a default value of 'meters', within a Python toolbox? I assume it happens in update Parameters, but don't know how to approach this issue.

 

Your help will be greatly appreciated

 

### From what I've been able to figure out, there is no way to choose a default linear unit such as 'meters'; however, the linear unit in the tool dialog will correspond with the active Data Frame's Map Units. I think this only works in ArcMap. At least there is an ArcCatalog Window in ArcMap now

 

Message was edited by: Andrew Fulton

0 Kudos
2 Replies
JustinBousquin
New Contributor

I've been trying to figure this out as well. I've somewhat been able to get it working using updateParameters, the trick is matching its required format and units.

#For a default meters (where param[1] is your parameter with datatype GPLinearUnit)

def updateParameters(self, params):

     if not params[1].altered:

          params[1].values = "0 Meters"

#Updating based on an input layer (params[0]) is trickier because spatialReference.linerarUnitName doesn't match up with the GPLinearUnit types

def updateParameters(self, params):

     if not params[1].altered and params[0].altered:

          spRef=arcpy.Describe(params[0].valueAsText).spatialReference

          params[2].values = spRef.linearUnitName

          if spRef.linearUnitName == "Foot_US":

               params[1].values = "0 Feet"

I'll let you know if I come across a better solution

0 Kudos
JustinBousquin
New Contributor

To update a GPLinearUnit parameter (units) based on an input parameter (input) use parameterDependencies in getParameterInfo:

units.parameterDependencies = [input.name]

0 Kudos