C4DAtom Manual

内容表

关于

C4DAtom is the base class for many entities in the classic Cinema 4D API. Along with GeListNode and BaseList2D it implements the basic functionality of most classic entities. C4DAtomGoal is the extension of the C4DAtom class that allows to create safe references to an C4DAtom entity with a BaseLink .

Access

A pointer to a C4DAtom is typically provided by resolving a BaseLink to an entity. See BaseLink Manual .

// This example gets the link of the given "Instance Object" and accesses the linked C4DAtom.
GeData data;

// read the "Reference Object" parameter if (!instanceObject->GetParameter( DescID { INSTANCEOBJECT_LINK }, data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

const BaseLink * const link = data. GetBaseLink (); if (link == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); const C4DAtom * const linkedAtom = link-> GetLinkAtom (doc); if (linkedAtom != nullptr ) { ApplicationOutput ( "Got linked C4DAtom" _s); }

C4DAtom pointers to any kind of entity are often stored in AtomArray objects. See AtomArray Manual .

Allocation/Deallocation

C4DAtom instances cannot be created directly. Only instances of C4DAtom based classes can be created.

类型

C4DAtom gives access to information about the type and class of the specific entity:

// This example checks if the given C4DAtom is a BaseObject. // If so it checks if the atom is also a point object.

// check the classification const Int32 classification = atom-> GetClassification (); if (classification == Obase ) { const BaseObject * const baseObject = static_cast< BaseObject * > (atom); const 向量 position = baseObject-> GetMg (). off ; ApplicationOutput ( "Position: " + String::VectorToString (position));

// check if it is an instance of a given class if (atom-> IsInstanceOf ( Opoint )) { PointObject * const pointObject = static_cast< PointObject * > (atom); const Int32 pointCount = pointObject-> GetPointCount (); ApplicationOutput ( "Point Count: " + String::IntToString (pointCount));

// check the specific type if (atom-> GetType () == Offd ) { // If this point object is a FFD object, change its grid size. atom-> SetParameter ( FFDOBJECT_SIZE , 向量 (500, 500, 500), DESCFLAGS_SET::USERINTERACTION ); EventAdd (); } } }

注意
C4DAtom::IsInstanceOf() can also be used to check the classification and element type.
C4DAtom::GetType() can be used to get the ID of any entity that is not listed in the documentation.

拷贝

C4DAtom based entities are easily copied and cloned:

The copy flags are:

The AliasTrans argument of these functions is optional. If an AliasTrans instance is provided it is used to update BaseLink parameters of the copied entities. If a BaseLink references an element that is also copied the BaseLink is changed to reference the copy of the originally referenced entity.

// This example clones the objects defined in the given AtomArray. // The clones are created using an AliasTrans object. // So if an object is referenced by another object in the object list // this reference is redirected to the clone of the original object. AutoAlloc<AliasTrans> alias; // check if the AliasTrans was allocated // and can be initiated if (alias == nullptr || !alias-> Init (doc)) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); doc-> GetActiveObjects (objectSelection, GETACTIVEOBJECTFLAGS::NONE ); const Int32 selectionCount = objectSelection->GetCount(); if (selectionCount == 0) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION ); for ( Int32 i = 0; i < selectionCount; ++i) { BaseObject * const object = static_cast< BaseObject * > (objectSelection->GetIndex(i)); if ( object == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); BaseObject * const clone = static_cast< BaseObject * > ( object ->GetClone( COPYFLAGS::NONE , alias)); if (clone == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); const String objectName = object ->GetName(); clone-> SetName (objectName + " clone" ); doc-> InsertObject (clone, nullptr , nullptr ); }

// this fixes links to elements that are not part of the given object selection alias-> Translate ( true );

Disc I/O

A C4DAtom based element can be read from and written to a HyperFile .

If the entity is handled inside another read/write function ( NodeData::Read() and NodeData::Write() ) these functions must be used:

警告
These functions are generally not recommended for third party plugins.

Parameter Properties

Parameter descriptions and IDs are managed with these functions:

// This example prints the names of all parameters in the current parameter description. AutoAlloc<Description> description; if (description == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// get the Description of the given object if (!object-> GetDescription (description, DESCFLAGS_DESC::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); void * handle = description-> BrowseInit (); const BaseContainer * bc = nullptr ; DescID id, gid;

// loop through all elements of the description while (description-> GetNext (handle, &bc, id , gid)) { ApplicationOutput ( "Parameter Name: " + bc-> GetString ( DESC_NAME )); } description-> BrowseFree (handle);

参数

The value of parameters should be changed with C4DAtom::GetParameter() and C4DAtom::SetParameter() . In this way one can be sure, the parameters are set correctly even if the entity does not store the data in its BaseContainer .

注意
Some parameters must be set with DESCFLAGS_SET::USERINTERACTION .
// This example gets the active object of the given BaseDocument. // If it is a "Cube" its size is increased. BaseObject * const cube = doc-> GetActiveObject ();

// check if the active object is a "Cube" object if (cube == nullptr || !cube-> IsInstanceOf ( Ocube )) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION ); GeData data; const DescID cubeLenID { PRIM_CUBE_LEN };

// read the "Size" parameter if (!cube-> GetParameter (cubeLenID, data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); 向量 size = data. GetVector (); size = size + 向量 { 100 }; cube-> SetParameter (cubeLenID, size, DESCFLAGS_SET::NONE );

注意
Parameter IDs are defined with DescID objects. See DescID Manual .

Dirty States

The dirty status of an entity is a number that is increased every time the entity is changed.

The dirty flags are:

// This example checks the dirty states of the given BaseObject before and after an edit.

// Get the current dirty checksums UInt32 dataDirtyStatus = baseObject-> GetDirty ( DIRTYFLAGS::DATA ); UInt32 matrixDirtyStatus = baseObject-> GetDirty ( DIRTYFLAGS::MATRIX ); ApplicationOutput ( "Data Status: " + String::UIntToString (dataDirtyStatus)); ApplicationOutput ( "Martix Status: " + String::UIntToString (matrixDirtyStatus));

// edit the object's data baseObject-> SetName ( "New Name" _s);

// Check the dirty checksums dataDirtyStatus = baseObject-> GetDirty ( DIRTYFLAGS::DATA ); matrixDirtyStatus = baseObject-> GetDirty ( DIRTYFLAGS::MATRIX ); ApplicationOutput ( "Data Status: " + String::UIntToString (dataDirtyStatus)); ApplicationOutput ( "Martix Status: " + String::UIntToString (matrixDirtyStatus));

Hierarchy dirty (HDirty) states are used to check if the given entity or some child elements in the hierarchy were changed. Typically used with a BaseDocument GeListHead .

The hierarchy dirty flags are:

// Get the current dirty checksums UInt32 materialsDirtyState = doc-> GetHDirty ( HDIRTYFLAGS::MATERIAL ); UInt32 objectsDirtyState = doc-> GetHDirty ( HDIRTYFLAGS::OBJECT ); ApplicationOutput ( "Materials Status: " + String::UIntToString (materialsDirtyState)); ApplicationOutput ( "Objects Status: " + String::UIntToString (objectsDirtyState));

// edit a material BaseMaterial * const mat = doc-> GetActiveMaterial ();

// check if the active material is a Cinema 4D standard material if (mat && mat-> IsInstanceOf ( Mmaterial )) { mat-> SetParameter ( MATERIAL_COLOR_COLOR , 向量 (255, 0, 0), DESCFLAGS_SET::NONE ); }

// check the dirty checksums materialsDirtyState = doc-> GetHDirty ( HDIRTYFLAGS::MATERIAL ); objectsDirtyState = doc-> GetHDirty ( HDIRTYFLAGS::OBJECT ); ApplicationOutput ( "Materials Status: " + String::UIntToString (materialsDirtyState)); ApplicationOutput ( "Objects Status: " + String::UIntToString (objectsDirtyState));

Messages

Entities in Cinema 4D often communicate by sending messages to each other. Such a message can be used to inform the element about some event or to retrieve data from the element. A message can be sent to an entity with these functions:

// This example gets the active object and checks if it is a point object. // If so its points are moved in object space. // The object itself is informed about this edit with the message MSG_UPDATE. BaseObject * const activeObject = doc-> GetActiveObject ();

// check if the active object is a point object if (activeObject == nullptr || !activeObject-> IsInstanceOf ( Opoint )) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION ); PointObject * const pointObject = static_cast< PointObject * > (activeObject); 向量 * const points = pointObject-> GetPointW (); if (points == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); const Int32 pointCount = pointObject-> GetPointCount (); for ( Int32 i = 0; i < pointCount; ++i) points[i] = points[i] + 向量 (0, 100, 0); pointObject-> 消息 ( MSG_UPDATE );

另请参阅 NodeData::Message() Manual .

延伸阅读

PointObject::GetPointW
Vector * GetPointW(void)
定义: c4d_baseobject.h:1432
DIRTYFLAGS::DATA
@ DATA
Container changed.
BaseDocument::InsertObject
void InsertObject(BaseObject *op, BaseObject *parent, BaseObject *pred, Bool checknames=false)
String::UIntToString
static String UIntToString(UInt32 v)
定义: c4d_string.h:511
PointObject
定义: c4d_baseobject.h:1389
C4DAtom::GetHDirty
UInt32 GetHDirty(HDIRTYFLAGS mask) const
定义: c4d_baselist.h:1559
BaseObject
定义: c4d_baseobject.h:224
DescID
定义: lib_description.h:327
C4DAtom::GetDescription
Bool GetDescription(Description *description, DESCFLAGS_DESC flags)
UInt32
maxon::UInt32 UInt32
定义: ge_sys_math.h:59
PointObject::GetPointCount
Int32 GetPointCount(void) const
定义: c4d_baseobject.h:1439
BaseDocument::GetActiveMaterial
BaseMaterial * GetActiveMaterial(void)
DIRTYFLAGS::MATRIX
@ MATRIX
Matrix changed.
BaseObject::GetMg
Matrix GetMg() const
定义: c4d_baseobject.h:482
GETACTIVEOBJECTFLAGS::NONE
@ NONE
None.
C4DAtom::GetClassification
Int32 GetClassification() const
定义: c4d_baselist.h:1379
Ocube
#define Ocube
Cube.
定义: ge_prepass.h:1040
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
DESCFLAGS_SET::USERINTERACTION
@ USERINTERACTION
DESCFLAGS_SET::NONE
@ NONE
None.
DESCFLAGS_DESC::NONE
@ NONE
None.
C4DAtom::GetDirty
UInt32 GetDirty(DIRTYFLAGS flags) const
定义: c4d_baselist.h:1543
Opoint
#define Opoint
Point - PointObject.
定义: ge_prepass.h:1022
MSG_UPDATE
#define MSG_UPDATE
Must be sent if the bounding box has to be recalculated. (Otherwise use MSG_CHANGE....
定义: c4d_baselist.h:340
String
定义: c4d_string.h:38
String::IntToString
static String IntToString(Int32 v)
定义: c4d_string.h:495
Description::GetNext
Bool GetNext(void *handle, const BaseContainer **bc, DescID &id, DescID &groupid)
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
AliasTrans::Init
Bool Init(BaseDocument *doc)
定义: c4d_baselist.h:3010
maxon::Vec3< maxon::Float64, 1 >
Offd
#define Offd
FFD.
定义: ge_prepass.h:983
PRIM_CUBE_LEN
@ PRIM_CUBE_LEN
定义: ocube.h:6
BaseDocument::GetActiveObjects
void GetActiveObjects(AtomArray &selection, GETACTIVEOBJECTFLAGS flags) const
GeData
定义: c4d_gedata.h:82
Obase
#define Obase
Base object - BaseObject.
定义: ge_prepass.h:1021
C4DAtom
定义: c4d_baselist.h:1331
BaseList2D::SetName
void SetName(const maxon::String &name)
定义: c4d_baselist.h:2324
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
FFDOBJECT_SIZE
@ FFDOBJECT_SIZE
定义: offd.h:6
AliasTrans::Translate
void Translate(Bool connect_oldgoals)
定义: c4d_baselist.h:3018
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
C4DAtom::Message
Bool Message(Int32 type, void *data=nullptr)
定义: c4d_baselist.h:1394
HDIRTYFLAGS::OBJECT
@ OBJECT
Object data mask.
Description::BrowseInit
void * BrowseInit()
Mmaterial
#define Mmaterial
Standard material.
定义: ge_prepass.h:950
向量
maxon::Vec3< maxon::Float64, 1 > Vector
定义: ge_math.h:145
EventAdd
void EventAdd(EVENT eventflag=EVENT::NONE)
maxon::Mat3::off
V off
The translation vector.
定义: matrix.h:279
AutoAlloc
定义: ge_autoptr.h:36
DESCFLAGS_GET::NONE
@ NONE
None.
HDIRTYFLAGS::MATERIAL
@ MATERIAL
Material data mask.
BaseContainer::GetString
String GetString(Int32 id, const maxon::String &preset=maxon::String()) const
定义: c4d_basecontainer.h:387
DESC_NAME
@ DESC_NAME
String Name for standalone use.
定义: lib_description.h:91
MATERIAL_COLOR_COLOR
@ MATERIAL_COLOR_COLOR
定义: mmaterial.h:56
BaseDocument::GetActiveObject
BaseObject * GetActiveObject(void)
C4DAtom::IsInstanceOf
Bool IsInstanceOf(Int32 id) const
定义: c4d_baselist.h:1373
Description::BrowseFree
void BrowseFree(void *&handle)
String::VectorToString
static String VectorToString(const Vector32 &v, Int32 nnk=-1)
定义: c4d_string.h:571
C4DAtom::GetType
Int32 GetType() const
定义: c4d_baselist.h:1348
BaseMaterial
定义: c4d_basematerial.h:27
GeData::GetBaseLink
BaseLink * GetBaseLink(void) const
定义: c4d_gedata.h:493
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
GeData::GetVector
const Vector & GetVector(void) const
定义: c4d_gedata.h:451
COPYFLAGS::NONE
@ NONE
None.
BaseContainer
定义: c4d_basecontainer.h:46

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1