Created
June 29, 2015 20:32
-
-
Save kes1/8a22e6e092f2d0b55d64 to your computer and use it in GitHub Desktop.
ArcPy Python Toolbox - Update FieldMapping Parameters based on Feature Class Parameter Selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy | |
class Toolbox(object): | |
def __init__(self): | |
"""Define the toolbox (the name of the toolbox is the name of the | |
.pyt file).""" | |
self.label = "Toolbox" | |
self.alias = "" | |
# List of tool classes associated with this toolbox | |
self.tools = [Tool] | |
class Tool(object): | |
def __init__(self): | |
"""Define the tool (tool name is the name of the class).""" | |
self.label = "Tool" | |
self.description = "" | |
self.canRunInBackground = False | |
def getParameterInfo(self): | |
"""Define parameter definitions""" | |
feature_class_parameter = arcpy.Parameter(displayName="Input_Table", #0 | |
name="fc_settlements", | |
datatype="DEFeatureClass", | |
parameterType="Required", | |
direction="Input") | |
fieldMapParameter = arcpy.Parameter(displayName="Primary Settlement Fields", #1 | |
name="primary_fieldmap", | |
datatype="GPFieldMapping", | |
parameterType="Optional", | |
enabled=True, | |
direction="Input" ) | |
fieldMapParameter.parameterDependencies = [feature_class_parameter.name] # Doesn't seem to work | |
params = [feature_class_parameter,fieldMapParameter] | |
return params | |
def updateParameters(self, parameters): | |
if parameters[0].altered: | |
parameters[1].addTable(parameters[0].valueAsText) # Fails with method not found | |
return | |
def isLicensed(self): | |
"""Set whether tool is licensed to execute.""" | |
return True | |
def updateMessages(self, parameters): | |
"""Modify the messages created by internal validation for each tool | |
parameter. This method is called after internal validation.""" | |
return | |
def execute(self, parameters, messages): | |
"""The source code of the tool.""" | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I change this so the two parameters are linked ? GIS SE Question : http://gis.stackexchange.com/questions/152659/how-to-update-field-mappings-parameter-on-table-selection-in-python-arctoolbox