# How does C4D calculate pos of selected objects?

• On 17/06/2015 at 10:29, xxxxxxxx wrote:

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

---------
Hi,

I was looking for a way to access the position of multiple selected objects, but I couldn't find any method for that. Is there one?

Because I didn't find one, I tried to make one myself.
BUT... I don't know how C4D calculates the position of multiple selected objects.
I did some calculations, but they all seem to be wrong.
I've searched the internet for an hour, but didn't find anything relevant.

Could somebody tell me how C4D does this?

With kind regards,

Casimir Smets

• On 17/06/2015 at 11:15, xxxxxxxx wrote:

Should simply be the centroid of all of their positions.  Loop through all of the selected lights, get their positions (you may need to consider global vs. local - global is recommended), sum the position vectors (sum += pos), and after the loop divide the vector (sum) by the number of lights.

PseudoCode:

``````Vector sum = Vector(0.0);
Int32 nlights = number of selected lights;
for (All selected lights)
{
sum += light->GetMg().off;
}
// This will be the centroid between the light positions
sum = sum / nlights;
``````

• On 17/06/2015 at 12:34, xxxxxxxx wrote:

Hi Robert!

Well, I think C4D does it another way.
With 2 objects it works fine, but as soon as there are more, it tends to give problems.

With kind regards,
Casimir Smets

• On 17/06/2015 at 12:43, xxxxxxxx wrote:

Let me run some tests on my end and get back with results and code. :)

• On 17/06/2015 at 12:56, xxxxxxxx wrote:

AFAIK it's the bounding box of the selected objects' axes.

``````MinMax mm;
for (All selected lights)
{
}
Vector min = mm.GetMin();
Vector max = mm.GetMax();
``````

• On 17/06/2015 at 14:53, xxxxxxxx wrote:

Hi Niklas!

That did it, apparentally that's the way C4D handles multi-selection of objects.

(You can mark this as solved)

With kind regards,
Casimir Smets

• On 18/06/2015 at 06:22, xxxxxxxx wrote:

Hello,

to get the axis of a multi-selection one can use BaseDocument::GetHelperAxis().

Best wishes,
Sebastian

• On 18/06/2015 at 06:32, xxxxxxxx wrote:

Hi Sebastian,

GetHelperAxis is faster than the solution Niklas gave me.

You can mark this as solved!
With kind regards,
Casimir Smets

• On 18/06/2015 at 11:01, xxxxxxxx wrote:

Hi,

Is there also such a function as GetHelperAxis for point/edge/polygon selection?
And what about pointselections from multiple objects? Or should I do this manually if I want to support that? (Because C4D doesn't seem to calculate that position...)

Greetings,
Casimir Smets

• On 19/06/2015 at 02:03, xxxxxxxx wrote:

Hello,

best wishes,
Sebastian

• On 19/06/2015 at 06:18, xxxxxxxx wrote:

Hi Sebastian,