Select to view content in your preferred language

FBX model export file name based on object attribute.

345
3
05-11-2024 09:57 PM
MonicaClayton
New Contributor

Hello. I am looking for help with a very specific problem that I cannot find an answer to. The one answer I did find was from 2017 and I couldn't get it to work anyway. I have looked for the answer to this, and cannot find anyone who has asked this specifically.

When exporting my models out to FBX, is there a way to export them out based on a specific attribute value? Currently, they are all exported out individually as whatever the osm name is in the attribute list, i.e. way_06780000293 or something like that. I'd like to be able to export out he models based on a different attribute, like osm_id, or some other attribute instead. 

I found this  CityEngine Export to OBJ : How to change the model... - Esri Community, however I could not get the code that was given to work, and I don't know if that is OBJ export specific or if it should work for FBX. If it should, I just don't understand it then because it never worked correctly, or at all.

I appreciate the help.

Monica

 

 

0 Kudos
3 Replies
JonasObertuefer
Esri Contributor

Hi @MonicaClayton,

Your goal is to export individual building/shapes to FBX from an OSM import and then name the exported files according to their OSM id, is that correct?

The linked thread/script seems to do what you want to achieve. What exactly did not work for you? Can you share your script?

Best,
Jonas

0 Kudos
MonicaClayton
New Contributor

@JonasObertuefer You are correct, it does, but only if the osm_id attribute is a string/text and not a considered a number. So then my next question is, is there a way to make this work as is, or add a text/string attribute to all of the footprints in bulk?

Edit: I have exported out the shp file, added it to ArcPro, done what I needed to do to the attribute list, and then reimported it into CityEngine, but then when the same rpk is applied, it does not generate the buildings the same way. 

Before export:

MonicaClayton_0-1716210180045.png

After export:

MonicaClayton_1-1716210229812.png

Nothing has changed about them, except an added attribute making the osm_id to a text/string.

 

0 Kudos
JonasObertuefer
Esri Contributor

Is this a RPK of the Building_From_OpenStreetMap.cga rule? This rule requires some object attributes of type float to work correctly: 

"building__levels", "roof__height", "roof__direction", "building__levels__underground", "building__min_level", "min_heigh"

In python you can check the type of an attribute with type() and then cast to a certain type as required with float() or str(). In case of the OSM id you probably want to remove the decimals before converting it to a string, this can be done by first casting it to int()

def initExport(exportContextOID):
    ctx = ScriptExportModelSettings(exportContextOID)
    
    shapes = ce.getObjectsFrom(ce.selection, ce.isShape)
    
    for s in shapes:
        osmId = ce.getAttribute(s, "osm_id")
        ce.setName(s, str(int(osmId)))

 

You can ofc also directly set/get object attributes for many objects using python, without using an export script:

shapes = ce.getObjectsFrom(ce.selection, ce.isShape)
ce.setAttribute(shapes, 'myName', 'myValue')

How to work with python in CityEngine is explained in this tutorial:

Cheers,
Jonas

0 Kudos