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

    Set position selected point in pointobject array

    SDK Help
    0
    8
    776
    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 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

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

        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.

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

          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 😛
          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

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

            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

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

              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

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

                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

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

                  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

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

                    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 😛

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

                    You can mark this as SOLVED!

                    With kind regards,
                    Casimir Smets

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