# Set object pos in center of selected points ?

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 :slightly_smiling_face:

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

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

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? :P

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

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

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