Hello everyone,
I'm writing a python generator plugin that should load an preset object from a file and return a modified version of that in GetVirtualObjects().
Right now the preset scene is just a simple cube without anything else.
The code I'm using:
def __init__(self):
self.loadedObject = None
self.SetOptimizeCache(True)
def Init(self, op):
#loading preset file and save first object internally
if not self.loadedObject:
dir, file = os.path.split(__file__)
path = os.path.join(dir, "presets", "test.c4d")
presetDoc = c4d.documents.LoadDocument(path, c4d.SCENEFILTER_OBJECTS, None)
self.loadedObject = presetDoc.GetFirstObject()
return True
def GetVirtualObjects(self, op, hh):
#return clone of loaded object
return self.loadedObject.GetClone()
Basically loading and extracting the object from the file is fine. The problem is that the object is not loaded/executed before it is added to the current doc and a refresh was forced.
When I add or reload the generator the object looks like this until i move the mouse and trigger a refresh:
I can of course force a refresh via code, but I still can't convert the generator with "Make editable" or "Current State to object". Then only an empty object is returned.
It looks like the conversion uses the state before the refresh and returns nothing.
I tried a lot of things like ExecutePasses() on the loaded document or setting the cube to dirty and sending update messages but nothing helped so far.
Adding the cube into the current document under the generator and hiding it is some kind of workaround but that leads to other problems - like being added multiple times because op.GetDown() not always returns the child on undo or scene changes or not being able to use "Make editable" and stuff like that.
Maybe there is something I missed?