Import multiple values from model builder to script as a list of values

492
2
Jump to solution
08-24-2021 06:07 AM
Poncio
by
New Contributor II

As a complete beginner I recently started tinkering with modelbuilder and arcpy to solve a little annoying repetitive task. The model checks the highest number in a field and shows in a small window using a python script.

I get the values thrugh a SQL search by attribute and an summary statistics. The values end up as single strings in separate branches of the model, and I feed them to the script with arcpy.GetParameter()

For now I've used this with only two values as an example:

 

Spoiler

import arcpy
import Tkinter
# Set local variables
Piano2 = arcpy.GetParameter(0)
Piano3 = arcpy.GetParameter(1)

parent_widget = Tkinter.Tk()
label_widget = Tkinter.Label(parent_widget, text= "Piano2 = " + Piano2 + "\nPiano3 = " + Piano3)
label_widget.pack()
Tkinter.mainloop()

 

When the tool is complete it will have around 30-60 variables that will vary depending on the situation.

What I want t do is instead of importing every value as a varaible, import a list of all values.

I tried with "collect values" and just "arcpy.GetParameter" the list but it doesn't seem to work.

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

Collects Values tool will return a string of semicolon separated values such as AA;BB;CC;DD.

It is up to you to split this string and process as you wish.

Example:

DuncanHornby_0-1629811703224.png

 

View solution in original post

2 Replies
DuncanHornby
MVP Notable Contributor

Collects Values tool will return a string of semicolon separated values such as AA;BB;CC;DD.

It is up to you to split this string and process as you wish.

Example:

DuncanHornby_0-1629811703224.png

 

Poncio
by
New Contributor II

Works perfectly! Thanks 😄

0 Kudos