Skip to content

Instantly share code, notes, and snippets.

@kes1 kes1/Toolbox.pyt
Created Jun 29, 2015

Embed
What would you like to do?
ArcPy Python Toolbox - Update FieldMapping Parameters based on Feature Class Parameter Selector
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
@kes1

This comment has been minimized.

Copy link
Owner Author

commented Jun 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.