PDA

View Full Version : A point in the right direction for automating script creation?... Please =)



NEO
September 11th, 2007, 02:09 AM
Morning folks.

I have another little question for you hardcore Nukers. I have rendered out like 20 different particle passes. 20 swarms of flies, each on seperate pass so I have more control in post. Might be bad might be good. But that is not the issue here. =)

Each pass is rendered into a new directory and with a filename that includes the particleShapes name. Like:



/images/particle_01_rndr/particle_01_rndr.<version>.<date>.%04d.iff
/images/particle_02_rndr/particle_02_rndr.<version>.<date>.%04d.iff
/images/particle_03_rndr/particle_03_rndr.<version>.<date>.%04d.iff
...etc


My simple question is how I would automate the creation of a read node for each of those. I know how a similar thing would look in Maya and MEL but afaik Nuke does not have a script editor like that.

But a simple for-loop would do it in Maya. Could someone please point me in the direction on how to automate it in nuke?

Thanks!

nathan
September 11th, 2007, 01:59 PM
Well here is my small stab at it, I must warn you that my example is horrible in that if you were to run this in a directory that has a ton of sub-directories and each of them has a ton of there own sub-directorys that you could cause the end of the world.

Run the command dir_import which will open a file browser, navigate to the folder that contains all your images they can be stored in there own sub-directories or under the folder you navigate to it doesn't matter. The proc will now transverse every directory and sub-directory of the main location you choose in the file dialog box creating a Read node for every single file it finds.

I set a max limit to how many directories deep to transverse because if I didn't and you set the directory to your root C: drive it would load every single file on your hard drive. If you want to change how many directories deep it transverses then change the var passed to proc get_files.

This is a little messy since it doesn't care if a file is a image or not, you could add a check to see if the file is a image or not if you wanted to.

I'm sure Frank will chime in like usual with a better way of doing it so you can always wait and see what he has to say.

Just load this in Nuke and run the command dir_import

proc dir_import {} {
get_files [get_filename "select directory" */] 2 0
}

proc get_files {indir maxdlimit cur} {
if {$cur >= $maxdlimit} {
return
}
foreach infile [filename_list -compress $indir] {
if {![file isdirectory $indir/$infile]} {
if {[file exists $indir/$infile]} {
Read -new file "$indir/$infile"
} else {
set getfile [string range $infile 0 [string last " " $infile]]
set getrange [string range $infile [string last " " $infile] [string length $infile]]
set rangestart [string range $getrange 0 [expr [string last "-" $getrange] - 1 ]]
set rangeend [string range $getrange [expr [string last "-" $getrange] + 1 ] [string length $getrange]]

Read -new file "$indir/$getfile" first $rangestart last $rangeend
}
} else {
get_files "$indir/$infile/" $maxdlimit [expr $cur + 1]
}
}
}

nathan
September 11th, 2007, 02:08 PM
Actually here is a slightly modified method that lets you launch the command telling it how many directories deep to go.

So you would launch the proc as "dir_import YOUR_NUMBER"


proc dir_import {limit} {
get_files [get_filename "select directory" */] $limit 0
}

proc get_files {indir maxdlimit cur} {
if {$cur >= $maxdlimit} {
return
}
foreach infile [filename_list -compress $indir] {
if {![file isdirectory $indir/$infile]} {
if {[file exists $indir/$infile]} {
Read -new file "$indir/$infile"
} else {
set getfile [string range $infile 0 [string last " " $infile]]
set getrange [string range $infile [string last " " $infile] [string length $infile]]
set rangestart [string range $getrange 0 [expr [string last "-" $getrange] - 1 ]]
set rangeend [string range $getrange [expr [string last "-" $getrange] + 1 ] [string length $getrange]]

Read -new file "$indir/$getfile" first $rangestart last $rangeend
}
} else {
get_files "$indir/$infile/" $maxdlimit [expr $cur + 1]
}
}
}

NEO
September 11th, 2007, 11:25 PM
Wow! Thanks nrgy! This is some great stuff! So it seems like coding something for Nuke and Maya ain't that big difference after all. =) You just increased my understanding with 100% or something. =)

rueter
September 11th, 2007, 11:26 PM
you should be able to just drag&drop the directories into Nuke (or copy/paste the file paths into the DAG).
I wrote an enhanced drop.tcl for that sort of thing:
http://www.fxshare.com/nuke/downloads/tcl_scripts/drop-tcl-4273.html

NEO
September 12th, 2007, 01:59 AM
:guitarman :niceone: :love: Thanks! Will try it out asap.


you should be able to just drag&drop the directories into Nuke (or copy/paste the file paths into the DAG).
I wrote an enhanced drop.tcl for that sort of thing:
http://www.fxshare.com/nuke/downloads/tcl_scripts/drop-tcl-4273.html

NEO
September 12th, 2007, 02:26 AM
Started with looking at your code since I'm eager to understand how to script stuffs in Nuke. One idea for the script popped up in my mind.


# create ~/.nuke/drop.preference and put the following lines into it:
# mode {<mode>}
# va_prompt <switch>
# ReadGeoPlus <switch>

Seems like it would be pretty easy (have in mind that this is speculation from my side =)) to create a procedure in the script that creates this file if it doens't exist. And also adds a GUI to that process so one can call drop.tcl from within Nuke and get up a window where all those settings can be set. =) Might be overkill but I'm all about overkill. ;)

NEO
September 12th, 2007, 05:52 AM
Hey. Now I have actually had the time to test it and ran into trouble. I get "compressList: Unknown command".

Seems like it is here:



foreach curClass [array names singleFiles] {
################
#create compressed lists according to user input
if {[lsort $singleFiles($curClass)] != [lsort [compressList $singleFiles($curClass)]]} {
if {$compress == 0} {
#if there are files that could be compressed ask the user
set name [basename [lindex [compressList $singleFiles($curClass)] 0]]
if [catch {panel "Sequence handling" {
{"import subsequent frames" compress e {"as sequence" "as stills" "only folders as sequence" "always prompt"}}
}}] {return}
}
switch $compress {
"as sequence" {
set readyToPaste [compressList $singleFiles($curClass)]
}
"as stills" {
set readyToPaste $singleFiles($curClass)
}
"only folders as sequence" {
set readyToPaste {}
set folderSeq {}
foreach curItem $singleFiles($curClass) {
if {[lsearch $incomingText [file dirname $curItem]] > -1} {
lappend folderSeq $curItem
} else {
lappend readyToPaste $curItem
}
}
set readyToPaste [concat $readyToPaste [compressList $folderSeq]]
}

rueter
September 12th, 2007, 09:43 AM
yes, that's totally doable.
If you want to have a peek at panel UI stuff or are generally interested in learning a bit about the scripting side of Nuke, play with this script here:
http://www.fxshare.com/nuke/downloads/tcl_scripts/PanelUI-4093.html

It'll pop up a panel with various UI elements and lets you plot colours and open the tcl code inside of Nuke to steal bits and pieces from. I use it quite often to get started on panel UIs.

NEO
September 12th, 2007, 10:24 AM
Oh! Cool! Must take a look at that.

Do you have ay ideas why the drop.tcl doesnt' work for me then? I get that compressList: Unknown command".


yes, that's totally doable.
If you want to have a peek at panel UI stuff or are generally interested in learning a bit about the scripting side of Nuke, play with this script here:
http://www.fxshare.com/nuke/downloads/tcl_scripts/PanelUI-4093.html

It'll pop up a panel with various UI elements and lets you plot colours and open the tcl code inside of Nuke to steal bits and pieces from. I use it quite often to get started on panel UIs.

rueter
September 12th, 2007, 11:18 AM
you'll need to have this in yourplugin path as well:
http://www.fxshare.com/nuke/downloads/tcl_scripts/compressList-tcl-4275.html

donat2
September 12th, 2007, 02:24 PM
Hi Frank,

I just downloaded compressList.tcl and drop.tcl and 'installed' those in the plugins folder. It seems to me that your drop.tcl doesn't work in 4.7.

For example, dropping a single jpeg file in the DAG creates a read node with an incorrect path to the file, and there's an expression in the frame range box.

Have you tried this in Nuke 4.7 ?

PS : the file location was in 'C:\Documents and settings\' The path in Nuke's reader is 'c:/Documents' and the expression in the frame range is 'and'. So it seems the script doesn't handle spaces in directory names.

Regards.

Donat
________
Curvy Webcams (http://www.girlcamfriend.com/webcam/curvy/)

rueter
September 12th, 2007, 03:04 PM
right, that's a windows bug where whiys spaces in the filename mess up the output.
meant to fix that for ages but keep forgetting cause I'm working on linux (which works fine).

I'll try to have a look tonight

rueter
September 13th, 2007, 01:44 AM
I've just posted an updated drop.tcl along with compressList2.tcl (which is required for the drop .tcl to work)
http://www.fxshare.com/nuke/downloads/tcl_scripts/4273.html
http://www.fxshare.com/nuke/downloads/tcl_scripts/4275.html

It seems to work with files that have white spaces in them now, hope I didn't break anything else (it's become a bit of a cancer like code and I'm tired). If I did break something please let me know.

cheers,
frank

NEO
September 13th, 2007, 02:17 AM
Great work man! I can confirm that it works on Windows and 4.7v3. At first it crashed but second time I started Nuke it worked fine. And I for sure stressed the hell out of it. =) Draged 10 folders with each 2000 images in them into Nuke and there was no problem what so ever. Sure... It takes a while for it to read in all the filenames but that is just normal. =)

There is one thing though. Don't know if it is a bug or not. It does not take subfolders correctly. I have this structure:

d:\Mosquito\images\

In images there are subfolders named swarm_34_rndr up to swarm_49_rndr.

When I drag the "d:\Mosquito\images" folder into Nuke I get a read node for each subfolder. Not for the images in each subfolder.

If I instead drag the subfolders in directly it works. It is really no biggie but thought I'd let you know. I don't even know if it is supposed to work with subdirs?

Great work rueter! This should be a standard tcl shipped with nuke! =))

nathan
September 13th, 2007, 02:27 AM
Seems like Frank just needs to add another check in his script that sees if a file is actually a file or a directory, I'll take a look at it myself to see if I can find it.

rueter
September 13th, 2007, 01:22 PM
cool, thanks for testing.
It's not meant to support sub folders (yet) cause I wouldn't know how many levels down to search. This could be another preference for the drop.preferences file at some stage. It shouldn't create a Read node for directories, that's a bug.

donat2
September 13th, 2007, 01:31 PM
Thanks Frank for the quick update.

There's another little bug : dropping a non-image file generates a read node. (for example dropping a shortcut creates a read node)

I too would be interested if it could read sequences in subfolders.

Regards.

Donat
________
Pure (http://www.girlcamfriend.com/cam/Pure/)

rueter
September 13th, 2007, 01:37 PM
yeah, I'm aware of that. In fact I have a little bit of code in there that tries to find out if the file is a Nuke readable image but it slowed down the script too much so I took it out. What I can do as a quick hack is make a list of supported image file extensions and check against that.

As for the sub folders, that is now more important because this file is used by the copy paste operation as well. So I guess I should look into that. For now you should be able to drag multiple folders into the DAG but I agree that it would be nice to get the sub folders working (though it's a bit of a bottomless pit)

rueter
September 14th, 2007, 12:22 AM
give it a whirl now:
http://www.fxshare.com/nuke/downloads/tcl_scripts/4273.html

This should fix the problem with subdirectories creating bad Read nodes.
I'm just checking against the list of supported file formats now before creating a read node so every node create *should* be valid.

NEO
September 14th, 2007, 01:51 AM
Works like a charm! No read nodes for subdirs any longer. One interesting note is that the verry first time you use it it's a bit slow. But the following times it just flyyyyyy! =) This is a great plugin.

Suggestions and ideas to addons are:
* In nuke-prefs GUI for it.
* Support for subdirs. Both so the user can set max depth and so it automatically goes until it doesn't find any more subdirs.
* To take it even further... Some kind of folder-name extraction so that is put into the node's label. Of course as a user option.
* Maybe somekind of progress-bar. Guess that's a tricky one though.

Great work rueter! This will for sure be a time and life saver! =))

rueter
September 14th, 2007, 01:05 PM
thanks, glad it's being used.
as for your suggestions, they all make sense and would be cool, I just don't have much time at the moment. I'll remember this thread when I do get around to tweaking it.

As for the UI (which is the easiest one of your suggestions), would you want that as a separate menu entry (i.e. in the Edit menu) and/or pop it up if there is no preference file yet?

Progress bars aren't possible in Nuke tcl but I hope that will change, it's on the wish list.