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

    Is SendModelingCommand allowed in Message?[SOLVED]

    SDK Help
    0
    6
    547
    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.
    • H
      Helper
      last edited by

      On 12/05/2015 at 05:18, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R16 
      Platform:      Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      Hi,

      I want to call MCOMMAND_CURRENTSTATETOOBJECT when a button is pressed.
      I should do this inside Message()'s MSG_DESCRIPTION_COMMAND, I guess, but if I try it my program crashes.
      Is this not possible inside Message?

      Here is my code:

        
      if (type == MSG_DESCRIPTION_COMMAND)  
      {  
        DescriptionCommand* dc = (DescriptionCommand* )data;  
        if (dc->id[0].id == MY_BUTTON)  
        {  
            BaseDocument* doc = static_cast<BaseDocument*>(data);  
            if (!doc)  
                return false;  
            BaseObject* myObject = doc->GetFirstObject();  
            if (!myObject)  
                return false;  
            ModelingCommandData cd;  
            cd.doc = doc;  
            cd.op = myObject;  
            SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd);  
        }  
      }  
      

      Thanks in advance for your help and time!
      Greetings,
      Casimir Smets

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 12/05/2015 at 06:03, xxxxxxxx wrote:

        It is valid and safe. But you cannot simply cast data (which is a DescriptionCommand) into a basedocument coz it does not hold a basedocument pointer.

        You should use node->GetDocument() instead (or GetActiveDocument() which should be valid due to a button click most of the time only being triggered interactively..though this is no guarantee so node->GetDocument() is the better alternative).

        Also you might need to do this on a copy of the scene.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 12/05/2015 at 06:22, xxxxxxxx wrote:

          Hi,

          If I change that, I get no error, and my program doesn't quit.
          The only problem is, it is not making it editable..

          Greetings,
          Casimir Smets

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 12/05/2015 at 06:32, xxxxxxxx wrote:

            Hi,

            Ignore my previous post 😉
            I forgot to cast it and add it to the scene, feeling stupid now yeeeuy 😄

            Greetings,
            Casimir Smets

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 12/05/2015 at 07:50, xxxxxxxx wrote:

              Hi Casimir,

              Katachi is right with his answer.
              I sense some problems with the concept of casting datatypes here. It is certainly one of the more advanced concepts of C and C++ and probably one which is cause for many (if not most) bugs. As casts are needed in several places in the C4D SDK, I'd recommend to have a read on this topic.
              For example here or here or here. Especially the parts about casting pointers are crucial.

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 13/05/2015 at 08:17, xxxxxxxx wrote:

                Hi Andreas,

                Thanks for your answer!
                I shall definately look more into casting!

                Greetings,
                Casimir Smets

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