I have a tool with a ValueTable consisting of two columns - text (GPString) and layer (GPFeatureLayer). When I fill the parameter with desired values (field names in the first column, some feature layers in the second column, I can run the tool.
Problem is that not every row is filled with a layer, so some rows have the field names only. The second row of the value table then returns:
- a geoprocessing Layer object if it has been filled with a feature layer or
- a geoprocessing value object if it has not been filled with a feature layer.
It looks like this:
I have a problem accessing the values row by row - I want to process all the rows with filled feature layer:
...
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = parameter("lokality", "Lokality", "GPFeatureLayer")
param1 = parameter("value_table", "Atributy a FeatureLayery", "GPValueTable", "Optional")
param1.columns = [["String", "Atribut"], ["GPFeatureLayer", "Limity"]]
def execute(self, parameters, messages):
"""The source code of the tool."""
lokality = parameters[0].valueAsText
valuetable = parameters[1].value
for v in valuetable:
# if v[1] has been filled, it is a geoprocessing layer object. I can check e.g. its name and continue
if v[1].name:
do something
# if v[1] has not been filled, it is an empty(?) geoprocessing value object, I don´t know how to handle this empty row
How can I check if a layer has been filled and process rows with filled layers only?
if v[1] is None:
orif v[1] == None:
Does that work?if not v[1]:
,if v[1] is None:
norif v[1] == None
not working... the empty GPFeatureLayer returns "something" even if it hasn´t been filled with a feature layer... that´s the problemif v[1].name:
to try-except block, so if v[1] was a layer object, it should go on, otherwise it would cast an exception. But I wouldn´t be much happy with this.