If statement executes when it's false
<p>I am getting "Knob already attached to a node" when i try to add a knob</p>

<p>i get this when i try to run my code from menu.py button.. if i run the script from the script editor i don't get the error.. why is that?</p>

<pre><code>for i in nuke.allNodes():
    if not i.knob("tempMb"):
        if sum0 == 0:
            nuke.message("first tmp knob created")
            i.addKnob(t)
        elif sum0 != 0:
            nuke.message("second tmp knob created")
    else: 
        nuke.message("no nob created")     
</code></pre>

<p>Even though <strong>i check if there is a knob named tempMb</strong> .. it still executes it as if there was not, when there is..
edit: "t" is earlier defined as Int_Knob...</p>

<p>Thanks!</p>

<p><code>nuke.exists("Name of Knob")</code> will check if your knob exists. Try using that in your if statement.</p>

<p>More details on <a href="http://community.thefoundry.co.uk/discussion/topic.aspx?f=190&amp;t=101399" rel="nofollow">Nuke forum</a>.</p>

<p>See also <a href="https://www.thefoundry.co.uk/products/nuke/developers/100/pythonreference/nuke-module.html#exists" rel="nofollow">Documentation on nuke.exists</a></p>

python nuke