On 27/05/2013 at 03:27, xxxxxxxx wrote:
Ah yes, I remember this when I implemented a Python tool! I'm not sure how I got to know when
the dialog was not visible anymore back then, but what I know is, that the reference to the dialog
was not valid anymore and therefore Cinema crashed or you got invalid data. I cached the parameters
using a small tool I wrote, and now I have it implemented in c4dtools.misc.dialog. Maybe you want
to check it out, it is very useful. It enables you to retrieve all values of a dialog in a BaseContainer or
a dictionary, and also allows you to set the values back via a BaseContainer or dictionary.
Here's an excerpt from a plugin where I used it in. In this code, I used it to save and load the
parameters of the dialog to keep the configuration even when you restarted Cinema. You can
use this to cache your symbols of course.
import c4d
import c4dtools
from c4dtools.misc.dialog import DefaultParameterManager
res, _ = c4dtools.prepare()
class MainDialog(c4d.gui.GeDialog) :
def __init__(self) :
super(MainDialog, self).__init__()
self.params = DefaultParameterManager()
# Initialize the Parameter Manager.
p = self.params
p.add('reset_axes', res.CHK_RESETAXES, 'b', True)
p.add('optimize', res.CHK_OPTIMIZE, 'b', True)
p.add('optimize_tolerance', res.EDT_OPTIMIZE_TOLERANCE, 'm', 0.01)
p.add('set_phong_angle', res.CHK_SETPHONGANGLES, 'b', True)
p.add('phong_angle', res.EDT_PHONGANGLE, 'd', math.radians(21))
p.add('untri', res.CMB_UNTRIANGULATE, 'i', res.CMB_UNTRIANGULATE_NGONS)
p.add('remove_empty', res.CHK_REMOVEEMPTYNULLS, 'b', True)
p.add('preserve_names', res.CHK_PRESERVENAMES, 'b', True)
p.add('remove_normaltags', res.CHK_REMOVENORMALTAGS, 'b', True)
p.add('remove_uvwtags', res.CHK_REMOVEUVWTAGS, 'b', True)
p.add('align_normals', res.CHK_ALIGNNORMALS, 'b', True)
p.add('norm_projection', res.CHK_NORMALIZEPROJECTION, 'b', True)
# Just a helper I used, I could now access parameters using
# self.v_optimize to get the value associated with the name "optimize"
# in the DefaultParameterManager.
def __getattr__(self, name) :
if name.startswith('v_') :
name = name[2:]
return self.params.get(self, name)
else:
return getattr(super(MainDialog, self), name)
def CreateLayout(self) :
return self.LoadDialogResource(res.DLG_MAIN)
def InitValues(self) :
self.params.set_defaults(self)
# Load a BaseContainer with all the parameters of the dialog.
config = load_dialog_config()
self.params.load_container(self, config)
return True
def DestroyWindow(self) :
config = self.params.to_container(self)
save_dialog_config(config)
-Nik