Skip to main content
Question

How to Pass AttributeCreator Values into PythonCaller Custom Array

  • June 13, 2023
  • 5 replies
  • 93 views

bhk
Contributor
Forum|alt.badge.img+3
  • Contributor
  • 7 replies

Having a Workspace like this

 

imageand the AttributeCreator like

 

 

imageCan you please let me know how I can pass the AttributeCreator Values into the PythonCaller. Like following pseudo code to loop in the attributes from the AttributeCreator

 

    def input(self, feature):
      for attr in .pythoncreator.getAttribute:
            print(attr )
        self.pyoutput(feature)

 

 

 

 

 

 

 

 

5 replies

virtualcitymatt
Celebrity
Forum|alt.badge.img+47

You can use "feature.getAllAttributeNames()" to get a list of all the attribute names.

 

e.g., attlist=feature.getAllAttributeNames()

 

You can then use feature.getAttribute() in a loop like:

 

  for att in attlist:

          att_name = att

att_value = feature.getAttribute(att)

print(att_name)

print(att_value)

 


david_r
Celebrity
  • 8394 replies
  • June 14, 2023

@virtualcitymatt​ is right, here's a code sample with indentation:

for attr_name in feature.getAllAttributeNames():
    attr_value = feature.getAttribute(attr_name)
    print('Attribute {} = {}'.format(attr_name, attr_value))

 You'll certainly also want to have a look at the fmeobjects documentation, found here: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.html


bhk
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 7 replies
  • June 14, 2023

@virtualcitymatt​ is right, here's a code sample with indentation:

for attr_name in feature.getAllAttributeNames():
    attr_value = feature.getAttribute(attr_name)
    print('Attribute {} = {}'.format(attr_name, attr_value))

 You'll certainly also want to have a look at the fmeobjects documentation, found here: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.html

Thanks for reply David but this is returning ALL Attributes in the workflow which I do not need them!

Attribute 1 = parks
Attribute 2 = swers
Attribute 3 = streets
Attribute 4 = schools
Attribute _creation_instance = 0
Attribute fme_feature_type = Creator
Attribute fme_geometry = fme_undefined
Attribute fme_type = fme_no_geom

and what I need is just this list from AttributeCreator

Attribute 1 = parks
Attribute 2 = swers
Attribute 3 = streets
Attribute 4 = schools

I checked the API but couldn't find out any parameter for fmeobjects.FMEFeature.getAllAttributeNames to limit this to only my specific AttributeCreator

Thanks

 


david_r
Celebrity
  • 8394 replies
  • June 14, 2023

Thanks for reply David but this is returning ALL Attributes in the workflow which I do not need them!

Attribute 1 = parks
Attribute 2 = swers
Attribute 3 = streets
Attribute 4 = schools
Attribute _creation_instance = 0
Attribute fme_feature_type = Creator
Attribute fme_geometry = fme_undefined
Attribute fme_type = fme_no_geom

and what I need is just this list from AttributeCreator

Attribute 1 = parks
Attribute 2 = swers
Attribute 3 = streets
Attribute 4 = schools

I checked the API but couldn't find out any parameter for fmeobjects.FMEFeature.getAllAttributeNames to limit this to only my specific AttributeCreator

Thanks

 

Indeed, fmeobjects does not keep track of which attribute was added or modified at which point in the workspace.


virtualcitymatt
Celebrity
Forum|alt.badge.img+47

Thanks for reply David but this is returning ALL Attributes in the workflow which I do not need them!

Attribute 1 = parks
Attribute 2 = swers
Attribute 3 = streets
Attribute 4 = schools
Attribute _creation_instance = 0
Attribute fme_feature_type = Creator
Attribute fme_geometry = fme_undefined
Attribute fme_type = fme_no_geom

and what I need is just this list from AttributeCreator

Attribute 1 = parks
Attribute 2 = swers
Attribute 3 = streets
Attribute 4 = schools

I checked the API but couldn't find out any parameter for fmeobjects.FMEFeature.getAllAttributeNames to limit this to only my specific AttributeCreator

Thanks

 

You can try and work around it by adding a prefix to the attributes you want to use. You can then remove this prefix in the python code​.