CityEngine Export to OBJ : How to change the model's name

1082
1
10-31-2017 08:22 AM
baptistemuscagorry
New Contributor

Hi,

I'm trying to export  CityEngine 2017 generated models to an OBJ, but all of the models are currently called "Cityengine_test_0:from_extrude" with a number attached after. Now each shape has an attribute with it's actual name, but I'd like that attribute to be used as the exported model's name, so I can cross reference it with a excell file later.

Is that possible ?

Tags (2)
0 Kudos
1 Reply
CherylLau
Esri Regular Contributor

When exporting models to separate files, the filename for each model will have the shape name appended to the base name.  Therefore, you can write a python export script that changes the name of each shape to be whatever is in the object attribute.  Then, you can specify the python export script in the last parameter in the export dialog window.  To create a python export script, right click on the scripts folder -> New -> Python Module -> Module:Export.  Then, add the following code (lines 4-7) to the initExport function which is executed before the export is performed.  This code sets the name of the shape to whatever is in the object attribute called myName.

def initExport(exportContextOID):
    ctx = ScriptExportModelSettings(exportContextOID)

    shapes = ce.getObjectsFrom(ce.scene, ce.isShape)

    for s in shapes:
        ce.setName(s, ce.getAttribute(s, 'myName'))

Note:  Setting the shape's name in the initModel() function will not set the file name suffix.  In order for the file name suffix to be set, you need to set the shape in the initExport() function.