Thread: Evaluating complete tcl expressioin

Reply to Thread
Results 1 to 5 of 5
  1. #1 Evaluating complete tcl expressioin 
    Join Date
    May 2010
    Location
    Düsseldorf, Germany
    Posts
    16
    Hey there!

    I'm using a TCl-Expression (in the file-parameter) to build dynamic folder-names in write-nodes.
    for example:

    /sh020/versions/v[string trimleft [lindex [split [string trim [file tail [value root.name]] .nk] _] 1] v]/[string trim [file tail [value root.name]] .nk].%04d.jpg

    I'd now like to parse this expression and have it return the proper string. I tried nuke.tcl(). It does parse the expression correctly, but somehow assumes, i wanna run the result as a command and returns this error:

    RuntimeError: sh020_v00_sys.nk: Unknown command

    sh020_v00_sys.nk is the resulting string but i can't explain the runtimeerror.

    If someone has an idea, i'd greatly appreciate it

    cheers,
    sean
    Reply With Quote  

  2. #2  
    Join Date
    Feb 2007
    Posts
    993
    If you're calling nuke.tcl() directly in the "file" knob of your Write node (e.g. [python {nuke.tcl ("Some TCL Expression")}] ), that means you're using Nuke's TCL interpreter to call a Python function that calls another TCL expression. The "Unknown command" error is a TCL error, and you're getting it because your Python call is returning the string directly to the TCL interpreter, which then tries to run it as a command.

    Where do you need to return the actual expression value to?
    Reply With Quote  

  3. #3  
    Join Date
    May 2010
    Location
    Düsseldorf, Germany
    Posts
    16
    i want to retrieve the file name from the write node for automated folder-generation.
    i just want to solve the tcl-expression before handing over the path to the folder-generation-script.
    Reply With Quote  

  4. #4  
    Join Date
    Feb 2007
    Posts
    993
    Oh I see. Well there are a couple ways to do this.

    If you want to use the nuke.tcl() method, you'll need to evaluate each TCL expression separately. So the two Python calls would look like this:
    Code:
    nuke.tcl("string trimleft [lindex [split [string trim [file tail [value root.name]] .nk] _] 1] v")
    nuke.tcl("string trim [file tail [value root.name]] .nk")
    Note that the top-level (outer-most) square brackets have been removed. This is because the TCL interpreter evaluates each nested set of brackets from the inside out, so if they were left in there, your expression would be evaluated and the return value would be passed to nuke.tcl(), which would then try and run that string in the TCL interpreter again, causing the "Unknown command" error.

    However, there's an easier solution to all of this: Just call the Write node's File knob's ".evaluate()" method to return the fully-substituted path. Then you can use something like os.path to test for existing levels of the tree and create them if necessary.
    Code:
    path = <WriteNode>['file'].evaluate()
    Hope this helps.
    Reply With Quote  

  5. #5  
    Join Date
    May 2010
    Location
    Düsseldorf, Germany
    Posts
    16
    The evaluate()-Method is exactly what I was looking for.
    Thanks a lot!
    Reply With Quote  

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. TCL expression help..
    By sri2128 in forum NUKE from The Foundry
    Replies: 6
    Last Post: May 14th, 2010, 02:45 PM
  2. tcl in menu.py
    By Gabi in forum NUKE from The Foundry
    Replies: 8
    Last Post: November 10th, 2009, 05:15 AM
  3. confused with tcl or python
    By blacknight in forum NUKE from The Foundry
    Replies: 11
    Last Post: April 15th, 2009, 09:51 PM
  4. Replies: 0
    Last Post: October 19th, 2008, 10:15 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts