<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Toolbox input parameter list: how to split name from group name? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272360#M67253</link>
    <description>&lt;P&gt;I have some ["GPRasterLayer", "DERasterDataset"] datatype&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 10:07:53 GMT</pubDate>
    <dc:creator>Manu</dc:creator>
    <dc:date>2023-03-28T10:07:53Z</dc:date>
    <item>
      <title>Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271851#M67227</link>
      <description>&lt;P&gt;I enabled &lt;STRONG&gt;multiple value input&lt;/STRONG&gt; for some parameter in an &lt;STRONG&gt;ArcMap 10.8&lt;/STRONG&gt; Python Toolbox.&lt;/P&gt;&lt;P&gt;In my script, I can easily split the input received from the UI by applying .split(";") since the input values are separated by ";".&lt;/P&gt;&lt;P&gt;However, when the user selects &lt;STRONG&gt;a layer from the drop-down&lt;/STRONG&gt; 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.&lt;/P&gt;&lt;P&gt;Is there some way to solve this?&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;combined_name.split("\\")
combined_name.split(r"\\")
r"{0}".format(combined_name).split("\\")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where combined_name is the respective name extracted from the input variable. All these attempts were without success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I tried the arcpy.GetParameter(0) suggestion with no success. This is the Toolbox I used to test it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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.")
        return&lt;/LI-CODE&gt;&lt;P&gt;When 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.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 11:08:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271851#M67227</guid>
      <dc:creator>Manu</dc:creator>
      <dc:date>2023-03-28T11:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271874#M67228</link>
      <description>&lt;P&gt;Instead of grabbing the input as text, you could grab the item itself using:&lt;BR /&gt;&lt;BR /&gt;arcpy.GetParameter()&lt;BR /&gt;&lt;BR /&gt;Then use a for loop to access the layer properties&lt;BR /&gt;&lt;BR /&gt;e.g.:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;layernames = arcpy.GetParameter(0)

for l in layernames:
   arcpy.AddMessage(l.name)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 13:10:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271874#M67228</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2023-03-27T13:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271920#M67229</link>
      <description>&lt;P&gt;split() returns a list so you have to use an index to grab the item that you want.&amp;nbsp; Maybe you are doing this, but its not in your code example?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = combined_name.split("\\")[-1]
fc = combined_name.split(r"\")[-1]
fc = r"{0}".format(combined_name.split("\\")[-1])&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 14:38:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271920#M67229</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-03-27T14:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271939#M67230</link>
      <description>&lt;P&gt;Unfortunately, arcpy.GetParameter(0) returns "None" for my ArcMap MultiValue input parameter... I guess this only works in ArcGIS Pro.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 15:15:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271939#M67230</guid>
      <dc:creator>Manu</dc:creator>
      <dc:date>2023-03-27T15:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271941#M67231</link>
      <description>&lt;P&gt;True, it returns a list. However, it returns a list of a single element which is still the combined name...&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 15:11:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1271941#M67231</guid>
      <dc:creator>Manu</dc:creator>
      <dc:date>2023-03-27T15:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272082#M67243</link>
      <description>&lt;P&gt;maybe try:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = str(combined_name).split("\\")[-1]
fc = str(combined_name).split(r"\")[-1]
fc = r"{0}".format(str(combined_name).split("\\")[-1])&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 18:46:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272082#M67243</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-03-27T18:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272331#M67249</link>
      <description>&lt;P&gt;This should work in ArcMap also. What Data Type do you have your multivalue input as? I've tried it with the option set to Layer and it works&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 07:54:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272331#M67249</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2023-03-28T07:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272346#M67251</link>
      <description>&lt;P&gt;I found some solution (here, I added a condition to check whether the input is some file path that I don't want to mess up. The tool accepts selecting loaded layers from a drop-down as well as browsing files):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def replace_grouped(in_var):
    if not os.path.isfile(in_var):
        out = repr(in_var).strip("'").split("\\")[-1]
    else:
        out = in_var
    return out&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or, in practice: Since somehow the ending \'" was introduced to some input variables but not others, I had to do the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def replace_grouped(in_var):
    if not os.path.isfile(in_var):
        out = repr(in_var).strip("'").strip('"').strip("'").strip('"') \
            .split("\\")[-1]
    else:
        out = in_var
    return out&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(very ugly, but I haven't found a better way to get rid of the trailing garbage yet.)&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 09:26:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272346#M67251</guid>
      <dc:creator>Manu</dc:creator>
      <dc:date>2023-03-28T09:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272360#M67253</link>
      <description>&lt;P&gt;I have some ["GPRasterLayer", "DERasterDataset"] datatype&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 10:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272360#M67253</guid>
      <dc:creator>Manu</dc:creator>
      <dc:date>2023-03-28T10:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox input parameter list: how to split name from group name?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272365#M67256</link>
      <description>&lt;P&gt;So it would work with raster layers, but not with a raster dataset, as that can't have a "Layer Name" property anyway. It only has layer properties once it is inside of an MXD or your have cast it as a feature layer, but if that hasn't happened/isn't the case then you wouldn't have the issue with it being part of a group layer anyway, so perhaps you could code around that e.g. an if statement based on feature type then a for loop to access layer name for those inputs that support it.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 10:39:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-input-parameter-list-how-to-split/m-p/1272365#M67256</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2023-03-28T10:39:18Z</dc:date>
    </item>
  </channel>
</rss>

