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

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

    Cinema 4D SDK
    r20 python
    2
    4
    940
    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.
    • B
      bentraje
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        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.

        1 Reply Last reply Reply Quote 4
        • B
          bentraje
          last edited by

          @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!

          CairynC 1 Reply Last reply Reply Quote 0
          • CairynC
            Cairyn @bentraje
            last edited by

            @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.)

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