BaseLink Manual
A BaseLink handles a reference to a C4DAtom ( C4DAtomGoal ) element. This class should always be used instead of storing a pointer to the element itself. A link is typically resolved by providing the BaseDocument that hosts the linked entity.
A BaseLink is typically stored in a BaseContainer or GeData container. Several functions are available to access either the BaseLink object itself or the linked entity.
To retrieve BaseLink objects stored in a BaseContainer use:
To modify BaseLink objects stored in a BaseContainer use:
另请参阅 BaseContainer Manual .
To retrieve BaseLink objects stored in a GeData object ( GeData type is DA_ALIASLINK ) use:
To modify BaseLink objects stored in a GeData object ( GeData type is DA_ALIASLINK ) use:
另请参阅 GeData Manual .
// This example reads the object link of the given Instance Object.// read "Reference Object" parameter if (!instanceObject->GetParameter( DescID ( INSTANCEOBJECT_LINK ), data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// check if a BaseList2D element is linked and if it is a BaseObject if (linkedEntity != nullptr && linkedEntity-> IsInstanceOf ( Obase )) { const BaseObject * const linkedObject = static_cast< BaseObject * > (linkedEntity); ApplicationOutput ( "Linked Object: " + linkedObject-> GetName ()); }
BaseLink objects can be created with the usual functions:
BaseLink objects can be cloned or copied:
A BaseLink object stores a reference to an entity. This reference can be handled with these function:
The stored reference is typically resolved using the BaseDocument that contains the referenced entity. If the linked entity is not part of a BaseDocument the BaseLink can be forced to be resolved:
// insert "cube" into the document tempDoc-> InsertObject (cube, nullptr , nullptr ); AutoAlloc<BaseLink> link; if (link == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );
// store link link-> SetLink (cube); BaseObject * const resultA = static_cast< BaseObject * > (link-> GetLink (tempDoc)); if (resultA != nullptr ) ApplicationOutput ( "Could access the linked object." );
// removes the cube from the document cube-> 移除 (); BaseObject * const resultB = static_cast< BaseObject * > (link-> GetLink (tempDoc)); if (resultB == nullptr ) ApplicationOutput ( "Could not access the linked object." ); BaseObject * const resultC = static_cast< BaseObject * > (link-> ForceGetLink ()); if (resultC != nullptr ) ApplicationOutput ( "Could access the linked object." );
BaseLink objects can be stored in a HyperFile using:
A BaseLinkArray can be used to handle multiple BaseLink 对象。
References to entities can easily be added to and removed from the array using:
References to entities and other relevant data can easily be retrieved from the array using:
// check if the referenced element is a BaseObject if (goal-> IsInstanceOf ( Obase )) { const BaseObject * const obj = static_cast< BaseObject * > (goal); ApplicationOutput (obj-> GetName ()); } }
The BaseLinkArray can be converted into and built from an AtomArray .