I enabled multiple value input for some parameter in an ArcMap 10.8 Python Toolbox.
In my script, I can easily split the input received from the UI by applying .split(";") since the input values are separated by ";".
However, when the user selects a layer from the drop-down that is located within a group, each such value consists of the group name and the layer name, separated by "\". The problem: "\" is an escape character in Python. I cannot separate the layer name from the group name. I need the layer name, though, because I want to search the .mdx document for that name in order to get the full path to the layer on disc.
Is there some way to solve this?
I tried:
combined_name.split("\\")
combined_name.split(r"\\")
r"{0}".format(combined_name).split("\\")
where combined_name is the respective name extracted from the input variable. All these attempts were without success.
Edit: I tried the arcpy.GetParameter(0) suggestion with no success. This is the Toolbox I used to test it:
import arcpy as ap
# Toolbox
class Toolbox(object):
def __init__(self):
self.label = "Tool"
self.alias = "Tool"
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = "Test GetParameter(0)."
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
in_raster = ap.Parameter(
displayName = "Input Raster",
name = "Raster",
datatype = ["GPRasterLayer", "DERasterDataset"],
parameterType = "Required",
direction = "Input",
multiValue = True)
params = [in_raster]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, params):
return
def updateMessages(self, params):
return
def execute(self, params, messages):
rasters = ap.GetParameter(0)
if rasters is None:
ap.AddMessage("Parameter is of type None.")
else:
ap.AddMessage("Parameter is something other then None.")
returnWhen I open the Tool dialogue and add some rasters to the list, I get the "Parameter is oy type None" message after running the tool.