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
    • Recent
    • Tags
    • Users
    • Login

    Set object pos in center of selected points ?

    Scheduled Pinned Locked Moved SDK Help
    6 Posts 0 Posters 585 Views
    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 Offline
      Helper
      last edited by

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

      On 12/03/2010 at 15:20, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   11.5 
      Platform:   Windows  ;   
      Language(s) :   C.O.F.F.E.E  ;

      ---------
      Ok my first post here 🙂

      Let's say I select some points, and i want to set the position of an object in the center of the selected points, any idea with simple coffee script?

      Here I attach image showing simple loop of points selected and placing a sphere in the center of the points

      Thanks

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

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

        On 12/03/2010 at 17:53, xxxxxxxx wrote:

        To get the center of of the points you will need to add the vector position of each point together and then divide by the number number of points.     So you will need the average of all the points.

        ~Shawn

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

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

          On 12/03/2010 at 18:49, xxxxxxxx wrote:

          Right, yes, that makes lot of sense , thanks alot, but... how we do that in coffee? 😛

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

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

            On 13/03/2010 at 04:55, xxxxxxxx wrote:

            Unfortunately I can't help you with the coffee syntax because I am not too familiar with COFFEE.   I use C++ ...   perhaps one of the COFFEE gurus here can jump in on this one.  🙂

            ~Shawn

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

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

              On 14/03/2010 at 15:09, xxxxxxxx wrote:

              How to know how many points are selected, with coffee, any idea?

              using GetPointSelection? mmmm?

              Thanks

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

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

                On 15/03/2010 at 03:03, xxxxxxxx wrote:

                Here is some commented code building the average of selected points.

                  
                var op = doc->GetActiveObject(); //get selected object  
                  
                //check if an object has been selected and if it is a polygon object  
                if (op && instanceof(op, PolygonObject))  
                {  
                  var sel = op->GetPointSelection();    //get the point selection  
                  var pcntsel = sel->GetCount();    //number of selected points  
                  
                  var points = op->GetPoints();    //get the points array  
                  var pcnt = op->GetPointCount();    //number of points  
                  
                  var midpoint = vector(0.0);  
                  
                  var i = 0;  
                  for (i = 0; i < pcnt; i++)    //iterate through the selected points build the sum  
                  {  
                      if (sel->IsSelected(i))  
                      {  
                          midpoint += points[i];  
                      }  
                  }  
                  
                  if (pcntsel > 0)  
                  {  
                      midpoint /= pcntsel;    //midpoint is the average of selected points  
                  }  
                }  
                

                cheers,
                Matthias

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