Get and Set DTYPE_COLORA/DTYPE_VECTOR4D on basecontainer or gedata
-
How do I get and set Vector4 and ColorA to the basecontainer/gedata?
I have tried pretty much every possible function and method but I dont seem to be able to use Vec4/Color4.I have managed to get it via unsafe c-style casting:
GeData ge(DTYPE_COLORA, DEFAULTVALUETYPE::DEFAULTVALUE); // Create // Get const CustomDataType* customPtr = ge.GetCustomDataTypeI(DTYPE_COLORA); maxon::ColorA color = *(maxon::ColorA*)customPtr; // Set color = maxon::ColorA(0.5, 0.1, 0.6, 0.7); CustomDataType* customPtrDst = (CustomDataType*)&color; ge.SetCustomDataTypeI(DTYPE_COLORA, *customPtrDst); // Get again to check if it worked const CustomDataType* customPtr2 = ge.GetCustomDataTypeI(DTYPE_COLORA); maxon::ColorA color2 = *(maxon::ColorA*)customPtr2;
But this is basically undefined behavior
-
-
This is a different question from:
https://developers.maxon.net/forum/topic/15823/data-datatypes-python-and-gui/6?_=1732092863717If you are referring to the same post i wrote on the backstage forum the suggestion i got there does not work:
const ColorA* color = data.GetCustomDataType<ColorA>();
^^ this does not work
I am asking how to use existing types here. And not new/custom ones
Specifically the DTYPE_COLORA and DTYPE_VECTOR4 and not the regular types DTYPE_COLOR and DTYPE_VECTOR -
I made this separate thread specifically because of the clear singular question rule i have been told to follow. And this is a different question from the question on custom data types.
-
Hey,
I appreciate you separating questions But there is code for this exact question in the old thread:
https://developers.maxon.net/forum/topic/15823/data-datatypes-python-and-gui/2.
You must wrap the
Data
asGeData
. One can of course play pointer games, as with pretty much everything, Cinema API types are usually just Maxon API types in disguise, but I would not recommend that.GeData
, i.e., aBaseContainer
, cannot storeData
directly.Cheers,
Ferdinand -
DTYPE_VECTOR4 and DTYPE_COLORA are not maxon::data types internally in c4d.
When I get or set them as maxon::data like your example code the GeData changes to a DTYPE_DATA instead
Additionally the existing 4d colorpicker GUI for DTYPE_COLORA will override the maxon::data type and reset it to whatever DTYPE_COLORA is internally. -
Hey @ECHekman,
COLORA and VECTOR4D are both Maxon datatypes. For how to deal with custom data types, you can have a look at this. But since this is a maxon data type and not a cinema data type, you cannot use a static_cast. When you do not want to store your maxon data wrapped as data, the only thing which remains is unsafely casting the data (but our style guide recommends using
reinterpret_cast
to make the unsafe nature obvious).const maxon::ColorA* myColor = reinterpret_cast<const maxon::ColorA*>(geData.GetCustomDataTypeI(DTYPE_COLORA));
I had a look and we do this in some UI related places too, so this might be a side effect of the 2024 changes to data types in relation to that specific custom gui.
Cheers,
Ferdinand