SendModelingCommand, MCData result array question



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

    On 14/04/2012 at 10:59, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   13 Demo 
    Platform:      
    Language(s) :     C++  ;

    ---------
    hiho,

    i have got a rather diffuse question again. i can't get the SMC to work in c++. i am following the
     sdk example with this slightly modified snippet :

    PolygonObject *result = NULL;
      
    // result is filled with points and polygons
      
    BaseContainer bc; 
    bc.SetLong(MDATA_KNIFE_MODE, MDATA_KNIFE_MODE_PLANE);
    bc.SetLong(MDATA_KNIFE_PLANE, MDATA_KNIFE_PLANE_YZ);
    bc.SetBool(MDATA_KNIFE_PLANE_SLICING, TRUE);
    bc.SetLong(MDATA_KNIFE_PLANE_CUTS, 4);
      
    ModelingCommandData cd;
    cd.doc = GetActiveDocument();
    cd.bc = &bc;
    cd.op = result;
      
    if (SendModelingCommand(ID_MODELING_KNIFE_TOOL, cd)) GePrint("Beep");
      
    BaseObject *res = static_cast<BaseObject*>(cd.result->GetIndex(0));
    

    the last line gives me a runtime error "access violation reading ...." when i watch
    the SMCData while debugging with VS cd.Result seems to be empty. so i have
    got three questions.

    1. how and where is it defined if SMC creates a new object. in python i can always read
    the returned array. i am using the default flag, aka MODELINGCOMMANDFLAGS_0.

    the help states for  AtomArray* result

    Resulting object array for commands that create new objects. Not used if MODELINGCOMMANDFLAGS_CREATEUNDO is set in flags.

    2. where is the difference between the COMMAND parameters MCOMMAND_KNIFE and ID_MODELING_KNIFE_TOOL.

    3. why is my array empty ?

    i am calling SMC from a static baseobject method if this does matter.

    edit : and it beeps , so SMC is true / executed ;)



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

    On 15/04/2012 at 01:09, xxxxxxxx wrote:

    Well for your questions 1 and 3:

    Q1. The SDK tells you. For example, under MCOMMAND_JOIN it says 'returns object'. If it doesn't say that, it shouldn't return a new object.
    Q3. It's empty because it isn't returning a new object. Your input object is just changed. (Though the SDK does say that if you input multiple objects, which uses the arr parameter, the changed objects are returned in result. But I've never tried that.)

    Don't know about Q2. I've always used the MCOMMAND_ series, never used ID_MODELING_. I'd like to know the answer to this, too.

    Oh, and be aware that SendModelingCommand is a pig. It never works the way you think it should.

    Steve



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

    On 15/04/2012 at 04:32, xxxxxxxx wrote:

    hey,

    thanks for your answer, as the code seemed to have no effect on my object i was desperately 
    trying to get the result array to work, ignoring that the problem obviously lies somewhere else.
    i should have done this before, but MCOMMAND_SUBDIVIDE is working as expected. which leads 
    me to a question, i also always had for python.

    how are we supposed to use modellingtools which require some sort of editor highlighting, like
    loops or the knifetool ? i found MDATA_KNIFE_ as a mysterious value in toolknife.h, MDATA_KNIFE_
    doesn't appear in the res file. is it holding the live selection informations ?

    edit : btw i found this here

    Originally posted by xxxxxxxx

    First, ID_MODELING_MELT_COMMAND is meant to be used with CallCommand() and MCOMMAND_MELT with SendModelingCommand().

    ok i found MDATA_OPTIONS, but what the heck is a cid ?

    cid MDATA_Options
    {
    public:
      Real MDATA_SPLINE_FREEHANDTOLERANCE;
      Real MDATA_SPLINE_OUTLINE;
      LONG MDATA_SPLINE_PROJECTMODE;
      LONG MDATA_SPLINE_ADDPOINTSEGMENT;
      Real MDATA_SPLINE_ADDPOINTPOSITION;
      Bool MDATA_SPLINE_ADDPOINTSELECT;
      Bool MDATA_SPLINE_OUTLINESEPARATE;
      Bool MDATA_DISCONNECT_PRESERVEGROUPS;
      Bool MDATA_MIRROR_SNAPPOINTS;
      Bool MDATA_MIRROR_DUPLICATE;
      Bool MDATA_MIRROR_WELD;
      Real MDATA_MIRROR_TOLERANCE;
      LONG MDATA_MIRROR_SYSTEM;
      LONG MDATA_MIRROR_PLANE;
      Real MDATA_MIRROR_VALUE;
      Vector MDATA_MIRROR_POINT;
      Vector MDATA_MIRROR_VECTOR;
      Bool MDATA_MIRROR_SELECTIONS;
      Bool MDATA_MIRROR_ONPLANE;
      Real MDATA_OPTIMIZE_TOLERANCE;
      Bool MDATA_OPTIMIZE_POINTS;
      Bool MDATA_OPTIMIZE_POLYGONS;
      Bool MDATA_OPTIMIZE_UNUSEDPOINTS;
      Real MDATA_CROSSSECTION_ANGLE;
      Bool MDATA_SUBDIVIDE_HYPER;
      Real MDATA_SUBDIVIDE_ANGLE;
      LONG MDATA_SUBDIVIDE_SPLINESUB;
      LONG MDATA_SUBDIVIDE_SUB;
      Vector MDATA_KNIFE_P1;
      Vector MDATA_KNIFE_V1;
      Vector MDATA_KNIFE_P2;
      Vector MDATA_KNIFE_V2;
      Real MDATA_KNIFE_ANGLE;
      Bool MDATA_UNTRIANGULATE_ANGLE;
      Bool MDATA_UNTRIANGULATE_NGONS;
      Real MDATA_UNTRIANGULATE_ANGLE_RAD;
      LONG MDATA_CONVERTSELECTION_LEFT;
      LONG MDATA_CONVERTSELECTION_RIGHT;
      Bool MDATA_CONVERTSELECTION_TOLERANT;
      Bool MDATA_CURRENTSTATETOOBJECT_INHERITANCE;
      Bool MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION;
      Bool MDATA_CURRENTSTATETOOBJECT_NOGENERATE;
      Bool MDATA_ROTATECAMERA;
      LONG MDATA_RING_EDGE;
      LONG MDATA_RING_SELECTION;
      LONG MDATA_RING_SKIP;
      LONG MDATA_FILLSEL_START_POLY;
      LONG MDATA_FILLSEL_SELECTION;
      LONG MDATA_OUTLINESEL_START_POLY;
      LONG MDATA_OUTLINESEL_SELECTION;
      Bool MDATA_RESETSYSTEM_COMPENSATE;
      Bool MDATA_RESETSYSTEM_RECURSIVE;
      Bool MDATA_JOIN_MERGE_SELTAGS;
      Real MDATA_SETVERTEX_VALUE;
      LONG MDATA_SETVERTEX_MODE;
    };
    

    it appears quite often in the sdk, but i cannot find any explanation ho to use it.



  • 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.



  • 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://plugincafe.maxon.net/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



  • 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.



  • 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



  • 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.



  • 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://plugincafe.maxon.net/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



  • 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);
    


  • 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;
    


  • 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



  • 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.



  • 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



  • 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.



  • 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.



  • 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.



  • 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.



  • 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.)



  • 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.


Log in to reply