GeData Manual

About

GeData is a container class. This container is used to store data of all Cinema API data types that are supported by Cinema 4D.

Access

A GeData object can be used to directly change the value of a parameter of a C4DAtom object:

  • C4DAtom::GetParameter(): Gets the value of the given parameter.
  • C4DAtom::SetParameter(): Sets the value of the given parameter.

See also C4DAtom Manual.

A BaseContainer object stores multiple values using GeData objects:

  • BaseContainer::GetParameter(): Retrieves the GeData for the given DescID.
  • BaseContainer::SetParameter(): Sets the GeData for the given DescID.
  • BaseContainer::GetData(): Returns the GeData element for the given ID.
  • BaseContainer::SetData(): Sets the GeData element for the given ID.
  • BaseContainer::GetDataPointer(): Returns a read-only pointer to the GeData element for the given ID.
  • BaseContainer::GetDataPointers(): Sets an array of read-only GeData pointers for the given array of IDs.
  • BaseContainer::GetIndexData(): Returns a pointer to the GeData element for the given index.
  • BaseContainer::InsData(): Inserts a GeData element into the BaseContainer with the given ID.
  • BaseContainer::InsDataAfter(): Inserts a GeData element into the BaseContainer with the given ID after the specified other element.
  • BaseContainer::FindIndex(): Returns the index of the given GeData element.

See also BaseContainer Manual.

// This example reads the "Radius" parameter of the selected sphere object using GeData.
BaseObject* object = doc->GetActiveObject();
// check if the active object is not a "Sphere" object
if (object == nullptr || object->IsInstanceOf(Osphere) == false)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
GeData data;
// access PRIM_SPHERE_RAD parameter
if (!object->GetParameter(ConstDescID(DescLevel(PRIM_SPHERE_RAD)), data, DESCFLAGS_GET::NONE))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// check if container contains a float value
if (data.GetType() != DA_REAL)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const Float radius = data.GetFloat();
ApplicationOutput("Radius: " + String::FloatToString(radius));
NONE
Definition: asset_browser.h:1
@ DA_REAL
Float.
Definition: c4d_gedata.h:40
#define Osphere
Sphere.
Definition: ge_prepass.h:1119
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
#define ConstDescID(...)
Definition: lib_description.h:592
maxon::Float Float
Definition: ge_sys_math.h:57
@ PRIM_SPHERE_RAD
Definition: osphere.h:6
const char * doc
Definition: pyerrors.h:226
Definition: object.h:105

Data

Type

A GeData object stores data of a certain type.

  • GeData::SetDefault(): Sets the default value for the given data type.
  • ::DEFAULTVALUE: Dummy value for the constructor to initialize the object with the default value.
// Code like this is typically used in a NodeData::Init() function to make sure complex data types are initialized
BaseContainer& bc = ((BaseList2D*)node)->GetDataInstanceRef();
bc.SetData(1234, GeData { DTYPE_BASELISTLINK, DEFAULTVALUE });
@ DTYPE_BASELISTLINK
BaseLink.
Definition: lib_description.h:73
@ DEFAULTVALUE
Dummy value for the default value GeData constructor.
Definition: c4d_gedata.h:64
Definition: node.h:10
  • GeData::GetType(): Returns the type of the stored data.
Note
If the type is not set, GeData::GetType() returns ::DA_NIL.
// Using GetType() it is possible to check if the returned value is of the expected type.
GeData data;
const Bool success = sphere->GetParameter(ConstDescID(DescLevel(PRIM_SPHERE_RAD)), data, DESCFLAGS_GET::NONE);
if (!success)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// check type
if (data.GetType() != DA_REAL)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const Float radius = data.GetFloat();
maxon::Bool Bool
Definition: ge_sys_math.h:46

Access

The GeData class offers access functions for all supported data types. "Set" functions set the value and also change the data type if needed. "Get" functions return the value and are only allowed to be used if the data type matches.

::Int32 and ::Bool data (data type ::DA_LONG):

  • GeData::GetBool(): Returns the ::Bool value.
  • GeData::GetInt32(): Returns the ::Int32 value.
  • GeData::SetInt32(): Sets a ::Int32 value.

::Int64 data (data type ::DA_LLONG):

  • GeData::GetInt64(): Returns the ::Int64 value.
  • GeData::SetInt64(): Sets the ::Int64 value.

::Float data (data type ::DA_REAL):

  • GeData::GetFloat(): Returns the ::Float value.
  • GeData::SetFloat(): Sets the ::Float value.

See also Primitive Data Types Manual (Cinema API).

Void pointers (data type ::DA_VOID):

  • GeData::GetVoid(): Returns the void pointer.
  • GeData::SetVoid(): Stores the void pointer.
// This example stores a void pointer in a GeData object.
GeData data;
data.SetVoid(&object);
// ...
SomeObject* const obj = static_cast<SomeObject*>(data.GetVoid());
PyObject * obj
Definition: complexobject.h:60
Note
In general it is not recommended to use "raw" pointers, instead see BaseLink Manual.

Raw memory (data type ::DA_BYTEARRAY):

  • GeData::GetMemoryAndRelease(): Returns a pointer to the stored memory and hands over the ownership.
  • GeData::GetMemory(): Returns a pointer to the stored memory.
  • GeData::SetMemory(): Stores the raw memory.
// This example stores some raw memory in a GeData object.
GeData geData;
geData.SetMemory(memory, memSize);
const Char* const data = (Char*)geData.GetMemory(count);
if (data != nullptr)
{
String output;
output.SetCString(data, count);
}
Py_ssize_t count
Definition: abstract.h:640
Py_ssize_t char * output
Definition: unicodeobject.h:985
maxon::Char Char
Definition: ge_sys_math.h:47
maxon::Int Int
Definition: ge_sys_math.h:55

::Vector objects (data type ::DA_VECTOR):

  • GeData::GetVector(): Returns the ::Vector object.
  • GeData::SetVector(): Stores the ::Vector object.

See also Vector Manual (Cinema API).

::Matrix objects (data type ::DA_MATRIX):

  • GeData::GetMatrix(): Returns the ::Matrix object.
  • GeData::SetMatrix(): Stores the ::Matrix object.

See also Matrix Manual (Cinema API).

String objects and C4DUuid objects (data type ::DA_STRING):

  • GeData::GetString(): Returns the ::String object.
  • GeData::SetString(): Stores the ::String object.

See also String Manual (Cinema API).

Filename objects (data type ::DA_FILENAME):

  • GeData::GetFilename(): Returns the Filename object.
  • GeData::SetFilename(): Stores the Filename object.

See also Filename Manual.

C4DUuid objects: (data type ::DA_UUID):

  • GeData::GetUuid(): Returns the C4DUuid object.
  • GeData::SetUuid(): Stores the C4DUuid object.

BaseTime objects (data type ::DA_TIME):

  • GeData::GetTime(): Return the BaseTime object.
  • GeData::SetBaseTime(): Stores the BaseTime object.

See also BaseTime Manual.

Tristate (data type ::DA_TRISTATE):

  • GeData::SetTristate()

See also TriState Manual.

BaseContainer objects (data type ::DA_CONTAINER):

  • GeData::GetContainer(): Returns the BaseContainer.
  • GeData::SetContainer(): Stores the BaseContainer.
// This example stores a BaseContainer in a GeData object.
GeData data;
{
// store BaseContainer
BaseContainer bc;
bc.InsData(100, "foobar");
data.SetContainer(bc);
}
{
// access stored BaseContainer
const BaseContainer* bc = data.GetContainer();
if (bc == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
ApplicationOutput("Container Content: " + bc->GetData(100).GetString());
}
#define MAXON_SCOPE
Definition: apibase.h:2891

See also BaseContainer Manual.

BaseLink objects (data type ::DA_ALIASLINK):

  • GeData::GetBaseLink(): Returns the BaseLink object.
  • GeData::GetLink(): Returns the BaseList2D object referenced by the stored BaseLink object.
  • GeData::GetLinkAtom(): Returns the C4DAtomGoal object referenced by the stored BaseLink object.
  • GeData::SetBaseLink(): Stores the BaseLink object.
  • GeData::SetBaseList2D(): Stores a BaseLink object referencing a given BaseList2D object.

See also BaseLink Manual.

Custom data types:

  • GeData::GetCustomDataType(): Returns the custom data type object.
  • GeData::SetCustomDataType(): Stores a custom data type object.
// This example accesses a custom data type value from a GeData object.
// get data
GeData data;
if (!activeTag->GetParameter(ConstDescID(DescLevel(EXPRESSION_PRIORITY)), data, DESCFLAGS_GET::NONE))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// get custom data type value
PriorityData* const priorityData = data.GetCustomDataTypeWritable<PriorityData>();
if (priorityData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// edit data
priorityData->SetPriorityValue(PRIORITYVALUE_CAMERADEPENDENT, GeData { true });
activeTag->SetParameter(ConstDescID(DescLevel(EXPRESSION_PRIORITY)), data, DESCFLAGS_SET::NONE);
#define PRIORITYVALUE_CAMERADEPENDENT
::Bool Camera dependent.
Definition: customgui_priority.h:35
@ EXPRESSION_PRIORITY
Definition: texpression.h:6

Copy

The data of one GeData object can easily be copied to another object:

  • GeData::CopyData(): Copies the data to the given target GeData object.
  • GeData::operator=: Copies the GeData object.
// This example copies the data from one GeData
// object to another.
GeData stringData { "foobar" };
GeData intData(100);
stringData.CopyData(&intData, nullptr);
// check if container contains a String
if (intData.GetType() == DA_STRING)
ApplicationOutput("Data: " + intData.GetString());
@ DA_STRING
String.
Definition: c4d_gedata.h:46

Clear

A GeData object can be cleared.

  • GeData::Free(): Deletes all internal data and sets the type to ::DA_NIL.
// This example stores a String in the given GeData object just do delete it.
GeData data { "foobar" };
// check if container contains a String
if (data.GetType() == DA_STRING)
ApplicationOutput("data contains a string"_s);
data.Free();
// check if data has no type (data is not set)
if (data.GetType() == DA_NIL)
ApplicationOutput("data is empty"_s);
@ DA_NIL
No value.
Definition: c4d_gedata.h:37

Compare

Two GeData objects can be compared with the usual operators:

  • GeData::operator==: Returns true if two GeData objects are equal.
  • GeData::operator!=: Returns true if two GeData objects are not equal.
// This example compares two GeData objects with the "same" value but different types.
GeData intergerDataA;
intergerDataA.SetInt32(123);
GeData integerDataB;
integerDataB.SetInt64(123);
if (intergerDataA != integerDataB)
ApplicationOutput("Data is different"_s);

Disc I/O

A GeData object can be stored in a HyperFile:

  • HyperFile::ReadGeData(): Reads the GeData object from the HyperFile.
  • HyperFile::WriteGeData(): Writes the GeData object to the HyperFile.
// This example writes a GeData value to a HyperFile.
AutoAlloc<HyperFile> hf;
if (hf == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// open HyperFile to write
{
hf->WriteGeData(data);
hf->Close();
}
else
{
return maxon::IoError(MAXON_SOURCE_LOCATION, MaxonConvert(filename, MAXONCONVERTMODE::NONE), "Could not open file."_s);
}
PyCompilerFlags const char * filename
Definition: ast.h:15
WRITE
Problems writing the file.
Definition: ge_prepass.h:4
ANY
Definition: lib_substance.h:28
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
// This example reads a GeData value from a HyperFile stored on disc.
AutoAlloc<HyperFile> hf;
if (hf == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// open HyperFile to read
if (hf->Open(456, filename, FILEOPEN::READ, FILEDIALOG::ANY))
{
GeData data;
hf->ReadGeData(&data);
// check if container contains a String
if (data.GetType() == DA_STRING)
ApplicationOutput("Loaded GeData String: " + data.GetString());
hf->Close();
}
else
{
return maxon::IoError(MAXON_SOURCE_LOCATION, MaxonConvert(filename, MAXONCONVERTMODE::NONE), "Could not open file."_s);
}
READ
Problems reading the file.
Definition: ge_prepass.h:3

Further Reading