UNSOLVED 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

Hi,

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.
https://plugincafe.maxon.net/topic/13004/cad-normal-tag-flipped-after-polyon-merge-join-and-axis-repositioning-how-realign/13

https://plugincafe.maxon.net/topic/11788/move-object-axis-problem-in-python/2
https://plugincafe.maxon.net/topic/13142/how-to-move-axis-to-desired-matrix-without-affecting-object-in-python

I also encourage you to read our matrix manual that will help you to understand how it works.

Cheers,
Manuel

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:

import c4d


# Main function
def main():
    doc.StartUndo
    objs=doc.GetActiveObjects(0)
    points_list=[]
    pos_list=[]

    #==Append Position of every selected Object into a list ============
    for a in objs:
        pos_list.append(a.GetAbsPos())

    counter=0
    #===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:

        i.SetAbsPos(c4d.Vector(i.GetAbsPos().x,i.GetAbsPos().y,0))
        doc.AddUndo(c4d.UNDOTYPE_CHANGE, i)
        richtung=i.GetAbsPos()-pos_list[counter]
        single_points=[]

        for p in i.GetAllPoints():
            single_points.append(p-richtung)

        i.SetAllPoints(single_points)


        counter+=1

    doc.EndUndo()
    c4d.EventAdd()



# Execute main()
if __name__=='__main__':
    main()

luckily it worked for me 🙂