Set position selected point in pointobject array



  • On 24/06/2015 at 00:29, xxxxxxxx wrote:

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

    ---------
    Hi,

    I have a method which gets called on a button press.
    The method iterates through all my selected objects, and, for each selected object, through all the selected points. Then, for each selected point, the position gets updated.

    My problem is, it does only update my last selected point.
    Here is my code:

      
    BaseDocument *doc = GetActiveDocument();  
      
    Float posX;         this->GetFloat(DLG_EDITNUMBER_X, posX);  
    Float posY;         this->GetFloat(DLG_EDITNUMBER_Y, posY);  
    Float posZ;         this->GetFloat(DLG_EDITNUMBER_Z, posZ);  
                
    Vector newPosition = Vector(posX, posY, posZ);  
                
    Int32 setAxis;      this->GetInt32(DLG_RADIOGROUP_AXIS_SET, setAxis);  
    Bool setX;          this->GetBool(DLG_CHECKBOX_SET_X, setX);  
    Bool setY;          this->GetBool(DLG_CHECKBOX_SET_Y, setY);  
    Bool setZ;          this->GetBool(DLG_CHECKBOX_SET_Z, setZ);  
      
    Int32 modelModeSet = doc->GetMode();  
    if (modelModeSet == Mpoints)  
    {  
      AutoAlloc<AtomArray> selection;  
      if (!selection)  
          return false;  
      
      if (doc)  
      {  
          doc->GetActiveObjects(*selection, GETACTIVEOBJECTFLAGS_0);  
          op = doc->GetActiveObject();  
      }  
      
      if (selection->GetCount() > 1)  
      {  
          GePrint("More than one object selected");  
          Int32 objectCount = selection->GetCount();  
          GePrint("The object count is: " + String::IntToString(objectCount));  
          for (Int32 i = 0; i < objectCount; i++)  
          {  
              PointObject *opPoint = static_cast<PointObject*>(selection->GetIndex(i));  
              if (!opPoint) return false;  
              Matrix modelingAxis = opPoint->GetModelingAxis(doc);  
              Int32 pointCount = opPoint->GetPointCount();  
              Vector *points = opPoint->GetPointW();  
              BaseSelect *bs = opPoint->GetPointS();  
              for (Int32 o = 0; o < pointCount; o++)  
              {  
                  if (bs->IsSelected(o))  
                  {  
                      Vector projection = newPosition - modelingAxis.off;  
                      points[o] = points[o] + projection;  
                      opPoint->Message(MSG_UPDATE);  
                  }  
              }  
          }  
      }  
    }  
    

    Does somebody see what could be the problem here?
    Thanks in advance for your help and time! I greatly appreciate it!

    With kind regards,
    Casimir Smets



  • On 24/06/2015 at 06:52, xxxxxxxx wrote:

    If you are only checking selected points, you should use the standard BaseSelect method (as shown in the docs) to traverse the selection set.  It is much more efficient.  Also, please only update the object after you have updated all of the point positions - that is, after the loop not inside it!  You are going to be sending an incredibly large number of redundant update messages otherwise.  You might also want to verify that the object in question is indeed an object with points.



  • On 25/06/2015 at 01:03, xxxxxxxx wrote:

    Hi Robert,

    Thanks for your answer!
    But with the baseselect, doesn't that have to be on just 1 object? If not, how can I improve my approach?
    Also, I have to say that it changes my points on the first object I selected. So in a way, it's doing what I want, only difference is that I want to change it on all selected objects.

    Thanks for your tip about updating it! I should've thought about it myself, but whatever :p
    And about the check if it is a point object, I will probably don't need to do that, because I support other modes than the point mode as well, which can work fine on non-pointobjects.

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



  • On 25/06/2015 at 07:16, xxxxxxxx wrote:

    Hi,

    I've added GePrint() inside the object iteration and inside the point iteration.
    The GePrints gets called correctly, it just doesn't set the new point position except for the first selected object.

    I really don't know what is going wrong here :s

    Thanks in advance for your help and time!
    With kind regards,
    Casimir Smets



  • On 25/06/2015 at 07:21, xxxxxxxx wrote:

    Hi,

    After some more tests I found out that the projection vector I create is empty for all objects, except for the first selected one. Let's continue debugging...

    Greetings,
    Casimir Smets



  • On 25/06/2015 at 07:30, xxxxxxxx wrote:

    Well,

    The problem is with getting the ModelingAxis for all objects except the first.
    For every selected object I do:

      
    Matrix modelingAxis = opPoint->GetModelingAxis(doc);  
    

    This is fine for my first selected objects, for the rest it does nothing.
    I do not understand why it isn't setting it properly for the other objects :s

    Did anybody have this problem in the past?
    Greetings,
    Casimir Smets



  • On 30/06/2015 at 02:26, xxxxxxxx wrote:

    Hello,

    if you have multiple polygon objects selected with point selections on all objects in point mode, then I don't see why you want to access a single object's modeling axis. What should this axis be? You have a multi-selection and you can get this axis from the BaseDocument from GetHelperAxis().

    Best wishes,
    Sebastian



  • On 30/06/2015 at 04:09, xxxxxxxx wrote:

    Hi,

    Well, I did some testing with GetHelperAxis, but it didn't work (because of my bad code) so I started looking for another way to do it. (This helped me to solve my bad code)
    What I've done now is calculate the Helper Axis from scratch, but I really don't need all that code :p

    Thanks for your answer! I'm using the helper axis again :p

    You can mark this as SOLVED!

    With kind regards,
    Casimir Smets


Log in to reply