Hi im converting Materials using the Corona To C4D Plugin,
and im running into a strange problem, were my the context for my doc seems to go missing. But first thing first:
I convert using the Cinema 4D exe as commandline, as the plugin otherwise does not seem to convert and store the information.
"Cinema 4D.exe" -nogui etc. etc..
This gives me very little commandline error output, making it very hard to debug, but its the only workaround i got for now. Se la vie.
I call my converter module giving it a doc reference and storing the document reference upon return
cac = CoronaAuraConverter.Converter(clone)
cloneResult = cac.main(clone, self, dst)
clone = cloneResult
In the converter submodule i process using the following code. This is because i can not seem to acess the converted materials until i saved and reload the document. This has been profen to work in a minimal sandbox example.
def main(self, doc, vuframeAuraInstanceRef, dst):
#Conversion process copied from Sandbox
tempORaryFilePath = self.tools.path_replace_leaf( dst, "tempStorageForMaterialDrop.c4d")
LogWithTimestamp("TempoaryFilePath " + tempORaryFilePath)
documents.SaveDocument(doc, tempORaryFilePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_C4DEXPORT)
newDoc = Tools.loadActiveDocumentFrom(tempORaryFilePath)
allMats = newDoc.GetMaterials()
for mat in allMats:
LogWithTimestamp("Storing Material Standard Info:" + mat.GetName())
#Doing work with the loaded materials - this work
Upon return working with the returned old doc reference seems to fail.
I tried to refresh it with
doc = documents.GetActiveDocments()
assumption being its some context reference going stale and getting gcc or similar.
Anyone any idea were i did go wrong. Also a way to get the standard output beyond 25 kb by g_logfile="c4dconversion.log" would be greatly appreciated.
PS: Is there a way to buy SDK-Team Support tickets?
PS: Just for completness, not relevant as it loads the document
print "DEBUG: file exists :" + str(os.path.exists(src))
load = documents.LoadFile(src)
if not load:
LogWithTimestamp( "Source File could not be loaded: " + src)
raise FileNotFoundError("Source file at path " +src + " not found")
doc = documents.GetActiveDocument()
if doc is None:
LogWithTimestamp( "Could not get active document")
Thank you for reaching out to us. Please note that there are certain limitations to the support we provide and the form we require:
With that being said, I am not sure if you have solved your problem yourself by now. But there are a few things I would point out:
Finally, you report the doc 'reference seems to fail.' Fail could mean here multiple things, but from the whole setting of your question is would assume that you are encountering a dead atom. The Python object cannot be garbage collected before its reference count goes to zero, just as any other Python object. But this c4d.documents.BaseDocument object called doc is just the frontend for a C++ object of matching type in the backend. A pattern as the following can be dangerous:
node = c4d.BaseList2D(typeID)
As node is not bound to any scope after the scope of foo has been left and cause Cinema 4D Python bindings to deallocate the C++ object wrapped by node. This severing of the C++ to Python binding of an object can be tested with C4DAtom.IsAlive(). There are also other cases where an object can die, as Cinema 4D often reallocates objects in the background. Since a BaseDocument is a BaseList2D, is a GeListNode, is a C4DAtom, it can also die. There are no diagrams for the life cycle of a BaseDocument. Many things in the backend of our API can decide to reallocate an object.
Thank you for the answer @ferdinand . Sorry for the decay of the follow up posts, im used to posting all attempted solutions, so that future readers have a guide.
We solved the problem by converting in a seperate Plugin call and it seems the legacy code im working on, "accidentally" reduced the context switch stale objects, by regularly re-storing the document refrence from a old reference kept in main. Your answers have been very useful and highlight important concepts developers should be well aware off. Thanks gain.
Thanks for the update!