Hello everyone, I ran into the simplest case that I introduced made me freeze for the whole evening.
Let's say there is a cube object, it has its own PRS (as in the screenshot). We apply GroupObjects to it, a parent object is created with the same coordinates as the cube itself.
Now, we're making Connect Objects so that it all becomes a normal editable object again. But for Axis, the position remains unchanged, and the rotation is reset. How to make sure that the PRS of the new object remains exactly the same as the original cube?
Of course, the simplest solution is to just copy the coordinates, but I'm looking forward to porting a huge game project with tens of thousands of such objects, each of which will have to repeat this over and over again (don't ask why, it's too long to explain). In general, doing it by hand is not an option.
I found out that the result I need can be achieved if I make a copy of the object, reset all its coordinates, do Connect + Delete, and then return it to its original place using the transfer. It remains only to automate this process.
So I decided to try to write a script that would do this.
I tried different methods, at the moment I settled on the fact that I instantiate the object (it remains in the right coordinates), the coordinates of the original object are reset and the connection + deletion occurs. And then, in theory, the coordinates of the PRS should be transferred from the instance to the original, followed by the removal of the instance, but this does not happen. There is a feeling that after combining the group into an object, the script loses the desired object and does not understand what to do next.
I apologize for the extremely incomprehensible story, I will be grateful for the answers and answer any questions.
Program code in its current form:
![from typing import Optional
import c4d
from c4d import gui
doc: c4d.documents.BaseDocument
op: Optional[c4d.BaseObject]
def main():
objs = doc.GetActiveObjects(1)
doc.StartUndo()
for obj in objs:
inst = c4d.BaseObject(c4d.Oinstance)
inst.SetName(obj.GetName()+' Instance')
inst[c4d.INSTANCEOBJECT_LINK]= obj
doc.InsertObject(inst)
inst()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X]
inst()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y] = obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y]
inst()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z] = obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z]
inst()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X]
inst()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y]
inst()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z]
inst()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_X] = obj()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_X]
inst()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_Y] = obj()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_Y]
inst()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_Z] = obj()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_Z]
obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = 0
obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y] = 0
obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z] = 0
obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = 0
obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = 0
obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = 0
obj()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_X] = 1
obj()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_Y] = 1
obj()[c4d.ID_BASEOBJECT_REL_SCALE,c4d.VECTOR_Z] = 1
obj[c4d.CallCommand(16768)]
obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = inst()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X]
obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y] = inst()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y]
obj()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z] = inst()[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z]
obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = inst()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X]
obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = inst()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y]
obj()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = inst()[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z]
doc.EndUndo()
c4d.EventAdd()
if __name__ == '__main__':
main()