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>Try this solution:</p>

<pre><code>t = nuke.Int_Knob( 'tempMb', 'tempMb' )

for i in nuke.allNodes():
    if not i.knob("tempMb"):
        if nuke.exists("sum0"):
            nuke.message("First tmp knob created")
            i.addKnob(t)
        else:
            nuke.message("Second tmp knob created")
    else: 
        nuke.message("No knob created")
</code></pre>

<p><a href="https://i.stack.imgur.com/fqgbx.png" rel="nofollow"><img src="https://i.stack.imgur.com/fqgbx.png" alt="enter image description here"></a></p>

python nuke