Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    1. Maxon Developers Forum
    2. wilsonic
    3. Posts
    W
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by wilsonic

    • How to move multiple objects axis to origin?

      Hello, I am a python novice, trying to find a way to move the axis of hundreds objects to the origin. I found a great script by Arttu Rautio https://aturtur.com/ar_scripts-for-cinema-4d/, specifically this one https://github.com/aturtur/cinema4d-scripts/blob/master/AR_Scripts_1.0.15/AR_AxisToCenter.py which will move the axis on many objects to their center and am wondering if it's possible to modify this to move the axis to the origin instead.

      This fuction appears to be doing the axis shifting in that script.

      def CenterAxis(obj): # Center object's axis
          doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
          points = [] # Initialize empty list
          pointCount = obj.GetPointCount() # Get object's point count
          for i in range(0, pointCount): # Loop through points
              points.append(obj.GetPoint(i)) # Add point to points list
          matrix = obj.GetMg() # Get object's global matrix
          center = obj.GetMp() # Get Object's bounding box center in local space
          axis = obj.GetAbsPos() # Get object's absolute position
          difference = axis - (axis + center) # Calculate difference
          if difference != c4d.Vector(0): # If there is a difference
              for i in range(pointCount): # Loop through object's points
                  obj.SetPoint(i, points[i] + difference) # Set new point position
              obj.Message(c4d.MSG_UPDATE) # Send update message
              obj.SetMg(c4d.Matrix((matrix * center),
                  matrix.v1, matrix.v2, matrix.v3)) # Set new matrix for the object
      

      I'm wondering if it's as simple as setting the center matrix to a fixed point (0,0,0) but I'm not sure how to format those coordinates as a matrix. (or if it's even this small a change or would need a larger re-write)

      I've also tried using the script log while performing the action manually but the cooridinate manager does not produce log entries that I can see unfortunately.

      Does anyone have any insight on how this might be achieved?

      Thanks

      posted in Cinema 4D SDK python
      W
      wilsonic