Multivalue Parameter in Custom tool adds extra quotes

430
2
07-19-2012 07:20 AM
ThomasStanley-Jones
New Contributor III
I struggled with this tool for many hours before I realized what was going wrong and why.  The issue was with a space in the name of the Feature layers that were being chosen in a multivalue parameter.  So this string would be returned: "'blah blah\blah';'meh meh\meh'".  Then when I tried to split out the string with .split(";"), the extra quotes would stay with the string and the tool that this value was passed to would break.  When there wasn't a space in the chosen parameters, I would get something like this: "blah;meh" and that would work fine.

Do I need to make this check in all my code when I don't know what the users will choose?  I haven't seen this in any of the examples in the help, so it caught me by surprise.  How do other people deal with this?

Here is the code that I came up with that works.

import os
import arcpy as ap

lines = ap.GetParameterAsText(0).split(";")
claims = ap.GetParameterAsText(1).replace("'","")
claims = claims.split(";")

for line in lines:
    for claim in claims:
        output = os.path.join(ap.GetParameterAsText(2),line + "_" + claim.split("\\")[1])
        ap.Intersect_analysis([line, claim],output,"","","LINE")
0 Kudos
2 Replies
markdenil
Regular Contributor II
That is pretty much what I would do; strip the unwanted characters with replace.
Do you need to make this check in all your code when you don't know what the users will choose?
You betcha.
A lot of problems can be traced to a loose nut on the keyboard.
0 Kudos
ThomasStanley-Jones
New Contributor III
For those that see this still, I've refined the code a bit from above.  Now if I'm getting values from a Multiple Parameter list in a custom tool I use this to get a clean list:

>> cleanList = [param.replace("'","") for param in arcpy.GetParameterAsText(0).split(";")]

I've never found any documentation on this from ESRI and it took a lot of time and frustration for me to figure this out as I wasn't a programmer before I started using ArcGIS.
0 Kudos