Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kes1
Created June 29, 2015 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kes1/8a22e6e092f2d0b55d64 to your computer and use it in GitHub Desktop.
Save kes1/8a22e6e092f2d0b55d64 to your computer and use it in GitHub Desktop.
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
Copy link
Author

kes1 commented Jun 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment