thanks for your code and for investing time into that!
I tried it and found some problems:
ReferenceError: the object 'c4d.BaseObject' is not alive
I think your code behaves the same as mine from the first post if you omit the .GetClone() in GVO there. I am not sure if the c4d.SCENEFILTER_SAVECACHES loading flag and ExecutePasses change anything. I have to add I only tested with a cube as preset. I could be the case that some of that is needed for Sweeps or the like.
no, the scene I load is just a simple cube object.
Initially I started with SweepNurbs and also suspected them to be the problem but then noticed it already happens with simple objects.
This old post I found seems to be a similar problem or even the same.
Unfortunately the issue was not solved. The original poster gave up on loading presets and created them in code which is not sensible for me because the presets will be quite complex.
thank you very much for your answer!
No errors in the console at all (unfortunately? ). Also no change if i add a check for self.loadedObject. Or even load the object in the GVO itself. So it looks like the order is not the problem here. The loaded object seems to be present.
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:
self.loadedObject = None
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()
def GetVirtualObjects(self, op, hh):
#return clone of loaded object
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?