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

    SendModelingCommand, MCData result array question

    SDK Help
    0
    25
    14.8k
    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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 15/04/2012 at 08:06, xxxxxxxx wrote:

      tried this,

      BaseContainer toolbc, mdatabc;
      ModelingCommandData cd; 
        
      mdatabc.SetVector( MDATA_KNIFE_P1, Vector(0,0,0) );
      mdatabc.SetVector( MDATA_KNIFE_P2, Vector(1,0,0) );
        
      toolbc.SetBool(MDATA_KNIFE_RESTRICT, FALSE);
      toolbc.SetLong(MDATA_KNIFE_MODE, MDATA_KNIFE_MODE_PLANE);
      toolbc.SetLong(MDATA_KNIFE_PLANE, MDATA_KNIFE_PLANE_YZ);
      toolbc.SetBool(MDATA_KNIFE_PLANE_SLICING, TRUE);
      toolbc.SetLong(MDATA_KNIFE_PLANE_CUTS, 4);
      toolbc.SetContainer(MDATA_KNIFE_, mdatabc);
        
      cd.doc = GetActiveDocument();
      cd.bc = &toolbc;
      cd.mode = MODELINGCOMMANDMODE_POLYGONSELECTION;
      cd.op = result;
      if (SendModelingCommand(MCOMMAND_KNIFE, cd)) GePrint("Beep");
        
      return result;
      

      but it doesn't work *scratch head*

      edit : to be more specific, it compiles and runs, but my object isn't cut.

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 15/04/2012 at 10:51, xxxxxxxx wrote:

        The first thing you should know is that the SMC is riddled with bugs. And you're probably beating a dead horse using the SMC for this.
        Try the same code you used. But put something like: ID_MODELING_EXTRUDE_INNER_TOOL in there instead. And it should work just fine for you.

        I've reported SMC bugs in the past. For example the old mirror tool only moves points in the Z direction. Regardless of what the settings are in the code.
        And then there's things that just don't work at all. Like this:https://developers.maxon.net/forum/topic/5863/5930_tool-doesnt-execute-until-view-is-selected&KW=tool&PID=24928#24928

        Here is a possible alternative to using the SMC:

            doc->SetAction(ID_MODELING_KNIFE_TOOL); //Executes the knife tool  
          
          LONG tool_id = doc->GetAction();  
          BasePlugin *tool = NULL;  
          tool = FindPlugin(tool_id, PLUGINTYPE_TOOL);  
          if (!tool) return FALSE;  
          
          tool->SetParameter(DescID(MDATA_KNIFE_RESTRICT), FALSE, DESCFLAGS_SET_0);       //Turns off the restrict option  
          tool->SetParameter(DescID(MDATA_KNIFE_CONSTRAIN_THETA), .65, DESCFLAGS_SET_0);  //Sets the value to 37.242°  
          tool->SetParameter(DescID(MDATA_KNIFE_MODE), MDATA_KNIFE_MODE_LOOP, DESCFLAGS_SET_0);//<--CRASHES C4D!!!
        

        This seems to work for changing everything in the knife tool. Except the mode option.
        I've tried a bunch of different things. But it either crashes, or doesn't do anything.
        I've also tried changing the knife mode using the tools container. But all I can manage to do is change it in memory. The AM refuses to update for me.

        -ScottA

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 15/04/2012 at 11:58, xxxxxxxx wrote:

          hi,

          thanks for your reply and the work you put into this. i am aware of the posts that point onto 
          numerous smc bugs. despite this fact i would really like to know how this is intended to be used. 
          the class cid MDATA_Options is there for some reason and it is obvious that tool knife won't work 
          without the vectors (you cannot finish the tool within c4d without hoovering a polygon).

          however MDATA_KNIFE_ doesn't seem to be used within c4d. did some quick tests in python :

          import c4d
          from c4d import documents, utils
            
          def main() :
              cube = doc.SearchObject("Cube")
              toolbc = c4d.BaseContainer()
              tool = doc.GetActiveToolData()
              
              toolbc[c4d.MDATA_KNIFE_RESTRICT] = False
              toolbc[c4d.MDATA_KNIFE_MODE] = c4d.MDATA_KNIFE_MODE_PLANE
              toolbc[c4d.MDATA_KNIFE_PLANE] = c4d.MDATA_KNIFE_PLANE_YZ
              toolbc[c4d.MDATA_KNIFE_PLANE_SLICING] = 1
              toolbc[c4d.MDATA_KNIFE_PLANE_CUTS] = 4
              toolbc[c4d.MDATA_KNIFE_P1] = c4d.Vector(0,-1000,0)
              toolbc[c4d.MDATA_KNIFE_P2] = c4d.Vector(0,1000,0)
            
              res = utils.SendModelingCommand(c4d.MCOMMAND_KNIFE, [cube], 
              c4d.MODELINGCOMMANDMODE_POLYGONSELECTION, toolbc, doc)
              
              tool[c4d.MDATA_KNIFE_MODE] = c4d.MDATA_KNIFE_MODE_PLANE
              c4d.EventAdd() 
              for index, value in tool:
                  print '{0} ==> {1}'.format(index, value)
              
          if __name__=='__main__':
              main()
          

          it would be really nice, if the support could explain how we are meant to use MDATA_Options.

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 15/04/2012 at 14:00, xxxxxxxx wrote:

            GetActiveToolData() get's the tool's container. So that can be used without needing to create a brand new container in your python example.
            I'm also not sure why you're trying to execute the knife tool with SMC after you've asked for the active tool. That seems backwards to me.

            Example:

            import c4d  
            from c4d import documents, utils  
              
            def main() :  
              cube = doc.SearchObject("Cube")  
              c4d.CallCommand(1016030)        #Execute the Knife tool first  
              tool = doc.GetActiveToolData()    #Then ask for the active tool's container data  
                
              tool[c4d.MDATA_KNIFE_RESTRICT] = False  
              tool[c4d.MDATA_KNIFE_MODE] = c4d.MDATA_KNIFE_MODE_PLANE  
              tool[c4d.MDATA_KNIFE_PLANE] = c4d.MDATA_KNIFE_PLANE_YZ  
              tool[c4d.MDATA_KNIFE_PLANE_SLICING] = 1  
              tool[c4d.MDATA_KNIFE_PLANE_CUTS] = 4  
              tool[c4d.MDATA_KNIFE_P1] = c4d.Vector(0,-1000,0)  
              tool[c4d.MDATA_KNIFE_P2] = c4d.Vector(0,1000,0)      
              tool[c4d.MDATA_KNIFE_MODE] = c4d.MDATA_KNIFE_MODE_PLANE  
              for index, value in tool:  
                  print '{0} ==> {1}'.format(index, value)  
              c4d.EventAdd()   
                
            if __name__=='__main__':  
              main()
            

            From the recent Python forum thread about executing buttons:
            Yannick wrote: " MDATA_TRANSFER_ marks the end of MDATA_TRANSFER's container entry enumeration; it's not a valid ID. "
            If maxon is consistent. Then that means MDATA_KNIFE_ is also not a valid ID to use with SMC.

            If you are attempting to execute the knife tool without the user hovering the mouse over the object. It's not possible.
            It's been discussed in the archives.

            -ScottA

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 15/04/2012 at 14:26, xxxxxxxx wrote:

              hi,

              thanks for your reply,

              Originally posted by xxxxxxxx

              GetActiveToolData() get's the tool's container. So that can be used without needing to create a brand new container in your python example.
              I'm also not sure why you're trying to execute the knife tool with SMC after you've asked for the active tool. That seems backwards to me.

              i am aware of that, the script was meant to do 2 things, check if SMC behaves differently in 
              python and for loping through the tooldata bc of the active tool (the knife tool). the 
              GetActiveToolData() & bc loop has nothing to do whit the smc part.

              Originally posted by xxxxxxxx

              If you are attempting to execute the knife tool without the user hovering the mouse over the object. It's not possible. It's been discussed in the archives.
              -ScottA

              yes i am trying to run the knife tool without hoovering. i couldn't find any threads on the knife 
              tool & smc. could you provide a link ? what i still don't understand why there is is MDATA_Options
              and what it is used for.

              Originally posted by xxxxxxxx

              Yannick wrote: " MDATA_TRANSFER_ marks the end of MDATA_TRANSFER's container entry enumeration; it's not a valid ID. "

              ok this makes sense, however a better naming would clearify things alot, olight ends with
              LIGHT_END_, much better imho.

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

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 15/04/2012 at 14:38, xxxxxxxx wrote:

                Here's one thread. But I think remember seeing more than just this one. This is just the first one I picked after doing a search for "knife tool" :
                 https://developers.maxon.net/forum/topic/2694/2066_knife-tool-in-version-9&KW=Knife+Tool&PID=7950#7950

                FYI:
                Just in case you don't already know this. Use the advanced search. And set the "Find Posts" option to "Any Date" to see all the really old archived threads.

                I would really like to know how to change the knife tool's mode in C++ myself.
                I can't understand why my SetParameter() code isn't working.

                -ScottA

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

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 16/04/2012 at 04:53, xxxxxxxx wrote:

                  Hi,

                  Originally posted by xxxxxxxx

                  I would really like to know how to change the knife tool's mode in C++ myself.
                  I can't understand why my SetParameter() code isn't working.

                  You should use a GeData and its Set*() method:

                  GeData data;
                  data.SetLong(MDATA_KNIFE_MODE_LOOP);
                  tool->SetParameter(DescID(MDATA_KNIFE_MODE), data, DESCFLAGS_SET_0);
                  
                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 16/04/2012 at 07:08, xxxxxxxx wrote:

                    so it still applies, that we cannot use smc knifetool without mouse input, we are not able to set
                    the knife vectors with MData_Options somehow ?

                     Vector MDATA_KNIFE_P1;
                    
                      Vector MDATA_KNIFE_V1;
                    
                      Vector MDATA_KNIFE_P2;
                    
                      Vector MDATA_KNIFE_V2;
                    
                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 16/04/2012 at 08:37, xxxxxxxx wrote:

                      Thanks Yannick,
                      That code works if the knife tool is already open. But it still crashes C4D when used like this:

                          doc->SetAction(ID_MODELING_KNIFE_TOOL); //Executes the knife tool  
                        
                        LONG tool_id = doc->GetAction();  
                        BasePlugin *tool = NULL;  
                        tool = FindPlugin(tool_id, PLUGINTYPE_TOOL);  
                        if (!tool) return FALSE;  
                        
                        if (tool)  
                        {  
                        GeData data;  
                        data.SetLong(MDATA_KNIFE_MODE_LOOP);  
                        tool->SetParameter(DescID(MDATA_KNIFE_MODE), data, DESCFLAGS_SET_0); //<---CRASHES!!  
                        tool->SetParameter(DescID(MDATA_KNIFE_RESTRICT), FALSE, DESCFLAGS_SET_0);       //Turns off the restrict option  
                        tool->SetParameter(DescID(MDATA_KNIFE_CONSTRAIN_THETA), .65, DESCFLAGS_SET_0);  //Sets the value to 37.242°  
                        }
                      

                      I'm not positive about this. But it seems like the knife tool is still loading(or the open dialog plugin doesn't see it as loaded yet) when SetParamerter() kicks in. So it crashes.
                      Is there a better way to execute the knife code like this?

                      -ScottA

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

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 16/04/2012 at 09:57, xxxxxxxx wrote:

                        The safest way to change a tool settings is to access its data container calling GetToolData() :

                        BaseContainer* data = GetToolData(doc, ID_MODELING_KNIFE_TOOL);
                        data->SetLong(MDATA_KNIFE_MODE, MDATA_KNIFE_MODE_LOOP);
                        

                        This way it works if the tool is open or not.

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

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          On 16/04/2012 at 11:07, xxxxxxxx wrote:

                          OK thanks.

                          This advice contradicts the sticky posted here about always using Get&Set parameter() instead of BaseContainers. So I try not to use BaseContainers as much as possible.
                          But I realize in programming there are no absolutes. And sometimes you have no choice.

                          Still. I suppose this could maybe confuse some people.

                          -ScottA

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

                            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                            On 18/04/2012 at 04:27, xxxxxxxx wrote:

                            i have replaced the smc with my own code , so i do not need this specific example anymore, 
                            but i still would really like to know, how we are supposed to use MDATA_Options.

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

                              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                              On 18/04/2012 at 07:11, xxxxxxxx wrote:

                              MDATA_Options doesn't exist in the SDK. It's just a group of all container IDs for modeling commands.
                              In the documentation IDs are grouped for better indexing.

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

                                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                On 18/04/2012 at 08:06, xxxxxxxx wrote:

                                so, we have to write the ids from MData_Options into the bc of the respective tool to 
                                use them or aren't we allowed to use the ids at all ? sorry, i still don't get it.

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

                                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                  On 19/04/2012 at 00:11, xxxxxxxx wrote:

                                  Originally posted by xxxxxxxx

                                  so, we have to write the ids from MData_Options into the bc of the respective tool to 
                                  use them or aren't we allowed to use the ids at all ? sorry, i still don't get it.

                                  Yes you can use the IDs listed in MData_Options. For example MDATA_CURRENTSTATETOOBJECT_INHERITANCE, MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION and MDATA_CURRENTSTATETOOBJECT_NOGENERATE for MCOMMAND_CURRENTSTATETOOBJECT.

                                  And the IDs from MData_Options are placed under their related command in SendModelingCommand() documentation.

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

                                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                    On 19/04/2012 at 03:34, xxxxxxxx wrote:

                                    hi,

                                    thanks for the clarification. that i wasn't able to set the vectors for the knife tool is just a limitation 
                                    of the knifetool  ?(i am aware that my orginal apporach to write these vectors into a seperate bc, 
                                    which i tried to write into the id MDATA_KNIFE_ was wrong, i also tried to write these values directly 
                                    into the ModellingCommandData bc.)

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

                                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                      On 19/04/2012 at 08:54, xxxxxxxx wrote:

                                      Originally posted by xxxxxxxx

                                      that i wasn't able to set the vectors for the knife tool is just a limitation 
                                      of the knifetool ?

                                      I contacted the developers on this.

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

                                        On 29/01/2013 at 07:23, xxxxxxxx wrote:

                                        Hi,

                                        A recent thread made me remember that I got some months ago an interesting code snippet from the developers that was showing how to send a knife modeling command.

                                        What's most important to understand is: MDATA_KNIFE_P1, MDATA_KNIFE_P2, MDATA_KNIFE_V1 and MDATA_KNIFE_V2 have to be given in world space.
                                        For this purpose we can use the handy conversion methods of BaseView (parent class of BaseDraw). In the example we call BaseView.SW() to convert screen space coordinates to world space.
                                        v1 and v2 are basically vectors showing away from the camera (and going through p1/p2). v1 % v2 build the normal of the cutting plane.

                                        The following example will show how to cut the selected spline just in the middle of the view:

                                        import c4d
                                        from c4d import utils
                                          
                                          
                                        def SplineCutter(doc, op, bd, x1, y1, x2, y2, bSelect) :
                                            
                                            p1 = bd.SW(c4d.Vector(x1, y1, 0.0))
                                            v1 = bd.SW(c4d.Vector(x1, y1, 100.0)) - p1
                                            p2 = bd.SW(c4d.Vector(x2, y2, 0.0))
                                            v2 = bd.SW(c4d.Vector(x2, y2, 100.0)) - p2
                                            
                                            bc = c4d.BaseContainer()
                                            bc.SetVector(c4d.MDATA_KNIFE_P1, p1)
                                            bc.SetVector(c4d.MDATA_KNIFE_P2, p2)
                                            bc.SetVector(c4d.MDATA_KNIFE_V1, v1)
                                            bc.SetVector(c4d.MDATA_KNIFE_V2, v2)
                                            bc.SetBool(c4d.MDATA_KNIFE_RESTRICT, False)
                                            bc.SetBool(c4d.MDATA_KNIFE_SELECTCUTS, bSelect)
                                            
                                            if op is not None and op.CheckType(c4d.Ospline) :
                                            
                                                utils.SendModelingCommand(command = c4d.MCOMMAND_KNIFE,
                                                                          list = [op],
                                                                          bc = bc,
                                                                          doc = doc,
                                                                          flags = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)
                                                c4d.EventAdd()
                                          
                                          
                                        def main() :
                                            
                                            bd = doc.GetActiveBaseDraw()
                                            frame = bd.GetFrame()
                                            middleX = (frame['cr']-frame['cl'])/2
                                            
                                            SplineCutter(doc, op, bd, middleX, frame['ct'], middleX, frame['cb'], True)
                                            
                                          
                                        if __name__=='__main__':
                                            main()
                                        

                                        You can then modify the call to SplineCutter() in main() to use other coordinates from the mouse, a tool etc. You can also 'play' with others MDATA_KNIFE_ options.

                                        EDIT: Fixed the code.

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

                                          On 29/01/2013 at 09:17, xxxxxxxx wrote:

                                          hey, thanks for the clarification 🙂

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

                                            On 29/01/2013 at 11:32, xxxxxxxx wrote:

                                            Hello Yannick
                                            Please correct your code(if you tested it?!), if you want to post right example for help:
                                            1. console displays: AttributeError: 'c4d.SplineObject' object has no attribute 'IsInstanceOf'
                                            2. even seems code was wrote from scratch : bc.SetVector( c4d., v2) - > bc.SetVector(c4d.MDATA_KNIFE_V2, v2)

                                            Any way, data from bc for SendModelingCommand, should be based on bd data?... For example
                                            c4d.ID_MODELING_POINT_ADD_TOOL at bc[c4d.MDATA_ADDPOINT_POINT] = gm.Mul(poly_center(op, i)) # vector data

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