NodeData::Message() Manual

内容表

关于

NodeData based classic plugin classes can implement NodeData::Message() to receive various messages that are sent for several reasons. This page shows how to handle the most important messages.

注意
Messages sent to C4DAtom::Message() and received by NodeData::Message() are synchronous messages.

NodeData::Message() corresponds to C4DAtom::Message() and C4DAtom::MultiMessage() .

用法

Basics

NodeData::Message() is called by Cinema 4D to inform the plugin class about an event or to request some information from it. Additional data is handed over in form of a void pointer that has to be cast into the correct type depending on the message.

// This example shows a primitive implementation of Message().
virtual Bool Message( GeListNode * node, Int32 type, void * data) { switch (type) { case ( MSG_UPDATE ): { break ; }

// more cases

注意
If the plugin class hosts a subshader, HandleShaderMessage() must be used to relay certain messages to this subshader. Especially MSG_GETALLASSETS , MSG_RENAMETEXTURES and MSG_MULTI_CLEARSUGGESTEDFOLDER should be handled.

过滤

With C4DAtom::MultiMessage() it is possible to send messages to the complete object hierarchy or branches (see also Heads and Branches ). In this case it is possible to filter certain messages so they are not sent to the child elements of the given element.

返回 true to let the message pass and false to block it.

The data of this message is MessageFilter :

数据

Messages can be used to retrieve data from an entity. For generic purposes this message exists:

The data of this message is RetrievePrivateData :

// This example sends MSG_RETRIEVEPRIVATEDATA to the generator to get its internal data. RetrievePrivateData data; data. flags = 0; data. data = nullptr ;

// send message to retrieve private data if (object-> 消息 ( MSG_RETRIEVEPRIVATEDATA , &data)) { // got data if (data. data != nullptr ) { Int32 * const value = static_cast< Int32 * > (data. data ); ApplicationOutput ( "Got value: @" _s, *value); } }

// This example receives a MSG_RETRIEVEPRIVATEDATA message // and sets the pointer to the internal data.

case MSG_RETRIEVEPRIVATEDATA : { RetrievePrivateData * const pdata = static_cast< RetrievePrivateData * > (data); if (pdata) { pdata-> data = &(this->_value); return true ; } break ; }

Assets

Plugins use external assets typically by referencing the asset file in a Filename parameter. When the document is saved with "Save Project with Assets" or is rendered via Team Render these assets have to be collected. To collect these assets Cinema 4D sends these messages to all scene elements:

警告
MSG_GETALLASSETS is not sent to MaterialData plugins.
// This example adds the file path stored in a parameter to the asset list.

case MSG_GETALLASSETS : { AssetData * const assetData = static_cast< AssetData * > (data); if (assetData == nullptr ) return true ;

// checks if only texture assets should be added if (assetData-> _flags & ASSETDATA_FLAG::TEXTURESONLY ) return true ; BaseList2D * const baseList2D = static_cast< BaseList2D * > (node); if (baseList2D) { // get the file name const Filename path = baseList2D-> GetData (). GetFilename (EXAMPLE_GENERATOR_PARAMETER_FILE);

// check if the file name is set if (path. IsPopulated ()) { // add the file name assetData-> 添加 (path, nullptr ); } } break ; }

// This example removes the folder part of the file path of the object's parameter.

case MSG_MULTI_CLEARSUGGESTEDFOLDER : { BaseContainer & bc = ( static_cast< BaseList2D * > (node))->GetDataInstanceRef(); const Filename path = bc. GetFilename (EXAMPLE_GENERATOR_PARAMETER_FILE);

// check if the directory part of the path contains anything if (path. GetDirectory (). IsPopulated ()) { bc. SetFilename (EXAMPLE_GENERATOR_PARAMETER_FILE, path. GetFile ()); } break ; }

Further asset related messages are:

另请参阅 BaseDocument Convert and Export and Disc I/O .

Icon

Cinema 4D sends a message to ObjectData and TagData based plugins so they can change their icon dynamically.

The data of this message is GetCustomIconData :

// This example simply sets a standard icon as the object's icon.

case MSG_GETCUSTOMICON : { // get data GetCustomIconData * const iconData = static_cast< GetCustomIconData * > (data); if (iconData == nullptr ) return true ;

// set as filled iconData-> filled = true ;

// load a standard Cinema icon return GetIcon ( RESOURCEIMAGE_OK , iconData-> dat ); }

An object or tag can include the ID_BASELIST_ICON_SETTINGS_GROUP parameter group. It is possible to add a custom color mode to that group and to define that custom color when reacting to MSG_GETCUSTOMICON .

// This example adds a new color mode to the object's "Icon Settings" in the Init() function. BaseObject * const op = static_cast< BaseObject * > (node); BaseContainer * const bc = op-> GetDataInstance ();

// add custom color mode BaseContainer iconSettings, iconSpecialModes; iconSpecialModes. SetString (0, "Custom Color Mode" _s); iconSettings. SetContainer ( ID_ICONCHOOSER_SETTINGS_SPECIALCASES , iconSpecialModes);

// since we are going to use our custom MSG_GETCUSTOMICONS code, set this to true so parent object (e.g. BaseObject) will ignore MSG_GETCUSTOMICONS messages. iconSettings. SetBool ( ID_ICONCHOOSER_SETTINGS_PARENT_IGNORE , true );

// set icon settings container into baselist2d data container bc-> SetContainer ( ID_ICONCHOOSER_SETTINGS , iconSettings);

// default color mode: custom mode bc-> SetInt32 ( ID_BASELIST_ICON_COLORIZE_MODE , ID_BASELIST_ICON_COLORIZE_MODE_CUSTOM + 1);

// This example defines the color of the custom color mode as well as the ID of the used icon.

case ( MSG_GETCUSTOMICON ): { GetCustomIconData * const cid = static_cast< GetCustomIconData * > (data); if (cid == nullptr ) return false ; BaseObject * const baseObject = static_cast< BaseObject * > (node); const BaseContainer & bc = baseObject-> GetDataInstanceRef ();

// define color for custom color mode CustomIconSettings settings; FillCustomIconSettingsFromBaseList2D (settings, bc, node-> GetType (), true ); 设置。 _specialColors .Resize(1) iferr_ignore ( "Can't do anything about it here." _s);

// get some float value from the object itself GeData parameterData; node-> GetParameter (ICONTEST_OBJECT_VALUE, parameterData, DESCFLAGS_GET::NONE );

// create RGB value for custom color mode const maxon::Float value = parameterData. GetFloat () / 360.0; const maxon::Color hsv { value, 1.0, 1.0 }; const maxon::Color rgb = maxon::HsvToRgb (hsv); // set custom color 设置。 _specialColors [0] = rgb;

// callback defining the icon ID CustomIconGetIdDelegate getIdCallback = [node]() -> Int32 { // read a parameter from the object GeData data; node-> GetParameter (ICONTEST_OBJECT_ID, data, DESCFLAGS_GET::NONE ); const Int32 id = data. GetInt32 ();

// set the icon ID based on that parameter value if ( id > 0) return Ocube ; return Osphere ; };

// define custom ID GetCustomIcon (*cid, settings, false , &getIdCallback); break ; }

交互

It is possible to drag and drop something onto objects and tags in the Object Manager. These elements are informed about this event with this message:

// This example checks if the file dropped onto an object is neither image nor scene file. // If so, the file path will be stored in one of the object's parameters.

case MSG_DRAGANDDROP : { // get data DragAndDrop * const dnd = static_cast< DragAndDrop * > (data); if (dnd == nullptr ) return false ;

// ignore this when the object itself is dragged if (dnd-> flags & DRAGANDDROP_FLAG_SOURCE ) return true ;

// check if a file (scene or image) is dragged onto the object const Bool typeIsNotFilename = dnd-> type != DRAGTYPE_FILENAME_OTHER ; const Bool dataNotSet = dnd-> data == nullptr ; if (typeIsNotFilename || dataNotSet) return false ;

// drop if (dnd-> flags & DRAGANDDROP_FLAG_DROP ) { // get filename Filename * const file = static_cast< Filename * > (dnd-> data ); // set parameter node-> SetParameter (EXAMPLE_GENERATOR_PARAMETER_FILE, *file, DESCFLAGS_SET::NONE ); } dnd-> flags |= DRAGANDDROP_FLAG_ACCEPT ; return true ; }

When the user double clicks on an icon in the Object Manger this message is sent to the corresponding element.

// This example simply opens a message dialog when one // double-clicks on the icon in the Object Manager.

case MSG_EDIT : { MessageDialog ( "You double-clicked on this object!" _s); break ; }

Attribute Manager Interaction

Users edit scene elements and their parameters with the Attribute Manager. The Attribute Manager sends multiple messages to the edited object to inform about the interaction.

// This example just opens a message dialog when a button was pressed.

case MSG_DESCRIPTION_COMMAND : { DescriptionCommand * const dc = ( DescriptionCommand *)data; if (dc == nullptr ) return false ;

// check the ID of the pressed button if (dc-> _descId [0].id == EXAMPLE_GENERATOR_BUTTON) { MessageDialog ( "You pressed the button." _s); } break ; }

Further messages are:

// This example defines the content of a popup menu of a "POPUP" parameter element.

case MSG_DESCRIPTION_POPUP : { DescriptionPopup * const dp = static_cast< DescriptionPopup * > (data);

// check the ID of the popup element if (dp-> _descId [0] == EXAMPLE_GENERATOR_POPUP) { // if nothing is chosen // the menu should be build if (dp-> _chosen == 0) { BaseContainer menu; 菜单。 InsData (1, "Options" _s); 菜单。 InsData (10, "Option A" _s); 菜单。 InsData (20, "Option B" _s); dp-> _popup . InsData (0, menu); } else { const Int32 option = dp-> _chosen ; ApplicationOutput ( "You chose option @" , option); } } break ; }

// This example receives a custom GUI messages sent from // the Attribute Manager. If the messages is sent from // a specific custom GUI type, the message data is printed.

case MSG_DESCRIPTION_CUSTOMGUI_NOTIFICATION : { DescriptionCustomGuiNotification * dcgn = static_cast< DescriptionCustomGuiNotification * > (data); if (dcgn) { // get parameter ID const Int32 parameterID = dcgn-> _descId [-1].id; ApplicationOutput ( "Message from parameter: " + String::IntToString (parameterID));

// check the type of custom GUI if (dcgn-> _customGuiId == ID_CUSTOMGUI_COLORSTRING_GFG) { // check the message ID if (dcgn-> _subId == MSG_DESCRIPTION_COLORSTRING_COLORCHANGE) { // get data from the message const BaseContainer * messageData = dcgn-> _data ; if (messageData) { const 向量 color = messageData-> GetVector (MSG_DESCRIPTION_COLORSTRING_COLOR); ApplicationOutput ( "New Color: " + String::VectorToString (color)); } } } } break ; }

另请参阅 Description Notifications .

These messages are related to the Take system:

Creation

// This example adds a tag to the object when it is created from the menu.

case MSG_MENUPREPARE : { BaseObject * const op = static_cast< BaseObject * > (node); BaseTag * const annotationTag = op-> MakeTag ( Tannotation ); if (annotationTag) { const String annotation { "This is a new object." }; annotationTag-> SetParameter ( ANNOTATIONTAG_TEXT , annotation, DESCFLAGS_SET::NONE ); } break ; }

Document Related

Certain events trigger a broadcast message that is sent to all elements of a BaseDocument .

Some messages are just send to SceneHookData plugins. See also BaseDocument::SendInfo() .

// This example catches MSG_DOCUMENTINFO in a ObjectData::Message() function. // When the document is loaded the value of a old (legacy) parameter is copied // into a new parameter.

case MSG_DOCUMENTINFO : { DocumentInfoData * const msg = static_cast< DocumentInfoData * > (data); if (msg == nullptr ) return false ;

// switch message sub-type switch (msg-> type ) { case MSG_DOCUMENTINFO_TYPE_LOAD : { BaseObject * const op = static_cast< BaseObject * > (node); if (!op) return false ; BaseContainer & bc = op-> GetDataInstanceRef (); bc. SetInt32 (NEW_PARAMETER, bc. GetInt32 (OLD_PARAMETER)); ApplicationOutput ( "document is loaded" _s); break ; } } break ; }

Also these messages are sent to all elements:

A special message is sent when the element is animated:

延伸阅读

DRAGANDDROP_FLAG_SOURCE
#define DRAGANDDROP_FLAG_SOURCE
Drag and drop message is send to the source objects (objects that were dragged).
定义: c4d_baselist.h:893
DocumentInfoData
Message struct for the MSG_DOCUMENTINFO message.
定义: c4d_baselist.h:986
BaseList2D::GetData
BaseContainer GetData()
定义: c4d_baselist.h:2266
DescriptionPopup
Message struct for MSG_DESCRIPTION_POPUP.
定义: lib_description.h:860
BaseContainer::GetFilename
Filename GetFilename(Int32 id, const Filename &preset=Filename()) const
定义: c4d_basecontainer.h:403
BaseContainer::GetVector
Vector GetVector(Int32 id, const Vector &preset=Vector()) const
定义: c4d_basecontainer.h:371
BaseList2D
定义: c4d_baselist.h:2144
MessageDialog
void MessageDialog(const maxon::String &str)
DRAGANDDROP_FLAG_DROP
#define DRAGANDDROP_FLAG_DROP
Drop.
定义: c4d_baselist.h:888
BaseContainer::SetFilename
void SetFilename(Int32 id, const Filename &f)
定义: c4d_basecontainer.h:583
DragAndDrop::data
void * data
The pointer to the dragged elements. Depends on the drag type.
定义: c4d_baselist.h:921
Filename::GetFile
const Filename GetFile(void) const
CustomIconSettings
定义: c4d_baselist.h:1237
DRAGTYPE_FILENAME_OTHER
@ DRAGTYPE_FILENAME_OTHER
Other filename.
定义: gui.h:763
ANNOTATIONTAG_TEXT
@ ANNOTATIONTAG_TEXT
定义: tannotation.h:21
ASSETDATA_FLAG::TEXTURESONLY
@ TEXTURESONLY
Only return texture assets.
BaseList2D::GetDataInstance
const BaseContainer * GetDataInstance() const
定义: c4d_baselist.h:2283
BaseObject
定义: c4d_baseobject.h:224
BaseContainer::SetInt32
void SetInt32(Int32 id, Int32 l)
定义: c4d_basecontainer.h:505
BaseContainer::SetString
void SetString(Int32 id, const maxon::String &s)
定义: c4d_basecontainer.h:569
DragAndDrop::type
Int32 type
The drag type: DRAGTYPE.
定义: c4d_baselist.h:920
MSG_DRAGANDDROP
#define MSG_DRAGANDDROP
Received by an element in the Object manager when something is dropped on it. The corresponding data ...
定义: c4d_baselist.h:441
ID_BASELIST_ICON_COLORIZE_MODE_CUSTOM
@ ID_BASELIST_ICON_COLORIZE_MODE_CUSTOM
定义: obaselist.h:12
Tannotation
#define Tannotation
Annotation.
定义: ge_prepass.h:1242
BaseTag
定义: c4d_basetag.h:46
Filename
Manages file and path names.
定义: c4d_file.h:93
MSG_DOCUMENTINFO
#define MSG_DOCUMENTINFO
Sent as broadcast message by the document when it is loaded, saved , merged etc. The corresponding da...
定义: c4d_baselist.h:445
MSG_RETRIEVEPRIVATEDATA
#define MSG_RETRIEVEPRIVATEDATA
A generic private message to retrieve data from an object. Specific for every type of object so no pu...
定义: c4d_baselist.h:385
MSG_GETALLASSETS
#define MSG_GETALLASSETS
定义: c4d_shader.h:987
Ocube
#define Ocube
Cube.
定义: ge_prepass.h:1040
maxon::Float
Float64 Float
定义: apibase.h:193
BaseContainer::SetBool
void SetBool(Int32 id, Bool b)
定义: c4d_basecontainer.h:498
DESCFLAGS_SET::NONE
@ NONE
None.
MSG_MULTI_CLEARSUGGESTEDFOLDER
#define MSG_MULTI_CLEARSUGGESTEDFOLDER
定义: c4d_baselist.h:505
MSG_DESCRIPTION_COMMAND
#define MSG_DESCRIPTION_COMMAND
Sent by for example BUTTON description element. The corresponding data is DescriptionCommand.
定义: c4d_baselist.h:375
DragAndDrop::flags
UInt32 flags
定义: c4d_baselist.h:918
RESOURCEIMAGE_OK
#define RESOURCEIMAGE_OK
定义: ge_prepass.h:3436
ID_ICONCHOOSER_SETTINGS_SPECIALCASES
@ ID_ICONCHOOSER_SETTINGS_SPECIALCASES
定义: customgui_iconchooser.h:37
BaseObject::MakeTag
BaseTag * MakeTag(Int32 type, BaseTag *pred=nullptr)
GetCustomIconData::filled
Bool filled
Set this to true if the icon data dat was changed or set.
定义: c4d_baselist.h:1110
GetCustomIcon
Bool GetCustomIcon(GetCustomIconData &cid, const CustomIconSettings &settings, Bool drawBeforeColoring=false, CustomIconGetIdDelegate *getIdCallback=nullptr, CustomIconDrawDelegate *drawCallback=nullptr)
DescriptionPopup::_chosen
Int32 _chosen
Selected element of the popup.
定义: lib_description.h:862
MSG_EDIT
#define MSG_EDIT
Allows elements to do some action if the user edits the element (double-click e.g....
定义: c4d_baselist.h:383
GeListNode
Represents a C4DAtom that resides in a 4D list.
定义: c4d_baselist.h:1767
GetCustomIconData::dat
IconData * dat
定义: c4d_baselist.h:1108
Osphere
#define Osphere
Sphere.
定义: ge_prepass.h:1041
DescriptionPopup::_popup
BaseContainer _popup
Popup container.
定义: lib_description.h:864
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
MSG_DESCRIPTION_POPUP
#define MSG_DESCRIPTION_POPUP
Allows popup menu handling in the Attribute Manager. The corresponding data is DescriptionPopup.
定义: c4d_baselist.h:376
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
iferr_ignore
#define iferr_ignore(...)
定义: resultbase.h:1399
DescriptionCommand
Message struct for MSG_DESCRIPTION_COMMAND.
定义: lib_description.h:850
maxon::Vec3< maxon::Float64, 1 >
AssetData::Add
Bool Add(const Filename &fn, BaseList2D *bl, Int32 parameterId=-1, Bool netRequestOnDemand=false, Int32 channelIndex=-1, const maxon::CString &nodePath=maxon::GetZeroRef< maxon::CString >(), const maxon::Id &nodeSpace=maxon::GetZeroRef< maxon::Id >())
GeData::GetInt32
Int32 GetInt32(void) const
定义: c4d_gedata.h:427
BaseList2D::GetDataInstanceRef
const BaseContainer & GetDataInstanceRef() const
定义: c4d_baselist.h:2299
CustomIconSettings::_specialColors
maxon::BaseArray< maxon::Color > _specialColors
Special colors (e.g. Light Color for light object)
定义: c4d_baselist.h:1242
MSG_MENUPREPARE
#define MSG_MENUPREPARE
Allows tags, objects, shaders etc. to do some setup work when called from the menu....
定义: c4d_baselist.h:384
Filename::GetDirectory
const Filename GetDirectory(void) const
DescriptionCustomGuiNotification::_subId
Int32 _subId
The message type sub-ID. Depending on the custom GUI implementation a different sub-ID can be passed ...
定义: lib_description.h:913
GeData
定义: c4d_gedata.h:82
DescriptionBaseMessage::_descId
DescID _descId
Description ID of the parameter that triggered the command.
定义: lib_description.h:843
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
C4DAtom::Message
Bool Message(Int32 type, void *data=nullptr)
定义: c4d_baselist.h:1394
maxon::Col3< Float, 1 >
AssetData::_flags
ASSETDATA_FLAG _flags
The asset data flags: ASSETDATA_FLAG.
定义: c4d_baselist.h:1045
DescriptionCustomGuiNotification::_data
const BaseContainer * _data
The data of the message, can be nullptr.
定义: lib_description.h:914
FillCustomIconSettingsFromBaseList2D
void FillCustomIconSettingsFromBaseList2D(CustomIconSettings &settings, const BaseContainer &data, Int32 defaultIconId, Bool fillDefault)
Private.
DescriptionCustomGuiNotification
定义: lib_description.h:910
ID_BASELIST_ICON_COLORIZE_MODE
@ ID_BASELIST_ICON_COLORIZE_MODE
定义: obaselist.h:10
MSG_DESCRIPTION_CUSTOMGUI_NOTIFICATION
#define MSG_DESCRIPTION_CUSTOMGUI_NOTIFICATION
Sent by a custom GUI to the parent. The corresponding data is DescriptionCustomGuiNotification.
定义: c4d_baselist.h:403
DESCFLAGS_GET::NONE
@ NONE
None.
BaseContainer::InsData
GeData * InsData(Int32 id, const GeData &n)
定义: c4d_basecontainer.h:238
GetCustomIconData
Message struct for the MSG_GETCUSTOMICON message.
定义: c4d_baselist.h:1101
BaseContainer::SetContainer
void SetContainer(Int32 id, const BaseContainer &s)
定义: c4d_basecontainer.h:597
DescriptionCustomGuiNotification::_customGuiId
Int32 _customGuiId
The custom GUI plugin ID.
定义: lib_description.h:912
maxon::Delegate
定义: delegate.h:235
MSG_GETCUSTOMICON
#define MSG_GETCUSTOMICON
Every atom can return a custom icon with this message. The corresponding data is GetCustomIconData.
定义: c4d_baselist.h:437
DRAGANDDROP_FLAG_ACCEPT
#define DRAGANDDROP_FLAG_ACCEPT
Accept.
定义: c4d_baselist.h:889
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
MSG_DOCUMENTINFO_TYPE_LOAD
#define MSG_DOCUMENTINFO_TYPE_LOAD
Document was loaded.
定义: c4d_baselist.h:457
DragAndDrop
Message struct for the MSG_DRAGANDDROP message.
定义: c4d_baselist.h:909
ID_ICONCHOOSER_SETTINGS_PARENT_IGNORE
@ ID_ICONCHOOSER_SETTINGS_PARENT_IGNORE
定义: customgui_iconchooser.h:38
maxon::HsvToRgb
MAXON_ATTRIBUTE_FORCE_INLINE COLORTYPE HsvToRgb(const COLORTYPE &hsv)
定义: gfx_image_functions_color_conversions.h:51
ID_ICONCHOOSER_SETTINGS
#define ID_ICONCHOOSER_SETTINGS
Id to store icon settings data into BaseList2D basecontainer.
定义: customgui_iconchooser.h:33
Filename::IsPopulated
Bool IsPopulated() const
RetrievePrivateData::flags
Int32 flags
The flags for the retrieval.
定义: c4d_baselist.h:829
String::VectorToString
static String VectorToString(const Vector32 &v, Int32 nnk=-1)
定义: c4d_string.h:571
C4DAtom::GetType
Int32 GetType() const
定义: c4d_baselist.h:1348
RetrievePrivateData
定义: c4d_baselist.h:822
BaseContainer::GetInt32
Int32 GetInt32(Int32 id, Int32 preset=0) const
定义: c4d_basecontainer.h:303
GetIcon
Bool GetIcon(Int32 lIconID, IconData *pData)
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
RetrievePrivateData::data
void * data
The address returned.
定义: c4d_baselist.h:830
DocumentInfoData::type
Int32 type
The message type: MSG_DOCUMENTINFO_TYPE.
定义: c4d_baselist.h:993
BaseContainer
定义: c4d_basecontainer.h:46
AssetData
定义: c4d_baselist.h:1033
GeData::GetFloat
Float GetFloat(void) const
定义: c4d_gedata.h:439

Copyright  © 2014-2025 乐数软件    

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