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 Center Pivot of Three or More Objects?

    Cinema 4D SDK
    r21 python
    3
    8
    887
    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 am able to get the center pivot of two objects but for some reason, it needs revision for three or more objects.
      You can see an illustration of the problem here:
      https://www.dropbox.com/s/u76v7zcbv8a38x4/c4d177_center_pivot_three_selected_object.jpg?dl=0

      Here is the working code so far:

      import c4d
      from c4d import gui
      
      # Main function`
      def main():
          #Assuming there are three objects in the scene
          cube01 = doc.SearchObject('cube01')
          cube02 = doc.SearchObject('cube02')
          cube03 = doc.SearchObject('cube03')
      
          cube01_pos = cube01.GetMg().off
          cube02_pos = cube02.GetMg().off
          cube03_pos = cube03.GetMg().off
      
          # Getting the pivot of the two objects. Works as expected
      
          cube_dif =  cube02_pos - cube01_pos
          cube01_02_pos = ((cube_dif/2) + cube01_pos) # Center Pivot
      
          # Getting the pivot of the three objects.
          cube_dif03 = cube01_02_pos - cube03_pos
          cube01_02_03_pos = ((cube_dif03/2) + cube01_02_pos)
      
          print cube01_02_03_pos #Does not match the pivot on the coordinate manager when all three objects are selected.
      
      
      # Execute main()
      if __name__=='__main__':
          main()
      

      Thank you for looking at my problem.

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi,

        the term pivot is a bit ambiguous in this posting, since it refers to a point, while you are showing a frame, a transform matrix, Cinema's little coordinate system widget in your illustration (props by the way for including these).

        The shared frame of N objects is just the arithmetic mean of the frames of these objects. Since you used the term pivot and things will get more complicated for averaging out also rotations (quaternions would be a solution) and scales, I will assume you are just after that the offset of that shared frame. Again in pseudo code:

        pivot = sum([obj.GetMg().off for obj in my_objects]) * (1. / len(my_objects))
        

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

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

          @zipit

          Thanks for the response.
          I'm not really sure on the nomenclature but I am referring to the Red,Green,Blue arrows as the pivot.

          Anyhow, for some reason your code does not match the pivot computed by the coordinate manager.
          You can see the illustration here:
          https://www.dropbox.com/s/tzlg3ry03e7tu5p/c4d177_center_pivot_three_selected_object02.jpg?dl=0

          1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand
            last edited by ferdinand

            Hi,

            I am sorry, I wrote this posting without checking it in Cinema. It seemed pretty self explanatory to me, that this is the answer. I am not quite sure why it does not work, I will have to check this myself in Cinema (I do not have the time to do it right now). Possible solutions could be, that Cinema computes the geometric or harmonic mean (which would strike me as odd) or that I made an oopsie in my code (that I do not see right now).

            PS: I pointed that pivot stuff out, because if the object frames (axis) are tilted (in respect to the world frame), then your shared frame will be titled too. Talking about a pivot implies you are not interested in that information. I just wanted to make sure, that this is the case.

            Cheers
            zipit

            MAXON SDK Specialist
            developers.maxon.net

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

              @zipit

              Uhm, yep. For the pivot, I guess I'm also interested on the its "tiltedness". Basically, what the coordinate manager shows (the position and rotation). Sorry for not being clear.

              I would just really like to call on the GetModelingAxis since it corresponds exactly with the coordinate manager but it only works on a selected object not document per se. In other words, it works only on one object but not on multiple objects.

              RE: I do not have the time to do it right now
              No worries. Thanks for the response. Have a great day ahead! 🙂

              1 Reply Last reply Reply Quote 0
              • S
                s_bach
                last edited by s_bach

                Hello,

                the axis displayed of a multi-selection is represented by a helper object.

                One can acess that helper object using BaseDocument.GetHelperAxis().

                See Axis and Plane.

                best wishes,
                Sebastian

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                1 Reply Last reply Reply Quote 1
                • ferdinandF
                  ferdinand
                  last edited by

                  Hi,

                  since @s_bach provided a much cleaner solution, I consider this solved and won't look for manual solution.

                  Cheers
                  zipit

                  MAXON SDK Specialist
                  developers.maxon.net

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

                    @s_bach
                    Thanks for the response! Works as expected.

                    @zipit
                    No worries. Will close this thread.
                    I will probably revive this a year from now (lol). I have a feeling that Matrix will haunt me again in other aspects so this would be a nice exercise if that happens.

                    Thanks again!

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