Question

Extract an attribute from geometry definition using Python

  • 29 March 2024
  • 3 replies
  • 72 views

Badge +11

Hi, when opening fbx in FME, I see a property with a description of the material in the geometry parts (pay attention to the line highlighted with a marker) 

FME has a python interpreter, with its own classes and functions.
I have already pulled out the coordinates of the points, in the code below

import fme
import fmeobjects


FeatureProcessor class (object):


def __init__(self):

passes

entering def (self, feature):


all_geom = function.getGeometry()

first_part = all_geom.getPartAt(0)

if type(first_part) == fmeobjects.FMEMesh:
meshs = first_part.getAsMultiSurface()


vertices_list = first_part.getVertices()
textur_coord_list = first_part.getTextureCoordinates()
textur_length = len(textur_coord_list)

if textur_length > 0:

for trian_mesh in first_part:

ver_index = trian_mesh.getVertexIndices()
textur_index = trian_mesh.getVertexNormalIndices()


newFeature = fmeobjects.FMEFeature()


pnt1 = vertices_list[ver_index[0]]
pnt1_t = textur_coord_list [textur_index [0]]

newFeature.setAttribute('X1',pnt1[0])
newFeature.setAttribute('Y1',pnt1[1])
newFeature.setAttribute('Z1',pnt1[2])
newFeature.setAttribute('U1',pnt1_t[0])
newFeature.setAttribute('V1',pnt1_t[1])

pnt2 = vertices_list[ver_index[1]]
pnt2_t = textur_coord_list [textur_index[1]]

newFeature.setAttribute('X2',pnt2[0])
newFeature.setAttribute('Y2',pnt2[1])
newFeature.setAttribute('Z2',pnt2[2])
newFeature.setAttribute('U2',pnt2_t[0])
newFeature.setAttribute('V2',pnt2_t[1])


pnt3 = vertices_list[ver_index[2]]
pnt3_t = textur_coord_list[textur_index[2]]

newFeature.setAttribute('X3',pnt3[0])
newFeature.setAttribute('Y3',pnt3[1])
newFeature.setAttribute('Z3',pnt3[2])
newFeature.setAttribute('U3',pnt3_t[0])
newFeature.setAttribute('V3',pnt3_t[1])

newFeature.setAttribute('geometry_name', feature.getAttribute('_geometry_name'))
newFeature.setAttribute('path_rootname', feature.getAttribute('path_rootname'))
newFeature.setAttribute ('appearance')

self.pyoutput(newFeature)
more:
newFeature_error = fmeobjects.FMEFeature()
newFeature_error.setAttribute('error_geometry', feature.getAttribute('_geometry_name'))
self.pyoutput(newFeature_error)


def close(self):

passes

def process_group(self):

passes

But it doesn't work for Appearance.
Judging by the help – appearance, this is part of the geometry. If you fall into the appearance class, then it should be a separate class, but how to pull it into separate variables is not described in the help

When referring to any function, it says that there are no such attributes.
I tried to refer to the feature unit itself, and to all its parts
-all_geometry
-first_part
-mesh
-trian_mesh

Please help with changing the code to extract attributes from the Front Appearance Preference line marked in the image above.

PS The FBX file for the test is attached.


3 replies

Userlevel 1
Badge +9

Hello, @muzhnasto.

We do have an AppearanceExtractor transformer that is more simple and may suffice your use case.

If you have gone by it and it does not suffice your use case, I can gladly give you some pointers for your python script.

Thanks!

Badge +3

Hello, @muzhnasto.

We do have an AppearanceExtractor transformer that is more simple and may suffice your use case.

If you have gone by it and it does not suffice your use case, I can gladly give you some pointers for your python script.

Thanks!

hi, how use python set texturecoord?

Userlevel 1
Badge +9

Hey, @charry.

Looking at the FME Python Documentation, setTextureCoordinate() doesn't exist. If you haven't checked them out yet, the fmeobjects.FMEMesh.appendTextureCoordinate() and fmeobjects.FMEMesh.appendTextureCoordinates() functions are available.

There is a transformer called TextureCoordinateSetter. If you haven't checked that out yet, that may suffice what you are trying to achieve.

Other than those resources, it would be helpful if you could elaborate more on what you are trying to achieve here. I’m more than glad to guide you.

Another option is searching if there is a similar question to what you're trying to accomplish in the Community. If not, you could create a question thread via Start a post on the navigation bar, and folks on the Community and other Safers can gladly help!

Reply