Dear Developers;
Whats the best practice to handle these conditions where the c4d.BaseDraw
is not alive anymore or the plugin probably has old data ?!?
My hunch is I have to reinitialize on restore / reload but I am clueless how to tackle this.
My environment:
User closes all documents (new unsaved document is displayed)
or the user creates new document - then clicks on plugin.
Code snipet:
def __init__(self):
self.doc = GetActiveDocument()
try:
self.rval_bd = self.doc.GetActiveBaseDraw()
except ReferenceError as e:
print("Error: ", e)
"""
more code
"""
def Restore(self, pluginid, sec_ref) :
# Set the pointers to the specific sub dialog here
# rather than in the CommandData section of this plugin
if sec_ref['subid'] == 1:
return self.sub_dialog1.Restore(pluginid, sec_ref)
else:
return super(MainDialog, self).Restore(pluginid, sec_ref)
Where the error occurs:
self.AddCheckbox(ID_SAVEFRAME, flags=c4d.BFH_LEFT, initw=270, inith=0, name="Show Save Frame")
self.SetBool(ID_SAVEFRAME, self.rval_bd[c4d.BASEDRAW_DATA_SHOWSAFEFRAME])
ReferenceError: the object 'c4d.BaseDraw' is not alive
The Try test above does nothing in this regard.
The only thing that works is reloading the python plugins ...
There is more code than this but this might be relevant ?
class MenuCommand(c4d.plugins.CommandData):
dialog = None
def Execute(self, doc):
if self.dialog is None:
self.dialog = MainDialog()
return self.dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, defaulth=100, defaultw=300)
def RestoreLayout(self, sec_ref):
if self.dialog is None:
self.dialog = MainDialog()
return self.dialog.Restore(PLUGIN_ID, sec_ref)
Kind regards
mogh