Hi @mogh,
unfortunately it is not quite clear to me what you are trying to do, because both your snippets are not executable, i.e. are just snippets or include pseudo-code. However, from this general setting and your wording in your first posting, I assume you are simply trying "to move the axis of an object without moving its points", i.e. do what the move axis tool does. Below you find a simple script which shows you how to change the transform of a PointObject
without changing the global coordinates of its points.
If this is not what you are looking for, I would ask you to show us code that is executable and to explain in more detail what kind of transform you are looking for.
Cheers,
Ferdinand
"""Demonstrates how to "move" the transform of a point object.
"Moves" the transform of a PointObject without changing the global
coordinates of its points, i.e. does what the move axis tool does.
You have to select a point object and then another object and it will move
the axis of the point object to the scond one.
"""
import c4d
def set_point_object_transform(node, transform):
"""Sets the global transform of a point object while keeping its points
in place.
Args:
node (c4d.PointObject): The point object to move the axis for.
transform (c4d.Matrix): The new global transform for the object.
Raises:
TypeError: When node or transform are not of specified type.
"""
if (not isinstance(node, c4d.PointObject) or
not isinstance(transform, c4d.Matrix)):
msg = f"Illegal argument types: {type(node)}{type(transform)}"
raise TypeError(msg)
mg = node.GetMg()
# Move the points in the global frame and then into the new frame.
points = [p * mg * ~transform for p in node.GetAllPoints()]
# Set the points and stuff ;)
node.SetAllPoints(points)
node.Message(c4d.MSG_UPDATE)
node.SetMg(transform)
def main():
"""Runs set_point_object_transform() on the current selection.
"""
nodes = doc.GetActiveObjects(0)
if len(nodes) < 2:
return
node, transform = nodes[0], nodes[1].GetMg()
set_point_object_transform(node, transform)
c4d.EventAdd()
if __name__ == "__main__":
main()