Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Default Object: How to apply those defaults?

    Cinema 4D SDK
    c++ r20 r21 s22 r23
    2
    11
    1.0k
    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 fwilleke80

      Hi,

      The Attribute Manager, the Edit menu offers the option "Set as Default...". This will save the active object as default for this object type. So far, so good.

      Creating a Cube, changing some attributes, and then setting it as default works fine. When I create a new Cube, it has my attribute settings.

      However, it does not work in two cases:

      1. With Field Objects that are added via a FieldList description in one of my plugin objects (or an object, for that matter)
        I can change settings in that Field Object, and set it as default. But when I create a new Field from the FieldList description in my plugin object, the created Field does not have my settings. The settings are only applied when I create a Field of that type from Cinema's Create menu.

      2. With objects that are added to the document via plugin code
        I do the normal stuff when adding an object to the scene via e.g. a command:

      		BaseObject *newObjectPtr = BaseObject::Alloc(id);
      		if (! newObjectPtr)
      			return false;
      		doc->StartUndo();
      		doc->InsertObject(newObjectPtr, op->GetUp(), op, true);
      		doc->SetActiveObject(newObjectPtr);
      		newObjectPtr->Message(MSG_UPDATE);
      		doc->AddUndo(UNDOTYPE::NEWOBJ, newObjectPtr);
      		doc->EndUndo();
      		EventAdd();
      

      But it's the same as with the Field objects, after setting an object as default, and creating another one (using the above code), the settings are not applied. It only works when creating the new object via Cinema's Create menu or from the plugin's menu.

      So here are the questions:

      1. How can I add the default object, that the user has set, to the document?
      2. Where are those default objects stored, by the way, and how can we remove a default object?
        Already solved: In the Content Browser under Presets/Defaults.

      Thanks in advance, greetings,
      Frank

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

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

        Follow-up: The behavior is the same when using the FieldList of any Effector. Adding a Field from the FieldList does not add the default object that the user has set.

        So I guess it's nothing we can change. Or is there a way to load those default settings from somewhere and apply them? There must be, as the code that adds objects from the Create or the plugin's menu obviously does it πŸ˜‰

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

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          hi,

          sorry for the delay, the default properties are stored in the Browser. you can retrieve them with GetDefaultObject. You will find more information on that page

          BaseObject* myDefaultObject = static_cast<BaseObject*>(SDKBrowser::GetDefaultObject(Opyramid));
          	if (myDefaultObject == nullptr)
          		myDefaultObject = BaseObject::Alloc(Opyramid);
          
          	if (myDefaultObject == nullptr)
          		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

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

            Hi,

            oops, sorry, didn't see your reply earlier (I never get notification emails).

            Thank you very much, that should be the solution at least for the objects I create in my code πŸ™‚

            However, I guess, there is no way to use the default object for Fields created by the FieldList customgui, right?

            Cheers,
            Frank

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

            1 Reply Last reply Reply Quote 0
            • ManuelM
              Manuel
              last edited by

              @fwilleke80 said in Default Object: How to apply those defaults?:

              However, I guess, there is no way to use the default object for Fields created by the FieldList customgui, right?

              I don't think so. But what's strange is that it does create your default field if you use the palette (icon on top).
              We could maybe consider that as a bug.
              I need to check the code to see why there's such a difference between the palette and the customGUI.

              Cheers,
              Manuel

              MAXON SDK Specialist

              MAXON Registered Developer

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

                Good to know, thank you for looking into it!

                Cheers,
                Frank

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

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

                  @m_magalhaes said in Default Object: How to apply those defaults?:

                  I don't think so. But what's strange is that it does create your default field if you use the palette (icon on top).
                  We could maybe consider that as a bug.
                  I need to check the code to see why there's such a difference between the palette and the customGUI.

                  I guess, that's because menus and palettes create the objects using menu item resource IDs like PLUGIN_CMD_440000266 (e.g. in /resource/c4dplugin/menus/c4d_m_editor.res), which I guess was a quick solution back when it was coded. It's a kind of CommandData that creates the objects, apparently invoking SDKBrowser::GetDefaultObject(). This has probably just been forgotten in the FieldListCustomGui.

                  I wonder if there's a way to call that 'secret' CommandData from a plugin.

                  Cheers,
                  Frank

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

                  1 Reply Last reply Reply Quote 0
                  • ManuelM
                    Manuel
                    last edited by

                    hi,

                    those commands are created whenever you register a plugin/tools etc.

                    after having a look at it, i confirm it's a bug, the object is allocated without checking for the content browser.

                    if it's in your objectData, you could maybe listen to the message MSG_DOCUMENTINFO_TYPE_OBJECT_INSERT, check if it's a field object and check if it's the default one or the browser one. Than replace according to what you want.
                    I didn't tested it myself but it could work.

                    But that's maybe too mush work for a "detail"

                    Cheers,
                    Manuel

                    MAXON SDK Specialist

                    MAXON Registered Developer

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

                      Oh, that is actually a good idea, thank you!
                      I'll try that!

                      Cheers,
                      Frank

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

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

                        @m_magalhaes said in Default Object: How to apply those defaults?:

                        MSG_DOCUMENTINFO_TYPE_OBJECT_INSERT

                        Sadly, it seems that MSG_DOCUMENTINFO is not sent when adding a Field via the FieldList CustomGui. I had been hoping that message would be triggered by BaseDocument::InsertObject() and GeListNode::InsertUnder() (and related functions).
                        I guess, we have to do without default objects in this case πŸ˜•

                        Cheers,
                        Frank

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

                        1 Reply Last reply Reply Quote 0
                        • ManuelM
                          Manuel
                          last edited by

                          well sorry for the misleading.
                          I was thinking it should work because the object is inserted with doc->InsertObject

                          Cheers,
                          Manuel

                          MAXON SDK Specialist

                          MAXON Registered Developer

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