Search code examples
pythontclnuke

Hey python to resolve tcl variable? Nuke


So, I'm trying to get python to print a string that had a tcl variable in it, with the result of that variable. I'm using nuke, in case that matters for my code.

[set THIS image] 
Ln = "/Test/still/testing/$THIS\_clean_v001"
print(Ln) # this prints exactly the above

G = nuke.tcl('[puts "$THIS"] ') 

Would print(G) return the word image or no?

I could then sub it in. The problem is the text field I'm entering that tcl in to solves it inside the program fine, but then as soon as I send it to process it takes the $THIS literally.


Solution

  • Two things to note:

    1. Tcl puts does not return a value. It sounds like you want Tcl set, which does.

    2. The docs for nuke.tcl at http://www.nukepedia.com/reference/Python indicate:

      tcl(command, arg, arg, ...)

      Run a tcl command. The arguments must be strings and passed to the command. If no arguments are given and the command has whitespace in it then it is instead interpreted as a tcl program (this is depreciated)

    Rather than invoking it as a full script, it seems you could both use the non-deprecated version and get the behavior you want by using:

    G = nuke.tcl("set", "THIS")
    

    Whic should reutrn the value of the THIS variable.