GeDialog Set combo default and hide/show fields
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/11/2012 at 03:15, xxxxxxxx wrote:
Cinema 4D Version: 13
Platform: Mac ;
Language(s) : Phyton ;Hi guys, I'm playing with dialogs and trying to figure out some things. With a little searching on forum I ended up having this code in a script, the code kinda works but I can't get a couple things:
- How do I set the default value (selected option) of a combo box ? .SetLong doesn't seem to work
- Is It possible to hide/show gadgets (or disable/enable) upon the selected value in a combo box ?This is the code:
import c4d from c4d import gui #Welcome to the world of Python def sweep_circle(rad) : print "Sweep circolare con raggio = ", rad return def sweep_square(lato) : print "Sweep quadrata lato = ", lato return class ExampleDlg(gui.GeDialog) : def CreateLayout(self) : #create the layout of the dialog self.GroupBegin(999, c4d.BFH_SCALEFIT, 2, 1) self.AddStaticText(1000, c4d.BFH_LEFT, name="Sezione") self.AddComboBox(1001, c4d.BFH_SCALEFIT) self.AddChild(1001,10011,"Circle") self.AddChild(1001,10012,"Square") self.AddStaticText(1002, c4d.BFH_LEFT, name="Radius") self.AddEditNumberArrows(1003, c4d.BFH_LEFT) self.AddStaticText(1006, c4d.BFH_LEFT, name="Edge Lenght") self.AddEditNumberArrows(1007, c4d.BFH_LEFT) self.AddButton(1004, c4d.BFH_SCALE, name="Close") self.AddButton(1005, c4d.BFH_SCALE, name="OK") self.GroupEnd() return True def InitValues(self) : #initiate the gadgets with values self.SetReal(1003, 10, min=0, step=0.1) self.SetReal(1007, 10, min=0, step=0.1) self.SetLong(1001, 1) return True def Command(self, id, msg) : #handle user input if id==1005: if self.GetLong(1001)==10011: rad = self.GetReal(1003) sweep_circle(rad) self.Close() elif self.GetLong(1001)==10012: lato = self.GetReal(1007) sweep_square(lato) self.Close() else: print "Nessuna sezione" gui.MessageDialog("Seleziona una sezione") elif id==1004: self.Close() return True dlg = ExampleDlg() dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50) # ASYNC = floating, MODAL = dialogo standard
What I want is to show Radius field only when Circle option is selected from the combo, and Edge Length only when Square is selected..don't really know if I can do it in a script.
Any advice would be great ! thanks
Massimiliano -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/11/2012 at 05:44, xxxxxxxx wrote:
Hi Massimiliano,
Originally posted by xxxxxxxx
- How do I set the default value (selected option) of a combo box ? .SetLong doesn't seem to work
self.AddChild(1001,10011,"Circle") self.AddChild(1001,10012,"Square")
You add the child with 10011 and 10012 but you set the default value with 1 :
self.SetLong(1001, 1)
You should pass 10011 instead.
Originally posted by xxxxxxxx
- Is It possible to hide/show gadgets (or disable/enable) upon the selected value in a combo box ?
You can disable/enable gadgets with GeDialog.Enable().
It's also possible to build dynamic groups with this sequence:GeDialog.LayoutFlushGroup(...) # Removes all gadgets from a group GeDialog.GroupBegin(...) # Add gadgets GeDialog.GroupEnd() self.LayoutChanged(...)
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/11/2012 at 05:58, xxxxxxxx wrote:
Thank for you response Yannick!
For the combo default, Ok now I'm getting how this worksFor GeDialog.Enable() I'm a little confused on where should I put it... inside CreateLayout, InitValues or Command ?
M.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/11/2012 at 06:20, xxxxxxxx wrote:
Originally posted by xxxxxxxx
For GeDialog.Enable() I'm a little confused on where should I put it... inside CreateLayout, InitValues or Command ?
In both InitValues() (to set the initial state of gadgets) and Command() (to respond to the combo box selection changes) you should call a method of your own named like UpdateGadgets().
This method would enable or disable the gadgets depending on the combobox selection. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/11/2012 at 06:45, xxxxxxxx wrote:
Ok, I will try to make it work Thanks
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/11/2012 at 18:44, xxxxxxxx wrote:
I finally managed to get a dialog...thanks for all the suggestions!
I have now a dialog with custom 'Ok' and 'Cancel' buttons...but..is there a way to get the OK button pressed when Enter key is pressed on the keyboard ?Thanks
M. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/11/2012 at 01:51, xxxxxxxx wrote:
Hi Massimiliano,
Originally posted by xxxxxxxx
I have now a dialog with custom 'Ok' and 'Cancel' buttons...but..is there a way to get the OK button pressed when Enter key is pressed on the keyboard ?
With the SDK you can easily add 'OK' and 'Cancel' buttons to a dialog with GeDialog.AddDlgGroup():
self.AddDlgGroup(c4d.DLG_OK|c4d.DLG_CANCEL)
This method creates 'OK' and 'Cancel' buttons with IDC_OK and IDC_CANCEL identifiers respectively.
To sets the focus to 'OK' button use GeDialog.Activate():
self.Activate(c4d.IDC_OK)
Finally in Command() you can then filter the buttons:
if id==c4d.IDC_OK: print "OK was pressed" elif id==c4d.IDC_CANCEL: print "Cancel was pressed"
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/11/2012 at 12:51, xxxxxxxx wrote:
Hi Yannick!
Thanks again for your help.
This the result of my efforts so far: its a plug-in to sweep multiples splines at once with either circular or square profile..like QuickPipe with a twist Surely the code can be improved, but seems to work..import c4d import os from c4d import documents, plugins, bitmaps, gui #updated version PLUGIN_ID = 1029425 splineList = None def checkObj(obj_list) : spline = 0 tot = len(obj_list) for obj in obj_list: tipo = obj.GetTypeName() if (obj.CheckType(c4d.Ospline) or obj.CheckType(c4d.Ospline4side) or obj.CheckType(c4d.Osplinearc) or obj.CheckType(c4d.Osplinecircle) or obj.CheckType(c4d.Osplinecissoid) or obj.CheckType(c4d.Osplinecogwheel) or obj.CheckType(c4d.Osplinecontour) or obj.CheckType(c4d.Osplinecycloid) or obj.CheckType(c4d.Osplineflower) or obj.CheckType(c4d.Osplineformula) or obj.CheckType(c4d.Osplinehelix) or obj.CheckType(c4d.Osplinenside) or obj.CheckType(c4d.Osplineprimitive) or obj.CheckType(c4d.Osplineprofile) or obj.CheckType(c4d.Osplinerectangle) or obj.CheckType(c4d.Osplinestar) or tipo == "MoSpline" or obj.CheckType(c4d.Osplinetext) or isinstance(obj, c4d.SplineObject)) : spline = spline+1 if spline < tot : #print "Tutti gli oggetti devono essere splines" return False else: return True def main() : doc = documents.GetActiveDocument() obj_list = doc.GetActiveObjects(0) if not obj_list: gui.MessageDialog('At least one spline must be selected') return elif checkObj(obj_list) : global splineList splineList = obj_list dlg = QuickSweepDlg() dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50) # ASYNC = floating, MODAL = dialogo standard else: gui.MessageDialog('Only splines can be selected') def sweep_circle(rad,originals) : doc=documents.GetActiveDocument() k=0 doc.StartUndo() c4d.CallCommand(100004767) for spline in splineList: k=k+1 sweep = c4d.BaseObject(c4d.Osweep) sez = c4d.BaseObject(c4d.Osplinecircle) phong = c4d.BaseTag(c4d.Tphong) phong[c4d.PHONGTAG_PHONG_ANGLELIMIT]=True phong[c4d.PHONGTAG_PHONG_ANGLE]=c4d.utils.Rad(80) phong[c4d.PHONGTAG_PHONG_USEEDGES]=True sez[c4d.ID_BASELIST_NAME] = sez.GetName()+"_section" tracciato = spline.GetClone() sez[c4d.PRIM_CIRCLE_RADIUS] = rad sweep[c4d.ID_BASELIST_NAME] = "Sweep_"+spline.GetName() doc.InsertObject(sweep) doc.AddUndo(c4d.UNDOTYPE_NEW,sweep) if originals==True: tracciato.InsertUnder(sweep) tracciato[c4d.ID_BASELIST_NAME] = tracciato.GetName()+"_path" else: doc.AddUndo(c4d.UNDOTYPE_CHANGE,spline) spline[c4d.ID_BASELIST_NAME] = spline.GetName()+"_path" spline.InsertUnder(sweep) sez.InsertUnder(sweep) sweep.InsertTag(phong) doc.EndUndo() c4d.EventAdd() return def sweep_square(lato,originals) : doc = documents.GetActiveDocument() k=0 doc.StartUndo() c4d.CallCommand(100004767) for spline in splineList: k=k+1 sweep = c4d.BaseObject(c4d.Osweep) sez = c4d.BaseObject(c4d.Osplinerectangle) phong = c4d.BaseTag(c4d.Tphong) phong[c4d.PHONGTAG_PHONG_ANGLELIMIT]=True phong[c4d.PHONGTAG_PHONG_ANGLE]=c4d.utils.Rad(80) phong[c4d.PHONGTAG_PHONG_USEEDGES]=True sez[c4d.ID_BASELIST_NAME] = sez.GetName()+"_section" tracciato = spline.GetClone() sez[c4d.PRIM_RECTANGLE_WIDTH] = lato sez[c4d.PRIM_RECTANGLE_HEIGHT] = lato sweep[c4d.ID_BASELIST_NAME] = "Sweep_"+spline.GetName() doc.InsertObject(sweep) doc.AddUndo(c4d.UNDOTYPE_NEW,sweep) if originals==True: tracciato.InsertUnder(sweep) tracciato[c4d.ID_BASELIST_NAME] = tracciato.GetName()+"_path" else: doc.AddUndo(c4d.UNDOTYPE_CHANGE,spline) spline[c4d.ID_BASELIST_NAME] = spline.GetName()+"_path" spline.InsertUnder(sweep) sez.InsertUnder(sweep) sweep.InsertTag(phong) return class QuickSweepDlg(gui.GeDialog) : def UpdateDlg(self, id) : if id==10011: self.Enable(1002,True) self.Enable(1003,True) self.Enable(1006,False) self.Enable(1007,False) elif id==10012: self.Enable(1002,False) self.Enable(1003,False) self.Enable(1006,True) self.Enable(1007,True) self.LayoutChanged(999) def CreateLayout(self) : #create the layout of the dialog self.SetTitle("QuickSweep") self.GroupBegin(999, c4d.BFH_SCALEFIT, 2, 5, groupflags=c4d.BFV_GRIDGROUP_EQUALROWS|c4d.BFV_GRIDGROUP_EQUALCOLS) self.GroupBorderSpace(10, 10, 10, 10) self.GroupBorderNoTitle(c4d.BORDER_ROUND) self.AddStaticText(1000, c4d.BFH_LEFT, name="Section") self.AddComboBox(1001, c4d.BFH_SCALEFIT) self.AddChild(1001,10011,"Circle") self.AddChild(1001,10012,"Square") self.AddStaticText(1002, c4d.BFH_LEFT, name="Radius") self.AddEditNumberArrows(1003, c4d.BFH_LEFT) self.AddStaticText(1006, c4d.BFH_LEFT, name="Edge Lenght") self.AddEditNumberArrows(1007, c4d.BFH_LEFT) self.AddCheckbox(1008, c4d.BFH_LEFT, initw=0, inith=0, name="Keep original(s)") self.GroupEnd() self.GroupBegin(998, c4d.BFH_SCALEFIT, 2, 1) self.AddDlgGroup(c4d.DLG_CANCEL|c4d.DLG_OK) #self.AddButton(1004, c4d.BFH_SCALE, name="Close") #self.AddButton(1005, c4d.BFH_SCALE, name="OK") self.GroupEnd() return True def InitValues(self) : #initiate the gadgets with values self.SetReal(1003, 10, min=0, step=0.1) self.SetReal(1007, 10, min=0, step=0.1) self.SetLong(1001, 10011) self.SetBool(1008, False) self.Activate(c4d.IDC_OK) self.UpdateDlg(self.GetLong(1001)) return True def Command(self, id, msg) : #handle user input self.UpdateDlg(self.GetLong(1001)) if id==c4d.IDC_OK: if self.GetLong(1001)==10011: rad = self.GetReal(1003) sweep_circle(rad,self.GetBool(1008)) self.Close() elif self.GetLong(1001)==10012: lato = self.GetReal(1007) sweep_square(lato,self.GetBool(1008)) self.Close() elif id==c4d.IDC_CANCEL: self.Close() elif id==c4d.BFM_INPUT: if msg[c4d.BFM_ACTION_ESC]==True: print "Action Escaped" self.Close() return True class QUICKSWEEP(plugins.CommandData) : pass def Execute(self, doc) : main() return True if __name__ == "__main__": # load icon.tif from res into bmp bmp = bitmaps.BaseBitmap() dir, file = os.path.split(__file__) fn = os.path.join(dir, "res", "QuickSweep.tif") bmp.InitWith(fn) # register the plugin okyn = plugins.RegisterCommandPlugin(id=PLUGIN_ID, str="Quick Sweep", info=c4d.PLUGINFLAG_COMMAND_HOTKEY, icon=bmp, help="Quick sweep multiple splines", dat=QUICKSWEEP()) print "" print "-------------- QuickSweep 1.0 by Visualtricks ----------------" if okyn: print "QuickSweep 1.0 initialized " else: print "Something went wrong - QuickSweep could not initialize" print "----------------------------------------------------------" print ""
can be downloaded from here: http://www.visualtricks.it/site/wp-content/uploads/2012/11/QuickSweep1.zip
If anyone wants to give any advice, will be appreciated !Cheers
Massimiliano