Skip to content
On this page

Rename objects using custom attributes

The Simplygon Max plug-in adds custom attributes to all processed objects, such as LOD switch- and naming attributes. This topic describes how name attributes can be used to rename imported objects.

The Simplygon plug-in does not allow writeback of multiple objects with the same name due to how the import / export pipeline are constructed. Some mapping and internal scripts are dependent on the name of objects and to avoid unexpected behavior we are choosing unique names for all objects. Max does, however, allow multiple objects with the same name.

To counter this issue we can use custom attributes to rename imported nodes, these attributes can be found under the object's user defined properties (Object properties -> User Defined -> User Defined Properties". In the image below there are three attributes related to the node name, the Original Node Name as it was when exported from Max, the Intended Node Name (including name formatting and index, if any) at import and the actual Imported Node Name.

Custom attributes:

LOD gets indexed

These attributes can be used to restore imported object names to their original- or intended name. If we want to rename an abject to its intended name, simply fetch the intended name and rename as in the script below.

MaxScript
-- fetch processed mesh names from Simplygon
    processedMeshes = sgsdk_GetProcessedMeshes()

    -- for all mesh names, print attributes
    -- and rename objects to original name
    for mesh in processedMeshes do
    (
        mMesh = getNodeByName mesh

        maxDeviation = getUserProp mMesh "MaxDeviation" 
        print (".MaxDeviation: " + maxDeviation as string)

        sceneRadius = getUserProp mMesh "SceneRadius" 
        print (".SceneRadius: " + sceneRadius as string)

        sceneMeshesRadius = getUserProp mMesh "SceneMeshesRadius" 
        print (".SceneMeshesRadius: " + sceneMeshesRadius as string)

        processedMeshesRadius = getUserProp mMesh "ProcessedMeshesRadius" 
        print (".ProcessedMeshesRadius: " + processedMeshesRadius as string)

        originalNodeName = getUserProp mMesh "OriginalNodeName" 
        print (".OriginalNodeName: " + originalNodeName as string)

        intendedNodeName = getUserProp mMesh "IntendedNodeName" 
        print (".IntendedNodeName: " + intendedNodeName as string)

        importedNodeName = getUserProp mMesh "ImportedNodeName" 
        print (".ImportedNodeName: " + importedNodeName as string)

        mMesh.name = originalNodeName
    )
python
from pymxs import runtime as rt

# fetch processed mesh names from Simplygon
processedMeshes = rt.sgsdk_GetProcessedMeshes()

# for all mesh names, print attributes
# and rename objects to original name
for mesh in processedMeshes:
    mMesh = rt.getNodeByName(mesh)

    maxDeviation = rt.getUserProp(mMesh, 'MaxDeviation')
    print('.MaxDeviation: ' + str(maxDeviation))

    sceneRadius = rt.getUserProp(mMesh, 'SceneRadius')
    print('.SceneRadius: ' + str(sceneRadius))

    sceneMeshesRadius = rt.getUserProp(mMesh, 'SceneMeshesRadius')
    print('.SceneMeshesRadius: ' + str(sceneMeshesRadius))

    processedMeshesRadius = rt.getUserProp(mMesh, 'ProcessedMeshesRadius')
    print('.ProcessedMeshesRadius: ' + str(processedMeshesRadius))

    originalNodeName = rt.getUserProp(mMesh, 'OriginalNodeName')
    print('.OriginalNodeName: ' + str(originalNodeName))

    intendedNodeName = rt.getUserProp(mMesh, 'IntendedNodeName')
    print('.IntendedNodeName: ' + str(intendedNodeName))

    importedNodeName = rt.getUserProp(mMesh, 'ImportedNodeName')
    print('.ImportedNodeName: ' + str(importedNodeName))

    mMesh.name = originalNodeName