DynamicDescription
*
const
ddesc = op->
GetDynamicDescription
();
if
(ddesc ==
nullptr
)
return
maxon::UnexpectedError(
MAXON_SOURCE_LOCATION
);
DescID
groupID;
MAXON_SCOPE
{
// make group
BaseContainer
bc =
GetCustomDataTypeDefault
(
DTYPE_GROUP
);
bc.
SetString
(
DESC_NAME
,
"Group"
_s);
bc.
SetInt32
(
DESC_COLUMNS
, 1);
bc.
SetInt32
(
DESC_DEFAULT
, 1);
bc.
SetInt32
(
DESC_SCALEH
, 1);
groupID = ddesc->
Alloc
(bc);
}
MAXON_SCOPE
{
// make string parameter
BaseContainer
bc =
GetCustomDataTypeDefault
(
DTYPE_STRING
);
bc.
SetString
(
DESC_NAME
,
"Text 1"
_s);
bc.
SetInt32
(
DESC_SCALEH
, 1);
// set group as parent
bc.
SetData
(
DESC_PARENTGROUP
,
GeData
{
CUSTOMDATATYPE_DESCID
, groupID });
ddesc->
Alloc
(bc);
}
Access
The
DynamicDescription
object can be obtained from every
C4DAtom
:
The description of a specific user data parameter can be directly accessed:
// This example prints the name of the user data parameter with the ID 1.
DynamicDescription
*
const
ddesc =
object
->GetDynamicDescription();
if
(ddesc ==
nullptr
)
return
maxon::UnknownError(
MAXON_SOURCE_LOCATION
);
const
DescLevel
userData =
DescLevel
(
ID_USERDATA
,
DTYPE_SUBCONTAINER
, 0);
const
DescID
ID { userData,
DescLevel
(1) };
const
BaseContainer
*
const
bc = ddesc->
Find
(ID);
if
(bc !=
nullptr
)
ApplicationOutput
(
"Name: "
+ bc->
GetString
(
DESC_NAME
));
It is also possible to iterate through all user data parameter descriptions:
// This example prints the name of all user data parameters of the given object.
// get user data
DynamicDescription
*
const
ddesc =
object
->GetDynamicDescription();
if
(ddesc ==
nullptr
)
return
maxon::UnknownError(
MAXON_SOURCE_LOCATION
);
// browse user data
void
* handle = ddesc->
BrowseInit
();
if
(handle ==
nullptr
)
return
maxon::UnknownError(
MAXON_SOURCE_LOCATION
);
DescID
ID;
const
BaseContainer
* bc =
nullptr
;
// loop through all user data parameter descriptions
while
(ddesc->
BrowseGetNext
(handle, &ID, &bc))
{
// print name
if
(bc !=
nullptr
)
ApplicationOutput
(
"Name: "
+ bc->
GetString
(
DESC_NAME
));
}
ddesc->
BrowseFree
(handle);
Edit User Data
User data parameter descriptions can be added or removed:
// This example creates a new user data parameter
// get user data
DynamicDescription
*
const
ddesc =
object
->GetDynamicDescription();
if
(ddesc ==
nullptr
)
return
maxon::UnknownError(
MAXON_SOURCE_LOCATION
);
// configure type as vector
BaseContainer
bc(
DTYPE_VECTOR
);
ddesc->
FillDefaultContainer
(bc,
DTYPE_VECTOR
,
"Position"
);
// create new userdata parameter
ddesc->
Alloc
(bc);
-
注意
-
An empty
DescID
作为
DESC_PARENTGROUP
of a user data group will create a new tab in the Attribute Manager.
交互
User data parameters can include buttons. When such a button is pressed a message is sent to
NodeData::Message()
,见
NodeData::Message() Manual
.
// This example catches the event triggered when a user data button was pressed.
// The event is caught in the host NodeData::Message() function.
case
MSG_DESCRIPTION_COMMAND
:
{
DescriptionCommand
*
const
dc =
static_cast<
DescriptionCommand
*
>
(data);
if
(dc ==
nullptr
)
return
false
;
// check if the DescID has two levels (expected for user data)
if
(dc->
_descId
.
GetDepth
() == 2)
{
// check if it is a user data button
if
(dc->
_descId
[0].id ==
ID_USERDATA
)
{
const
maxon::String
stringID = maxon::String::IntToString(dc->
_descId
[1].id);
MessageDialog
(
"User Data Button clicked: "
_s + stringID);
}
}
break
;
}
杂项
Further functions of the
DynamicDescription
class are:
// This example prints the dirty count of the user data description.
const
UInt32
dirty = ddesc->
GetDirty
();
ApplicationOutput
(
"Dirty State: "
+
String::UIntToString
(dirty));
User Data Editor
The user data manager can be opened with these functions:
// This example opens the dialog to add user data descriptions to the given object.
BaseObject
*
const
object
= doc->
GetActiveObject
();
if
(
object
==
nullptr
)
return
maxon::IllegalArgumentError(
MAXON_SOURCE_LOCATION
);
AddDescription
(
object
);
延伸阅读
DynamicDescription * GetDynamicDescription()
BaseContainer GetCustomDataTypeDefault(Int32 type)
void MessageDialog(const maxon::String &str)
GeData * SetData(Int32 id, const GeData &n)
定义:
c4d_basecontainer.h:255
static String UIntToString(UInt32 v)
定义:
c4d_string.h:511
定义:
lib_description.h:327
void SetInt32(Int32 id, Int32 l)
定义:
c4d_basecontainer.h:505
void SetString(Int32 id, const maxon::String &s)
定义:
c4d_basecontainer.h:569
maxon::UInt32 UInt32
定义:
ge_sys_math.h:59
@ DTYPE_SUBCONTAINER
Sub-container.
定义:
lib_description.h:58
#define CUSTOMDATATYPE_DESCID
DescID custom data type ID.
定义:
lib_description.h:260
#define MAXON_SOURCE_LOCATION
定义:
memoryallocationbase.h:66
@ DESC_COLUMNS
Int32 Number of columns for layout groups (DTYPE_GROUP).
定义:
lib_description.h:127
#define MSG_DESCRIPTION_COMMAND
Sent by for example BUTTON description element. The corresponding data is DescriptionCommand.
定义:
c4d_baselist.h:375
void BrowseFree(void *&handle)
@ DTYPE_GROUP
Group.
定义:
lib_description.h:56
#define ID_USERDATA
User data ID.
定义:
lib_description.h:25
Message struct for MSG_DESCRIPTION_COMMAND.
定义:
lib_description.h:850
@ DTYPE_VECTOR
向量
定义:
lib_description.h:70
Represents a level within a DescID.
定义:
lib_description.h:286
@ DTYPE_STRING
String.
定义:
lib_description.h:72
DescID _descId
Description ID of the parameter that triggered the command.
定义:
lib_description.h:843
#define ApplicationOutput(formatString,...)
定义:
debugdiagnostics.h:207
const BaseContainer * Find(const DescID &descid)
@ DESC_SCALEH
Bool Scale element horizontally.
定义:
lib_description.h:135
Bool BrowseGetNext(void *handle, DescID *id, const BaseContainer **data)
String GetString(Int32 id, const maxon::String &preset=maxon::String()) const
定义:
c4d_basecontainer.h:387
@ DESC_NAME
String Name for standalone use.
定义:
lib_description.h:91
BaseObject * GetActiveObject(void)
@ DESC_PARENTGROUP
Int32/DescID Parent ID.
定义:
lib_description.h:117
@ DESC_DEFAULT
Int32/Float/Vector Default numeric value.
定义:
lib_description.h:120
void AddDescription(C4DAtom *bl)
定义:
lib_description.h:733
DescID Alloc(const BaseContainer &datadescription)
#define MAXON_SCOPE
定义:
apibase.h:2645
Bool FillDefaultContainer(BaseContainer &res, Int32 type, const String &name)
定义:
c4d_basecontainer.h:46