Yep, I ended up using if/elif, too. I posted my sample code in a reply to Ivan, 
but here it is again, since I seem to have started more than one email thread 
on this… (blush)

def knobChanged(self, knob):
                if  nuke.thisKnob().name() == 'prefix':
                        self.do_part_filtering()
                        self.viewname_filter_mashup()
                elif  nuke.thisKnob().name() == 'contains':
                        self.do_part_filtering()
                        self.viewname_filter_mashup()
                elif nuke.thisKnob().name() == 'clear_filters':
                        self.clear_views_filters()
                        self.viewname_filter_mashup()
                elif nuke.thisKnob().name() == 'config_images':
                        self.use_part_selection_as_filter()
                        self.viewname_filter_mashup()
                elif nuke.thisKnob().name() == 'exterior_colors':
                        self.viewname_filter_mashup()
                elif nuke.thisKnob().name() == 'interior_colors':
                        self.viewname_filter_mashup()
                elif nuke.thisKnob().name() == 'finishes_colors':
                        self.viewname_filter_mashup()
                elif nuke.thisKnob().name() == 'pick_a_view':
                        
self.active_viewer.setView(self.view_selector_knob.value())


Rich


On May 8, 2013, at 2:40 AM, Ean Carr <eanc...@gmail.com> wrote:

> And since more than one knob will not be changed at a time, I usually use 
> if/elif/elif/elif structure (since there's no switch in python), ensuring 
> when the right knob is found, the flow stops. Not sure how much difference 
> that makes in practice, but, hey, why not.
> 
> 
> On Tue, May 7, 2013 at 6:18 PM, Richard Bobo <richb...@mac.com> wrote:
> OK, my question hasn't shown up in the newsgroups, yet, but I found the 
> answer to my question...
> 
> I just needed to changed all the if statements (e.g. -- "if a_knob:" ) to "if 
> nuke.thisKnob() == a_knob:"
> 
> Sorry for the bandwidth!
> 
> 8^)
> 
> 
> Rich
> 
> 
> Begin forwarded message:
> 
>> From: Richard Bobo <richb...@mac.com>
>> Subject: knobChanged question...
>> Date: May 7, 2013 12:58:05 PM EDT
>> To: Nuke-Users Mailing List List Postings 
>> <nuke-us...@support.thefoundry.co.uk>, Nuke Python discussion 
>> <nuke-python@support.thefoundry.co.uk>
>> 
>> Hi,
>> 
>> This is probably a very elementary question, but I can't quite wrap my head 
>> around it…
>> 
>> I have a Python_Panel with four knobs on it: three Enumeration_Pulldown 
>> knobs and a PyScript_Knob. I have added them all to a knobChanged method. I 
>> am using something like this for my checking:
>> 
>> def knobChanged(self, knob):
>>      if a_knob:
>>              set_something = a_knob.value()
>>      if b_knob:
>>              set_something_else = b_knob.value()
>>      if c_knob:
>>              set_another_thing = c_knob.value()
>>      if d_knob:
>>              run_a_method()
>> 
>> You will probably notice that each time a knob is changed, all of the 
>> statements are executed, including the run_a_function(). I'm sure this is 
>> from "Programming 101", but how do I isolate the knob changed events, so 
>> that *only* the one that has been changed is executed…?
>> 
>> Thanks for any help!
>> 
>> 
>> Rich
>> 
>> Rich Bobo
>> Senior VFX Compositor
>> Armstrong-White
>> http://armstrong-white.com/
>> 
>> Email:  richb...@mac.com
>> Mobile:  (248) 840-2665
>> Web:  http://richbobo.com/
>> 
>> "We are fallible. We certainly haven't attained perfection. But we can 
>> strive for it, and the virtue is in the striving."
>> - Carlos P. Romulo
>> 
>> 
>> 
>> 
>> 
>> 
>> 
> 
> 
> _______________________________________________
> 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
> 
> 
> _______________________________________________
> 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

_______________________________________________
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