Skip to main content

I have a requirement to modify the list attribute generated on schema port.

Lets say my schema scanner have default attributes name, fme data type and native data type.

I want to look on name attribute and find any of its elements have OBJECTID string and remove if it is present.

I try to modify list attributes using python caller. It modifies the list elements when I overwrite using feature.setAttribute method it is not working and returns original schema attributes unmodified.

 

Any help using python would be highly appreciable.

 

Have you checked on the writer, some of them have a setting to remove/ignore named attributes. That way you wouldn’t have to modify the schema feature.

 


Have you checked on the writer, some of them have a setting to remove/ignore named attributes. That way you wouldn’t have to modify the schema feature.

 

Yeah this one helps to remove when known attributes. My requirement is to remove unknown attributes that generates on the fly.  

 


Try something like this in a PythonCaller:

# Generate a list containing a tuple for each attribute definition
names = feature.getAttribute('attribute{}.name')
fme_data_types = feature.getAttribute('attribute{}.fme_data_type')
native_data_types = feature.getAttribute('attribute{}.native_data_type')
input_schema = zip(names, fme_data_types, native_data_types)

# Filter out named attributes
attributes_to_delete = ('OBJECTID', 'MyAttribute1', 'MyAttribute2')
output_schema = [attr_def
for attr_def
in input_schema
if attr_def[0] not in attributes_to_delete]

# Need to explicitely remove all existing list items first, since
# simply setting new values does not automatically remove
# existing items outside of the range of new items.
feature.removeAttribute('attribute{}.name')
feature.removeAttribute('attribute{}.fme_data_type')
feature.removeAttribute('attribute{}.native_data_type')

# Set the schema feature attribute definitions
feature.setAttribute('attribute{}.name',
[attr_def[0] for attr_def in output_schema])
feature.setAttribute('attribute{}.fme_data_type',
[attr_def[1] for attr_def in output_schema])
feature.setAttribute('attribute{}.native_data_type',
[attr_def[2] for attr_def in output_schema])

Make sure to modify the contents of attributes_to_delete as needed.


Try something like this in a PythonCaller:

# Generate a list containing a tuple for each attribute definition
names = feature.getAttribute('attribute{}.name')
fme_data_types = feature.getAttribute('attribute{}.fme_data_type')
native_data_types = feature.getAttribute('attribute{}.native_data_type')
input_schema = zip(names, fme_data_types, native_data_types)

# Filter out named attributes
attributes_to_delete = ('OBJECTID', 'MyAttribute1', 'MyAttribute2')
output_schema = [attr_def
for attr_def
in input_schema
if attr_def[0] not in attributes_to_delete]

# Need to explicitely remove all existing list items first, since
# simply setting new values does not automatically remove
# existing items outside of the range of new items.
feature.removeAttribute('attribute{}.name')
feature.removeAttribute('attribute{}.fme_data_type')
feature.removeAttribute('attribute{}.native_data_type')

# Set the schema feature attribute definitions
feature.setAttribute('attribute{}.name',
[attr_def[0] for attr_def in output_schema])
feature.setAttribute('attribute{}.fme_data_type',
[attr_def[1] for attr_def in output_schema])
feature.setAttribute('attribute{}.native_data_type',
[attr_def[2] for attr_def in output_schema])

Make sure to modify the contents of attributes_to_delete as needed.

Thank you ​@david_r This is what I exactly looking for. removeAttribute is mandate before setAttribute. 

 


Reply