I am getting "Knob already attached to a node" when i try to add a knob
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?
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")
Even though i check if there is a knob named tempMb .. it still executes it as if there was not, when there is.. edit: "t" is earlier defined as Int_Knob...
Thanks!
First I'm going to change the elif
to just else
because your if condition is already testing the elif condition and I don't see how that would be changing while in this code.
for i in nuke.allNodes():
if not i.knob("tempMb"):
if sum0 == 0:
nuke.message("first tmp knob created")
i.addKnob(t)
else:
nuke.message("second tmp knob created")
else:
nuke.message("no nob created")
Second I'm assuming that i.knob(string)
doesn't check for the existence of a knob by that name, or your code would behave more as you expected. So when I read the docs it seems like a couple of things may happen:
nuke.allNodes(nuke.Knob)
.if i.name != "tempMb":
or possibly if i.label != "tempMb"
it depends on how you created t
. Moving on though, I think there may be a logical error here. If you have 2 nodes (and if you make the above changes, let's assume they're both knobs), and as you loop over all nodes the first one is the tempMb
, then when you check the second one it won't be that and you'll try to add t
, which I assume is named tempMb
too. So that's why it looks to you as though the negative condition is always occurring.
You need to restructure in one of two ways:
tempMb
is found; you may as well exit the loop as soon as this occurs. After the loop check the boolean to see if it's safe to add t
.nuke.exists(s)
which tells you if you have any "item" named s
.Maybe remove the loop and write the following:
if not nuke.exists("tempMb"):
# Add your knob. I'm actually not seeing `addKnob` in the docs.
nuke.exists("Name of Knob")
will check if your knob exists. Try using that in your if statement.
More details on Nuke forum .
See also Documentation on nuke.exists
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.