SOLVEDRetrieve the World Position of the Current Selection (from points or edges or faces)?

Hi,

I'm trying to create a joint based on selection. My problem is getting the world position of the current selections from points or edges or faces (i.e. the current selection's pivot axis).

Correct me if I'm wrong but I cannot use the GetMg() function as it requires a base object. For instance, a cube. But what I need is the selection from the cube not the cube itself.

Is there a way around this?

Thank you for looking at the problem

You are probably in need of GetModelingAxis() which reacts to object selections or polygon/edge/point selections.

Here's how I determine the pivot for CollieMouse, which is supposed to be the same pivot that the built-in transformation functionality is using:

BaseObject* objcenter = doc->GetRealActiveObject(nullptr, nullptr); // GetActiveObject() fails with multiple selections?
if (objcenter != nullptr)
{
Matrix centermat = objcenter->GetModelingAxis(doc);
pivot = centermat.off;
}

Note: This is R19 C++, but I can see GetModelingAxis in R20 Python as well.

If this is not what you're looking for, you can take a point as vector, transform this vector by the object's world matrix, and get the world "matrix" for the point. If you need more than one point, use the average of those points.

@Cairyn

Thanks for the response. The GetModelingAxis() works as expected.

RE: " If you need more than one point, use the average of those points."

There was no need.
Once you select other points, the axis gets averaged automatically.

Thanks again!

@bentraje Yeah, the second part was meant just in case you have need for a manual process. GetModelingAxis() takes multiselections of elements into account.
However, I believe GetModelingAxis() works by selected mode (as you can have different selections for points, polys, and edges in parallel depending on whether the point, poly, edge, or object mode is active. So if you explicitly need the point selection and use the method in a script, you may want to switch to the point mode before using GetModelingAxis(). (Also, the actual modeling axis can be changed by the tools, so caution is in order. Personally, this is the behavior I needed, so I didn't make any big experiments.)