@m_magalhaes
Hi there,
Well, I figured it out, and have no issue rendering to picture viewer with python effector, so not sure what you're referring to, but maybe the bug is fixed?
Here is the code that works as intended, although it requires a frame update to change. I'm guessing I can fix that as well with a bit more tinkering. This works as intended with the cloner in either instance or render instance mode.
from typing import Union
import c4d
from c4d.modules import mograph as mo
from c4d import utils
op: c4d.BaseObject # The python effector
gen: c4d.BaseObject # The MoGraph Generator executing the effector
doc: c4d.documents.BaseDocument # The document evaluating this effector
thread: c4d.threading.BaseThread # The thread executing this effector
def SetTarget (objMx, target):
pos2 = target[c4d.ID_BASEOBJECT_REL_POSITION]
pos1 = objMx.off
vec3=(pos2-pos1).GetNormalized()
vec2=vec3.Cross(c4d.Vector(0,1,0)).GetNormalized()
vec1=vec3.Cross(c4d.Vector(1,0,0)).GetNormalized()
newMx = c4d.Matrix(pos1,vec1,vec2,vec3)
newRot = c4d.utils.MatrixToHPB(newMx)
return newRot
def main() -> Union[c4d.Vector, float, int]:
# Called when the effector is executed to set MoGraph data.
target = doc.SearchObject("TargetNull")
if (target == None): return False
moData = c4d.modules.mograph.GeGetMoData(gen)
marr = moData.GetArray(c4d.MODATA_MATRIX)
cloneSource = gen.GetCache().GetDown()
clones = []
while cloneSource != None:
clones.append(cloneSource)
cloneSource = cloneSource.GetNext()
cnt = len(clones)
frame = doc.GetTime().GetFrame(doc.GetFps())
for i in range(cnt):
fixt = clones[i]
base = fixt.GetDown()
yoke = base.GetDown()
head = yoke.GetDown()
newRot = SetTarget(marr[i], target)
head.SetRelRot(c4d.Vector(0,newRot.y,0))
yoke.SetRelRot(c4d.Vector(newRot.x,0,0))
moData.SetArray(c4d.MODATA_MATRIX, marr, False)
c4d.EventAdd()
return True