THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/08/2012 at 08:34, xxxxxxxx wrote:
The work around I came up with works on a different principle.
Since we can't create a container in a script dialog and use it's data to test if the dialog is open or closed. What I needed was something that was already globally available that the script could use as a sort of "state switch".
There's a ton of settable color attributes available for the UI. And I found something really obscure in there called IRR color. Which changes the border color of the IRR.
I thought... Who in the heck would want to change that thing?
So I use it for something more useful...Like a switch that tells my dialog plugin when it can and can't launch. Forcing only one copy of the dialog to be open at a time.
#This is a trick to force only one script manager dialog instance to open
#The script toggles the IRR window color and uses it like a switch to tell the script whether it is allowed to launch or not
#The close button and/or the "X" in the menu sets the IRR color back to it's original white color when the dialog is closed
from c4d import gui
class YourDialog(gui.GeDialog) :
BUTTON_ID = 1001
color = c4d.GetViewColor(c4d.VIEWCOLOR_IRR)
def CreateLayout(self) :
c4d.SetViewColor(c4d.VIEWCOLOR_IRR,c4d.Vector(0,0,0)) #Change the IRR color to black
self.AddButton(self.BUTTON_ID, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "Close Dialog")
def Command(self, id, msg) :
c4d.SetViewColor(c4d.VIEWCOLOR_IRR,self.color) #Set the color back to the original white value
def DestroyWindow(self) : #Use this method to toggle the IRR back to it's original white color
c4d.SetViewColor(c4d.VIEWCOLOR_IRR,self.color) #Set the color back to the original value
dlg = YourDialog()
bgcolor = dlg.color
#If the IRR color is white(default) then go ahead and open this dialog window
if bgcolor.x == 1: dlg.Open(dlgtype= c4d.DLG_TYPE_ASYNC, xpos=600, ypos=500, defaultw=200, defaulth=200)
It works great!
But the down side is that the user could still change the IRR color(why anyone would do that I have no idea..But users often do crazy things) and cause problems.
And I think I would also need to use another UI attribute If I wanted to apply it to two keep two dialogs.
It would be handy if we had a bunch of empty global booleans in our preferences so we could use them for special cases like this.
But then we'd all be doing things that we aren't supposed to do. :joy:
*Edit- I also use a variation of this same code using a null and a user data boolean entry to force only one instance of a dialog to be open. Which is more safe. But requires more initial set up.