Hi there,
I have a python generator that reads the rad and mp of a clone of an object.
When I move and transform the object the origin matrix of the clone is reset to 0.
I was hoping to get the new rad and mp of the transformed state, but still get the same values as the original object.
In the documentation it states, that "the radius is internally cached".
So I suspect resetting the matrix will will not update the cache.
Is it somehow possible to update this cache or do i have to calculate the bunding box myself?
Best, Sebastian
import c4d
doc: c4d.documents.BaseDocument # The document the object `op` is contained in.
op: c4d.BaseObject # The Python generator object holding this code.
hh: "PyCapsule" # A HierarchyHelp object, only defined when main is executed.
# ===============
def csto( obj: c4d.BaseObject, doc = None ) -> c4d.BaseObject:
"""modeling command - current state to object
"""
if not doc:
doc = c4d.documents.GetActiveDocument()
res = c4d.utils.SendModelingCommand( c4d.MCOMMAND_CURRENTSTATETOOBJECT, [ obj ], doc=doc)
if not res: print ( f"main command: csto error: {obj.GetName()}" )
else:
res = res[0]
for i in range(10):
if res.GetType()==c4d.Onull and res.GetDown():
res = res.GetDown().GetClone()
elif res.GetType()!=c4d.Onull:
res = res.GetClone()
break
else:
res = None
print ( f"main command: csto error 2: {obj.GetName()}" )
break
return res
def change_object_origin_matrix( obj: c4d.PointObject, matrix ):
mg_old = obj.GetMg()
mg_new = matrix
m_delta = c4d.Matrix(~mg_old * mg_new )
obj.SetAllPoints( [(p * ~m_delta) for p in obj.GetAllPoints()] )
obj.SetMg( mg_new )
return
# ===============
def main() -> c4d.BaseObject:
"""Called by Cinema 4D to retrieve the cache of the Python Generator object.
"""
obj = op[c4d.ID_USERDATA,1]
if obj:
obj = obj.GetClone()
obj = csto( obj )
change_object_origin_matrix( obj, c4d.Matrix() )
rad = obj.GetRad()
mp = obj.GetMp()
cube = c4d.BaseObject(c4d.Ocube)
cube[c4d.PRIM_CUBE_LEN] = rad*2
cube[c4d.ID_BASEOBJECT_REL_POSITION] = mp
return cube
else:
return c4d.BaseObject(c4d.Onull)