Thursday, March 28, 2013

Splitting out a file name in an image sequence from a directory path using tcl in Nuke

I'm writing this down, mostly so I won't have to dig around different nuke comps the next time I need it.  Using tcl to write little scripts in Nuke is very helpful, but it's a bit of an old language (just a few years younger than Perl), so it's got an interesting nomenclature.

Anyways I use this bit of tcl in my nuke text nodes to get the name of an image sequence:
 
[split [lindex [split [lindex [split [knob [topnode].file] "/"] 10] "."] 0] "_"]

It first splits the whole path (which in this case has 10 tokens) using a "/"
The last token is returned and split again based on "."
And finally it splits out the last token if there's any underscores

so a path like this:
/job/thingny/dev/sandbox/sandbox_iguerrer/work/iguerrer/maya/images/skinTestSmooth_backLeft.####.iff

ends up being displayed as this:
skinTestSmooth backLeft

This assumes you have a read node as the top most node in the tree with the text node in the flow.

I'd like to figure (using tcl --- python is a bit easier for me when it comes to text manipulation) how to get the total number of tokens in the first directory split where I'm using "/", and then feed the number to the rest of the expression.

Further explorations!


addenum --  check out this web site for lots of nuke tcl tips:
http://thoughtvfx.blogspot.com/2012/12/nuke-tcl-tips.html

1 comment:

  1. So there's lots of ways to do this as I'm learning.
    I found these tidbits on nukepedia:

    This give you the file name sans directory:
    [lindex [split [lindex [split [knob [topnode].file] .] 0] /] end]

    Root dir:
    [file dirname [knob [topnode].file]]

    File name:
    [file tail [knob [topnode].file]]

    File extension:
    [file extension [knob [topnode].file]]

    fun fun fun

    ReplyDelete