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?
You can't only move the axis, for that you need to move the points also (Visually nothing changes).
The problem can be harder that you think because of hierarchies.
You also need to check if the object's type is Opolygon. For that, you can use IsInstanceOf
this question has been asked many times now:
the first one will probably help you a lot, there is a "transfert axis" function.
I also encourage you to read our matrix manual that will help you to understand how it works.
Yes simply use a direction vector to move the points back
Here is a script where the Z-Axis of all selected obects is set to Zero:
# Main function
#==Append Position of every selected Object into a list ============
for a in objs:
#===move every Object in Z to Zero and a inner for-Loop to move every point of the object back with a direction vector
for i in objs:
for p in i.GetAllPoints():
# Execute main()
luckily it worked for me