Select to view content in your preferred language

How to pass the iteration result to a parameter

802
4
Jump to solution
02-04-2021 03:10 AM
Sergey_Grechkin
Occasional Contributor

Hello everybody

I need to pass the list of domains that I have in the database in the script parameter. I didn’t find a suitable option in the data type. I decided to use ListDomains

import arcpy
a=set()
domains = arcpy.da.ListDomains("Database Connections\sde.sde")
for dom in domains:
    a.add(dom.name)
arcpy.GetParameterAsText(0)

but this option doesn't work

how do i pass a list to a script parameter?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Sergey_Grechkin
Occasional Contributor

David I solved my problem
I wrote in validation

def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
domains = arcpy.da.ListDomains("Database Connections\sde.sde")
my=[]
for domain in domains:
my.append(domain.name)
self.params[3].filter.list=sorted(my)
return

Now the parameter displays a list of the required data

import arcpy

fc = arcpy.GetParameterAsText(0) 
field = arcpy.GetParameterAsText(1) 
domain_1 = arcpy.GetParameterAsText(3) 
domain_2 = arcpy.da.ListDomains("Database Connections\sde.sde")
field_1 = arcpy.GetParameterAsText(2) 
cursor = arcpy.SearchCursor(fc)

b=set() 
a=set()
for domain in domain_2:
if domain.name == domain_1:
for val in domain.codedValues.keys():
b.add(val)
with open(r'R:\{}.txt'.format(field), 'w') as f:
for row in cursor:
k=row.getValue(field)
if k not in b:
a.add(row.getValue(field_1))
if len(a)>0:
f.write ('COLUMN {} IS NOT FILLED BY STANDARD'.format(field)+'\n')
for val in a:
f.write ('{}'.format(val)+'\n')
else:
f.write ('COLUMN {} FILLED BY STANDARD'.format(field)+'\n')

View solution in original post

4 Replies
DavidPike
MVP Frequent Contributor

Setting script tool parameters—ArcGIS Pro | Documentation 

If you look at the multivalue option it should be explained.

Sergey_Grechkin
Occasional Contributor

I don’t understand how to specify for GetParameterAsText() the result of the iteration 😞

I try SetParameterAsText

But SetParameterAsText only works on output and is not displayed in the script window

0 Kudos
DavidPike
MVP Frequent Contributor

I'm not completely sure of what you mean, can you not just have the sde connection file as a parameter, then do whatever else within the script? 

What's the full script and what do you want to achieve? 

0 Kudos
Sergey_Grechkin
Occasional Contributor

David I solved my problem
I wrote in validation

def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
domains = arcpy.da.ListDomains("Database Connections\sde.sde")
my=[]
for domain in domains:
my.append(domain.name)
self.params[3].filter.list=sorted(my)
return

Now the parameter displays a list of the required data

import arcpy

fc = arcpy.GetParameterAsText(0) 
field = arcpy.GetParameterAsText(1) 
domain_1 = arcpy.GetParameterAsText(3) 
domain_2 = arcpy.da.ListDomains("Database Connections\sde.sde")
field_1 = arcpy.GetParameterAsText(2) 
cursor = arcpy.SearchCursor(fc)

b=set() 
a=set()
for domain in domain_2:
if domain.name == domain_1:
for val in domain.codedValues.keys():
b.add(val)
with open(r'R:\{}.txt'.format(field), 'w') as f:
for row in cursor:
k=row.getValue(field)
if k not in b:
a.add(row.getValue(field_1))
if len(a)>0:
f.write ('COLUMN {} IS NOT FILLED BY STANDARD'.format(field)+'\n')
for val in a:
f.write ('{}'.format(val)+'\n')
else:
f.write ('COLUMN {} FILLED BY STANDARD'.format(field)+'\n')