Share

Understanding the Referenced Objects and Referenced Items

The following example shows how the referenced objects and referenced items can be used in a scene.

Example Scene Showing Referenced Objects and Referenced Items

Consider a scene named abc.fbx that contains a couple of cubes as shown in the following figure.

You can create a file reference object that references abc.fbx using the NamespaceImport function.

FBSystem().Scene.NamespaceImport( "NS", "abc.fbx", True )

This creates a scene structure as shown in the following figure.

You can now create a new cube and a parent/child constraint. You can also connect the newly created cube to one of the referenced items using the parent/child constraint.

# Create a parent/child constraint
lConstraintManager = FBConstraintManager()
for lIndex in range( lConstraintManager.TypeGetCount() ):
    if lConstraintManager.TypeGetName( lIndex ) == "Parent/Child":
        lParentChildConstraint = lConstraintManager.TypeCreateConstraint( lIndex )

# Create a new cube
lNewCube = FBModelCube( "NewCube" )
lNewCube.Show = True

# Find the "Cube 2" under file reference object "NS"
lNSCube2 = FBFindObjectByFullName( "Model::NS:Cube 2" )

# Set "NS:Cube 2" to be the child of the constraint
lProperty = lParentChildConstraint.PropertyList.Find( "Constrained object (Child)" )
lNSCube2.ConnectSrc( lProperty )

# Set NewCube to be the parent of the constraint
lProperty = lParentChildConstraint.PropertyList.Find( "Source (Parent)" )
lNewCube.ConnectDst(lProperty)

NS:Cube does not have a parent, so it can be parented to another scene object even though it belongs to the reference object. This can be achieved through the following script.

lParentCube = FBModelCube( "NewParent" )
lParentCube.Show = True
lNSCube = FBFindObjectByFullName( "Model::NS:Cube" )
lNSCube.Parent = lParentCube

This creates a scene structure as shown in the following figure.

NS:Cube 1 is the leaf node in the reference object, so it can be the parent of a non-referenced scene object. The following script parents a new scene object to NS:Cube 1.

lChildCube = FBModelCube( "NewChild" )
lChildCube.Show = True
lNSCube1 = FBFindObjectByFullName( "Model::NS:Cube 1" )
lChildCube.Parent = lNSCube1

This creates a scene structure as shown in the following figure.

You can also add animatable and non-animatable custom properties to referenced items using the PropertyCreate() function as follows:

lReferencedCube = FBFindObjectByFullName( "Model::NS:Cube" )
lReferencedCube.PropertyCreate( "CustomProp", FBPropertyType.kFBPT_double, "", False, True, None )

Running this script creates a non-animatable custom property named CustomProp on NS:Cube. The fourth parameter determines whether the newly created custom property is animatable. Additionally, the file reference edit reflects the changes whenever the new custom property is changed.

The same action can also be done on the reference object as follows:

lFileReference = FBFindObjectByFullName( "FileReference::NS" )
lFileReference.PropertyCreate( "CustomProp", FBPropertyType.kFBPT_double, "", False, True, None )

Was this information helpful?