GeData Manual

About

GeData is a container class. This container is used to store data of all classic 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:

See also C4DAtom Manual.

A BaseContainer object stores multiple values using GeData objects:

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 || object->IsInstanceOf(Osphere) == false)
return maxon::OK;
GeData data;
// access PRIM_SPHERE_RAD parameter
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();

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();
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(DescID(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();

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):

Int64 data (data type DA_LLONG):

Float data (data type DA_REAL):

See also Primitive Data Types Manual (Classic).

Void pointers (data type DA_VOID):

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

Raw memory (data type DA_BYTEARRAY):

// This example stores some raw memory in a GeData object.
GeData geData;
geData.SetMemory(memory, memSize);
Int count;
Char* data = (Char*)geData.GetMemory(count);
if (data)
{
String output;
output.SetCString(data, count);
}

Vector objects (data type DA_VECTOR):

See also Vector Manual (Classic).

Matrix objects (data type DA_MATRIX):

See also Matrix Manual (Classic).

String objects and C4DUuid objects (data type DA_STRING):

See also String Manual (Classic).

Filename objects (data type DA_FILENAME):

See also Filename Manual.

C4DUuid objects: (data type DA_UUID):

BaseTime objects (data type DA_TIME):

See also BaseTime Manual.

Tristate (data type DA_TRISTATE):

See also TriState Manual.

BaseContainer objects (data type DA_CONTAINER):

// This example stores a BaseContainer in a GeData object.
GeData data;
{
// store BaseContainer
bc.InsData(100, "foobar");
data.SetContainer(bc);
}
{
// access stored BaseContainer
if (!bc)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
ApplicationOutput("Container Content: " + bc->GetData(100).GetString());
}

See also BaseContainer Manual.

BaseLink objects (data type DA_ALIASLINK):

See also BaseLink Manual.

Custom data types:

// This example accesses a custom data type value from a GeData object.
// get data
GeData data;
if (!activeTag->GetParameter(DescLevel(EXPRESSION_PRIORITY), data, DESCFLAGS_GET::NONE))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// get custom data type value
PriorityData* const priorityData = static_cast<PriorityData*>(customData);
if (priorityData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// edit data
activeTag->SetParameter(DescLevel(EXPRESSION_PRIORITY), data, DESCFLAGS_SET::NONE);

Copy

The data of one GeData object can easily be copied to another 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());

Clear

A GeData object can be cleared.

// 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);

Compare

Two GeData objects can be compared with the usual operators:

// 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:

// This example writes a GeData value to a HyperFile.
if (!hf)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// open HyperFile to write
if (hf->Open(456, filename, FILEOPEN::WRITE, FILEDIALOG::ANY))
{
hf->WriteGeData(data);
hf->Close();
}
else
{
return maxon::IoError(MAXON_SOURCE_LOCATION, MaxonConvert(filename, MAXONCONVERTMODE::NONE), "Could not open file."_s);
}
// This example reads a GeData value from a HyperFile stored on disc.
if (!hf)
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);
}

Further Reading