Empty output generated with python script tool in model builder?

325
6
03-04-2020 06:56 AM
RPGIS
by
Regular Contributor

Hi,

So I have been trying to figure out why some of my script tools work and some don't. They are very simple and straight forward, but for some reason they don't generate an output. I am using the script below in conjunction with other added variables in the model that I am working on.

import arcpy
arcpy.env.overwriteOutput = True

#Set parameters
inputList = arcpy.GetParameterAsText(0)

w = ''.join(list(inputList))

x = w.find('-')

if x > 0:
    y = w.replace('-', '_')
    if y.find(';') > 0:
        z = y.replace(';','_')

        print z
        #Output Parameter 
        arcpy.SetParameterAsText(1, z)

        #Add Message
        arcpy.AddMessage('string {} added'.format(z))

I have the input set to any values with multivalue set to yes.

If anyone has any ideas on how or why this isn't working and could help me with this I would greatly appreciate it.

Robert

0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

what is "inputList" ?

most esri multivalue input parameters normally provide them as a semicolon delimited string which you need to split

 inputList = "a;b;c"

inputList
'a;b;c'

inputList.split(";")
['a', 'b', 'c']
0 Kudos
RPGIS
by
Regular Contributor

Hi Dan,

The inputlist is derived from multiple inputs that (depending on the user) could attach several variables inside model, have them all connect to the script tool, and then it would combine all the strings based on those inputs. The reason I am doing this (or at least trying) is because I have several personal databases where I need to get the names of the personal databases, a list of specific feature classes in those databases, and get the counts for each feature class. I tried using a standalone python script, which didn't work, and then I thought about trying a combination of script tools and regular tools in a model. I also came across some really old documentation from Esri (ArcView, ArcEditor, and ArcInfo (9.3)) that kind of explained why a standalone python script may not work with personal databases but the tools do. So if there are other solutions that you, or anyone, may know of I would be really glad to hear them.

Thanks,

Robert

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Robert, If a parameter is multivalued (ie one parameter, letting you select several things at a time), then a semicolon string is returned.

If you have multiple values that you want to work with, then you would have had multiple parameters or you actually provided a real list since you only have one parameter

inputList = arcpy.GetParameterAsText(0)

So show what is actually provided would help... does it look like ['a', 'b', 'c'] or "a,b,c" or "a;b;c"  or some variant.

0 Kudos
RPGIS
by
Regular Contributor

Sorry Dan,

I should have provided what that would have looked like when it is finished.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

The semicolon delimited list is indeed there.

The first input from the list is

dmdb_amdb_tmdb_amdb_bmdb_amdb_smdb_emdb

which I am wildly guessing isn't what you want. Further splitting is possible for whatever it is you are using it for, but you might be ending up with a list of lists.

good luck

0 Kudos
RPGIS
by
Regular Contributor

Hi Dan,

So with random luck I was actually able to get it to work.

Thanks for the help Dan.

0 Kudos