Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Best way to update objects after preference change?

    Cinema 4D SDK
    c++ r20 r21 s22
    2
    7
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fwilleke80F
      fwilleke80
      last edited by

      Hello,

      in my plugin, I have a PrefsDialogObject. After the user changed something in those preferences, I need to notify all my plugin objects in all open documents. What's the best way of doing this?

      Cheers,
      Frank

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        I'd go for SpecialEventAdd.

        1 Reply Last reply Reply Quote 0
        • fwilleke80F
          fwilleke80
          last edited by fwilleke80

          That would work... if NodeDatas would receive CoreMessages ๐Ÿ˜‰

          www.frankwilleke.de
          Only asking personal code questions here.

          1 Reply Last reply Reply Quote 0
          • M
            mp5gosu
            last edited by

            Ah yea, my bad. You were talking about objects, not GUI.
            Maybe implement a Scenehook that notifies all objects in question.

            1 Reply Last reply Reply Quote 0
            • fwilleke80F
              fwilleke80
              last edited by

              Yeah, I thought about a SceneHook, too. But if that scene hook would only iterate over the objects in the document and send a message to each object of the desired type, I can simply do that from within the PrefsDialogObject.

              I was hoping for some message-based approach that would spare me more code ๐Ÿ˜„

              www.frankwilleke.de
              Only asking personal code questions here.

              1 Reply Last reply Reply Quote 0
              • fwilleke80F
                fwilleke80
                last edited by

                Maybe the SDK Team has an idea(@r_gigante )? If I could just have all object in the scene receive a message like MSG_MYPREFSHAVECHANGED, that would be nice.

                www.frankwilleke.de
                Only asking personal code questions here.

                1 Reply Last reply Reply Quote 0
                • fwilleke80F
                  fwilleke80
                  last edited by fwilleke80

                  Oh wait, I think I found a way. In case anybody else wants to know, here it is...

                  In the PrefsDialogObject:

                  Bool MyPrefsDialog::SetDParameter(GeListNode *node, const DescID &id,const GeData &t_data,DESCFLAGS_SET &flags)
                  {
                  	BaseContainer* bc = MyPlugin::GetPreferences();
                  	if (!bc)
                  		SUPER::SetDParameter(node, id, t_data, flags);
                  	
                  	switch (id[0].id)
                  	{
                  		// If PREFS_MYPLUGIN_SOMEVALUE was changed, store value and notify plugin objects in all open documents.
                  		case PREFS_MYPLUGIN_SOMEVALUE:
                  			bc->SetInt32(PREFS_MYPLUGIN_SOMEVALUE, t_data.GetInt32());
                  			flags |= DESCFLAGS_SET::PARAM_SET;
                  			
                  			// Iterate open documents
                  			for (BaseDocument *doc = GetFirstDocument(); doc; doc = doc->GetNext())
                  			{
                  				// Send broadcast message to each document, use unique ID
                  				doc->MultiMessage(MULTIMSG_ROUTE::BROADCAST, MyPlugin::UNIQUE_ID_PREFS, nullptr);
                  			}
                  			
                  			GeUpdateUI();
                  			return true;
                  	}
                  	
                  	return SUPER::SetDParameter(node, id, t_data, flags);
                  }
                  

                  And then, in the plugin object:

                  Bool MyPluginObject::Message(GeListNode *node, Int32 type, void *data)
                  {
                  	if (type == MyPlugin::UNIQUE_ID_PREFS)
                  	{
                  		GePrint("Aha! My prefs have changed!"_s);
                  		return true;
                  	}
                  	return SUPER::Message(node, type, data);
                  }
                  

                  www.frankwilleke.de
                  Only asking personal code questions here.

                  1 Reply Last reply Reply Quote 3
                  • First post
                    Last post