Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Apr 24, 2018

Nuke scnenemanager and other tools



Hi,

I will present a quick description of our most important inhouse tool for nuke, that I developed :). Maybe some of you will get inspiration to develop something like this. :) It is a gui programmed in python, using pyqt and pyqt designer.
It has two parts, the first part we call "scenemanager", which is a helper gui for quick opening and saving nuke scenes (yes, we call it scenes, instead of scripts, to avoid confusion with python and tcl scripts. I know nuke scene itself actually a tcl script, but anyway :)
In this gui you can quickly select the different parts of the path to the scene, like project, shotgroup (sequence), shot, task, and scene. Basicly with 5-6 clicks you can open any scene from any project.
Very, very handy to avoid spending minutes for browsing the paths in the default nuke scriptopen browser. 

It also has a number features, like: commenting scenes and displaying scene details, these are stored in an sqlite database. Storing used renderlayers for comparing later. Also featuring an elements checker, which is storing all the exr renders from fx or lighting, and comparing that to the versions used in the current comp, and displaying if there is new updated render for a shot. It is a brute-force method, it searches for exr sequences the selected project/shotgroup on disk. We could have used some automated method for storing render information from our deadline rendermanager, but we found that renders could come from outside, like outer renderfarm, or other vendors. So the most reliable method of knowing all the renders that we have, if we search for exrs in our file system.
The other part of this scenemanager we call "nuke butcher" :)  (instead of nuke batcher), which is a standalone batch processor for nuke. It was developed in the need of more compers. With it you can chain different actions together, and do that on many comps at once. For example, the most basic use is to make a general herocomp for the first renders of one shot manually, and with this tool I can distribute that to all the other shots, and it will set the names, frameranges, and the newest arnold render versions automatically per shot, and submit all these comps to deadline to render. But it can do knob modifications on nodes, or any custom python code. Last time I wrote a custom code for that and with that I could export manually animated dof nodes from all the shots, then do a new hero comp render for all the shots (which means dof nodes are all the same in all shots), and then import the already exported dof nodes and place them back in comp. So it can save a loooooot of manual labor time. 


Of course it was a big challange to develop it, and it still needs some update, like saving action presets, but it is still very functional, and working nicely, and it is the software that I'm the most proud of! At least until this point :)
Hope this was interesting for some of you and I would be very grateful if you could share also some tools or tips what you are using at your place. 
Of course the software itself is not shareable, and not for sale, it is and inhouse development, used in Puppetworks. 



Dec 4, 2014

Radio buttons in nuke

Hi, I always wanted to have the option of creating radiobuttons in the nuke gui, for gizmos. Its easier to use than dropdown menus, because they  need only on click to select the value. Today I checked the documentation, and I found an option. The radiobuttons are a different widget version of the enumeration knob. You can't add this knob like others via the "manage user knobs" panel, but you can with the help of a little python. For example like this:

n = nuke.toNode('Group1')
r = nuke.Radio_Knob('options', 'Option channels', ('red', 'green', 'blue', 'alpha'))
n.addKnob(r)

First argument is the name of the knob, second is the label, and the third is a tuple, with the radiobuttons' name in it.
Hope this was useful, cheers.

Dec 14, 2012

Nuke tcl tips

I have a lot of tcl expressions, and other nuke snippets written down, because always forget these. I decided to share some. In general I can say tcl in nuke is very flexible and quick for simple tasks.
For expression testing the expression I use the text node, easier than always getting into the specific knob, and click edit expression.
So first come the tcls in knob expressions, with examples:

Getting a knob's value of a specific node:
[value Read1.first]

Getting a knob's value of current node:
[value this.size]

Setting a knob's value of a specific node:
[knob Read1.first 10]

First frame of current read/write:
[value this.first_frame]

Setting a general tcl variable :
[set variablename value]
for example (tsize is the variable name):
[set tsize 15]

Using that variable later (notice the "$") for setting a knob value:
[knob this.size $tsize]

Name of the input node:
[value this.input.name]

Expressions in a group going outside (to parentgroup or root). This example gives the name of the node before the group:
[value this.parent.input.name]


String substitute and compare:

Replace string in current node file knob with regex (string "proj" to "projects" in all occurences):
[regsub -all "proj" [value [node this].file] "projects"]

String map (replace multiple stringpairs):
[string map {"aa" "xx" "bb" "yy"} "aaffffaabb" ] this returns: xxffffxxyy

Compare values:
[string equal [value Text1.message] "bla"]

Regexp matching:
[regexp -inline "_v\[0-9]{3}" [value Read2.file]]


Path manipulations:

Filepath without extension:
[file rootname [value [topnode].file]]


Filename only:
[basename [value [topnode].file ]]


Filename only without extension:
[basename[file rootname [value [topnode].file]]]


This one splits the uppermost node's (probably a readnode) filepath by slashes and then joins together until a certain point, giving a directory few levels upper than the currrent path). "File split" does the splitting, making a list of directory names, "lrange ... 0 7 "selects a range from the list, from the beginning to the 7. item, and "join ... / " joins by forward slashes (which I use always in paths):

[join [lrange [file split [value [topnode].file]] 0 7] /]


This one can be used in a writenode fileknob to quickly convert the topmost readnode's path to another format(tga). Similar to the previous, but splits path by "." (different than previous file split), and gets the range from the beginning to 2 before the end, this way cutting off the extension and the counter (framecounter must have preceeded by a "." ) :

[join [lrange [split [value [topnode].file] .] 0 end-2] .].%04d.tga
(I use similar to make the comps writenode have the output path automatically getting from path of the nukescene )

Other useful:

Get the value the channel of a node, at a specific pixelcoordinates (e.g.: 10,10):
[sample [node input] red 10 10]

Setting a variable, without returning that (useful in a textnode):
[set seq [value Read1.file]; return]


Example of "IF" in an expression:
[if {condition} {expr1} else {expr2}]
for example:
[if {[value Switch1.which]==1} {return "aaa"} {return "bbb"}]

to be continued...


Sep 6, 2012

Applauncher - setting environment for apps

Hi, sorry for not posting for a long time. But this one is really interesting! Earlier this year we had a job to recreate a character that we used in Eset commercial. It would have been an easy thing, because we had the asset, but the arnold renderer, and shaders are changed a lot since last summer. And the config wasn't backed up properly with the project. This gave the idea that we should re-think our current application-environment-management system (what an expresssion:)
Until that point, for maya we had a lot of scripts, icons, shelves on the fileserver, that accessible for every maya; and with plugins/modules on the local machine (if it would be also on fileserver, the plugins we develop can't be updated if someone is using maya loaded that plugin.) For starting maya, artists were using a custom batchfile that copies needed plugins to local, sets some environment variables, and launches. But almost everything was hard-coded to maya.env and the batchfile.
It worked to point, but wasn't effective nor elegant. So we came up with the idea of Applauncher.
Here I give a little insight about this software, maybe useful for some of you thinking about similar solution.
It is a gui for starting maya, and nuke with the proper environment. In short: in the gui the artist chooses the project (show) and the context (lighting, dynamics, animation etc.) he/she wants to work. Then applauncher copies the needed scripts, plugins, modules etc., sets the environments and launches the application.
What is needed for the given context is stored on the network in an xml file, that is easy to edit and read. It's created by sup. before the show starts, but of course can be modified later. In the xml we define what addontype (scipts, modules etc), what addon with what version is in that environment config.
So when user chose context, and clicked on launch, the needed content (plugins, scripts etc) are copied to local disk, or if that content is already there, the copy process can be skipped. After copy, depending on addontypes the proper environment variables are set.
For maya we use following addontypes: modules, scripts, shelves, icons, additional envvars. All plugins are stored in modules: that is the most flexible type of addon.
For nuke we use much more type of addons, that are differently set for the software: gizmos, scripts, plugins, icons, luts, modules, ofx, prefs etc.
Important that on the server-side the addons are versioned, but on local they are not. Always the actual version of the addon (defined in xml) is copied.
We don't make separate addon for each gizmo, or script, it would be hard to version and manage them. Rather we chose to group them along some common attribute. For example my script package for maya is 1 addon. The other developer's scripts are another addon.

Example structure in xml, for maya:

addonGroup: modules
addon:commonscriptpack
version: 1.0
addon: userscriptpack1
version: 1.1
addon: userscriptpack2
version: 1.5
addon: yeti
version: 1.0
addonGroup: shelves
addon: lighting
version: 1.3
...
Now every artist at us uses this little gui without problems. The advantages: 1. we can restore any working environment at any time 2. much faster app. loads. 3. easier distribution of tools. I even integrated it with deadline, it was a must to run renders with same environment as the artists.
I hope this writing was understandable, and useful. If needed, I can continue telling more about this, because I think it has really nice logic, and features, that now is proven to be very useful.
Further reading on this theme in these topics: 1 2 3



Aug 30, 2010

Deadline - nuke post job script

We wanted to have an automatic process with deadline, to convert all the 3d renders to exrs with proper compression and autocrop (datawindow) option enabled. Currently I implemented this on linux, and I had to make a little hack to run nuke from shell. I think it's much easier on windows (no permission problems etc.) Usage:
So the main file is a pythonfile, a deadline post job script, the path of this has to be placed in deadline monitor, in the job properties panel. The machine that rendered the last task will "render" this extra task. The file gets data from deadline, like output path, frame range etc. Then it's executing a nuke render, from command line, but the renderable file is not a nuke script, but another python file. It could be a nuke scene, with a read and write node, but I think it's nicer to generate the nodes on the fly, and this way no problem with script paths etc.
So we have 2 python files at this point: a "JobNuke2exr.py" which should be placed in deadline, and "glt_deadlinepostjob.py" which should be reachable by nuke and deadline (that's why I inserted a line with sys.path.append in the first python file, it should be edited). To make it more complex, I had to make an .sh file, (like a .bat on windows) that launches nuke from terminal, with arguments, because the specific deadline command (SpawnProcess) couldn't make this. Of course this .sh file needs also be edited, because it contains the path to nuke executable.
So the first .py calls this .sh, that fires nuke, that renders the other .py! Easy, no? :)
A little thing with the process that has to be solved: currently nuke rendering checkerboards, and not skipping missing frames.
Here you can download the files
I'm sure this whole postprocess can be achieved much easier, but at this point this is working here. Comments, tips are welcome.
Gabor

Aug 7, 2010

Multiple autosave in nuke

So we had a little dataloss yesterday, some of our nuke files went 0B in size. Checked the autosaves... none existing! What happened (other than file system corrruption or what)? We are working on linux, and the NUKE_TEMP_DIR environment variable was properly set in init.py. But, nuke was started as a simple user, and that dir can be written only by root. At least this is my idea. That's about it, but I started to think where and how to place autosaves properly. We now having them in /home/user/Nuke/autosaves folder. Another question is how to preserve the autosave files? Because nuke deletes them as soon as the scene is saved, but we need them to stay, for these occasional dataloss events.
I found a tip in the mailing list, to include the current date, time in the autosaved filename:

/autosaves/[date %y]-[date %m]-[date %d]_[date %H]-[date %M]_[file tail [value root.name]]
But this is too long, and can get infinite number of autosaves.

So another tip: include only the current minute, so it starts again in the next hour, maximum of 60 file (for 1 scenefile, if you save a new version there can be another 60!)
[file rootname [value root.name]]-[date %M].nk.autosave
it gives path like (when for example the current time in minute is 15):
w:/Projects/Test/AutosaveTest/AutosaveTest_v001-15.nk
But that is still to much files.

How can it be reduced? I could include a modulo (%) operator to limit the number of minutes, like %6 gives only 0-5. It's great, but think. When minute is 01, it writes in the fileneme 01. When 02, 02 and so on, and when 06, it starts from the beginning. It would be better to have 1 autosave filename in the first 5 minutes (continuously overwritten), then another in the next 5 minutes, and so on. So in half an hour you still would have the first file, and that gives a good chance to go back if something went wrong. This can be achieved, by an expression like this:

[file rootname [value root.name]]-[expr int ([expr [date %M]%30]/5)].nk.autosave

Let's look at this from closer! The first part (before the "-") is simply gives back the file path, but without extension, so we can put anything after this. The second part can be understood from inside the date part: [date %M] is the minute of current time (That's going 0-59). Outside there is an expr(ession) command for the modulo (%30) operation, that gives the remaining of current minute and 30, with this we modified the range to 0-29. Then comes "/5", notice the brackets, so range is 0-5.8. Then the "expr int" takes only the integer of this. The final range is 0-5 integer only. This is pasted after the filename.
Now this expression makes a "filename-0" file when current minute is between 0-4, then "filename-1" when minutes 5-9... and at 30 it starts from the beginning, overwriting the "filename-0". There can be maximum of 6 files, for 1 version. But remember if you save the script (ctrl-s) the last autosave will be deleted!
I hope this will be useful for someone. Modify as you need.