Well, using knobChanged is probably the cleanest and simplest way to get access to a specific panel instance’s attributes.
The problem with calling your print_value function *without* using knobChanged is you don’t actually know where to find your panel instance. There are quite a few ways you could deal with this, however, including: 1) Making your panel instance global 2) Making your panel a singleton class and providing a class method that returns the instance (cleaner than #1) 3) If you need multiple instances: Storing a class-level registry dict, and registering each panel instance using a unique identifier as it is created. Then call your function with the identifier of the instance you want to check. -Nathan From: Kristopher Young Sent: Sunday, December 02, 2012 2:33 AM To: Nuke Python discussion Subject: Re: [Nuke-python] Pyhon panels and functions Thanks for your replys! However, If I'm not mistaken none of those methods will actually pass the values from my panel to the function. In other words, I can't print the value of the checkbox in my print_value function. Maybe I'm doing this in a complete different way than I'm supposed to? I've seen it be done with using knobChanged commands, but this seems much cleaner. Any other suggestions? Thanks a lot. 2012/11/30 Nathan Rusch <[email protected]> Assuming all you need to do is show the panel, just bind the whole call to your menu item at once: menu.addCommand(‘Show the Panel’, ‘testscript.test_panel().show()’) -Nathan From: Kristopher Young Sent: Thursday, November 29, 2012 10:43 AM To: Nuke Python discussion Subject: Re: [Nuke-python] Pyhon panels and functions Hi again, forgive me for bringing this thread up again. I've searched for an answer, but I just haven't been able to find one. Using the technique Nathan posted above, everything works perfectly if I run the script in the script editor. But what about if I wanted to add it to a menu in Nuke. Normally I just wrap a function around all of my code and in my menu.py I call testscript.testfunction(). But now the code where I show the panel isn't inside a specific function, it lives in the "root" of the script. I guess this is basic Python, but I would really appreciate your help on this. Thanks a lot! class test_panel(nukescripts.PythonPanel): def __init__(self): nukescripts.PythonPanel.__init__(self, "test panel") self.check = nuke.Boolean_Knob("checkbox", "checkbox") self.addKnob(self.check) self.button = nuke.PyScript_Knob("button", "button") self.addKnob(self.button) self.button.setValue("print_value()") p = test_panel() p.show() def print_value(): if p.check.value() == True: print "It's true." else: print "It's not true." 2012/11/11 Kristopher Young <[email protected]> Thanks for that example Nathan. I will try to read up a bit on Python classes. This is one of my first expreciences with panels so it's a bit hard to grab at the moment. Thanks a lot for your help. 2012/11/11 Nathan Rusch <[email protected]> test_panel is your panel class. Since 'check' is defined in __init__, it doesn’t exist until you create an instance of the class. I recommend reading up a bit on Python classes. p = test_panel() p.show() def print_value(): if p.check.value(): print "It's true" else: print "It's not true" Hope this helps -Nathan From: Kristopher Young Sent: Sunday, November 11, 2012 9:52 AM To: Nuke Python discussion Subject: Re: [Nuke-python] Pyhon panels and functions Hi Howard, I tried your suggestion but it returns "type object 'test_panel' has no attribute 'check". Any idea? I tried with test_panel["check"].value() but that didn't work either. 2012/11/11 Howard Jones <[email protected]> I'm not the best at this by any stretch but isn't it def print_value(): if test_panel.check.value() == True: print "It's true." else: print "It's not true." ____________________________________ Howard On 11 Nov 2012, at 09:28, Kristopher Young <[email protected]> wrote: > def print_value(): > > if self.check.value() == True: > print "It's true." > else: > print "It's not true." > ____________________________________ _______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python -------------------------------------------------------------------------- _______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python _______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python ------------------------------------------------------------------------------ _______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python _______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python -------------------------------------------------------------------------------- _______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________ Nuke-python mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
