Hi Kristopher,

why dont you just wrap the functionality that is in the root into a main-method 
and call this in the menu:

def main():
            p = test_panel()
            p.show()

If the name of your py file (module) was" testscript", then you simply call:

testscript.main()

Assuming your python path is set correctly the module should be found an the 
main function should be called...

Does this solve your problem?

lars


Von: nuke-python-boun...@support.thefoundry.co.uk 
[mailto:nuke-python-boun...@support.thefoundry.co.uk] Im Auftrag von Kristopher 
Young
Gesendet: Donnerstag, 29. November 2012 19:43
An: Nuke Python discussion
Betreff: 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 
<youngkristophe...@gmail.com<mailto:youngkristophe...@gmail.com>>
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 
<nathan_ru...@hotmail.com<mailto:nathan_ru...@hotmail.com>>
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<mailto:youngkristophe...@gmail.com>
Sent: Sunday, November 11, 2012 9:52 AM
To: Nuke Python discussion<mailto:nuke-python@support.thefoundry.co.uk>
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 
<mrhowardjo...@yahoo.com<mailto:mrhowardjo...@yahoo.com>>
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 
<youngkristophe...@gmail.com<mailto:youngkristophe...@gmail.com>> wrote:

> def print_value():
>
>    if self.check.value() == True:
>        print "It's true."
>    else:
>        print "It's not true."
> ____________________________________
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk<mailto:Nuke-python@support.thefoundry.co.uk>,
 http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

________________________________
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk<mailto:Nuke-python@support.thefoundry.co.uk>,
 http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk<mailto:Nuke-python@support.thefoundry.co.uk>,
 http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python


_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to