Question

Hello, I'm using FME to read IFC files and I would like to know if it is possible to get GeometryPropertyExtractor (to get traits) by calling the FME API into PythonCaller ? Thank in advance Best regards Bruno Hilaire

  • 28 September 2023
  • 7 replies
  • 7 views

Hello, I'm using FME to read IFC files and I would like to know if it is possible to get GeometryPropertyExtractor (to get traits) by calling the FME API into PythonCaller ? Thank in advance Best regards Bruno Hilaire

7 replies

Userlevel 3
Badge +18

Hello @bruno​ 

The FME Objects API have a method for retrieving traits if given the trait name (documentation for fmeobjects.FMEGeometry.getTraits() here).

Is there a reason why you're looking to do this using the FME Objects Python API rather than using one of FME's transformers?

Hello,

Thank for your input. In fact, I already used the GeometryPropertyExtractor Transformer to get traits from an IFC object. But in my case, I have to first search for a property named "CodeObject" and then, search for a list of properties depdending of the value of "CodeObject". With the transformer, it seems that I must write the name of theses traits and can not pass as an argument a list containing the names to search for. That's why I try to solve this issue with FME Objects Python API

Best regards

Bruno Hilaire

Hello,

I tried to use FMEGeometry.getTrait with the following code :

class FeatureProcessor(object):

  def __init__(self):

    pass

  def input(self,feature):

    geom = feature.getGeometry()

    res = geom.getTrait('LOC_ID')

    feature.setAttribute('Extracted', str(res))

 

But the result is 'None'

 

While I get the right value using the GeometryPropertyExtractor Transformer

 

Do you have an idea why the python script doesn't give the same result than the Transformer ?

 

Thank you in advance

 

Best regards

 

Bruno

Userlevel 3
Badge +18

Hello,

I tried to use FMEGeometry.getTrait with the following code :

class FeatureProcessor(object):

  def __init__(self):

    pass

  def input(self,feature):

    geom = feature.getGeometry()

    res = geom.getTrait('LOC_ID')

    feature.setAttribute('Extracted', str(res))

 

But the result is 'None'

 

While I get the right value using the GeometryPropertyExtractor Transformer

 

Do you have an idea why the python script doesn't give the same result than the Transformer ?

 

Thank you in advance

 

Best regards

 

Bruno

Hello @bruno​ 

I tested using the getTraits method and was able to get the value of a trait using Python code similar to yours. I have attached the workspace along with data showing this.

If the method is returning null values, it may be the LOC_ID trait does not exist on the feature or its value is null. Are you able to share a small sample of your data along with your workspace?

Hello @bruno​ 

I tested using the getTraits method and was able to get the value of a trait using Python code similar to yours. I have attached the workspace along with data showing this.

If the method is returning null values, it may be the LOC_ID trait does not exist on the feature or its value is null. Are you able to share a small sample of your data along with your workspace?

Hello Debbi,

Thank you for you reply. In fact, I am working with IFC file. You will find the in the zip file the tests I made. For example, I look for a property named "2D Detail Level". When I use the GeometryPropertyExtractor, I find that 69 IfcWindow have this property. But with the python script, this property is never found. If I look for attribute directy attached to the IFC object "GlobalId" for example, it works. But when I look for the IFC property contained in an IFC property set (as "2D Detail Level"), the getTrait method doesn't work.

Did I make a mistake ?

Thank you in advance

Best regards

Bruno

Userlevel 3
Badge +18

Hello @bruno​ 

I tested using the getTraits method and was able to get the value of a trait using Python code similar to yours. I have attached the workspace along with data showing this.

If the method is returning null values, it may be the LOC_ID trait does not exist on the feature or its value is null. Are you able to share a small sample of your data along with your workspace?

Hello @bruno​,

Thanks for the dataset. gettrait("2D Detail Level") doesn't work in the PythonCaller because the specific trait does not exist on that level of geometry (the root aggregate geometry) unlike GlobalId, Name, tag, etc. The geometry the method is working on does not contain the trait--one of its descendant geometry contains this 2D Detail Level trait.

It works in the GeometryPartExtractor as the Geometry Part Selection parameter is set to "all parts". When using fmeobjects, you must do the same and split the aggregate into pieces using the fmeobjects.FMEFeature.splitAggregate() method

def input(self,feature):
for part in feature.splitAggregate(True):
geom = part.getGeometry()
if "2D Detail Level" in geom.getTraitNames():
res = geom.getTrait('2D Detail Level')
feature.setAttribute('Traits', res)
self.pyoutput(feature)

Note it is possible to extract all traits that exist on a feature with the GeometryPartExtractor transformer by leaving the Trait to Extract table blank. Hopefully this information will create another option for your workflow.

Hello Debbi,

Thak you so much, it works perfectly. I finally used the GeometryPartExtractor transformer because I didn't know that it was possible to recover all the traits by leaving the Trait to Extract table blank.

Best regards

Bruno

 

Reply