I have made another concerted effort to learn Python this year. I hadn’t coded for a while, so I needed to pick an IDE to help me get going. I decided to give Atom a go as it is free, actively being developed and seems to have all the features I would possibly need.
I’m no power user, and I haven’t tried many other IDEs, so this isn’t a review of Atom, but I will say, so far I’m very happy with it.
One of the features of Atom are ‘packages’. These are extensions that anyone can write to extend the functionality of Atom. I was getting tired of copying and pasting code between Atom and the Nuke script editor to test my scripts, so I was interested when someone pointed me in the direction of the foundry-nuke package for Atom written by Toke Jepsen.
This package allows you to run the code that you’ve written in Atom directly in Nuke with just a keyboard shortcut, no copy and pasting. But it wasn’t quite as I expected, so here are a few tips to get it working.
Installation
To get it working you need to install the package to Atom, which you can do inside Atom in the Preferences > Packages. Click Install at the bottom of the sidebar and search for foundry-nuke. Then click install.
Once you have installed the extension, you also need to install the atom_server.py Python script into your Nuke setup. You can get the script from the package webpage, or the Github repository.
I copied and pasted the code into a new file and had some indentation issues, but once I sorted that out, saved atom_server.py
to my Python location, and added import atom_server
to my menu.py
, it worked.
Gotchas
I’ve only used this extension for a few days, but there were a couple of gotchas that I discovered.
Firstly, the keyboard shortcut. The keyboard shortcut to run the code you are working on directly in Nuke is ctrl+alt+r. I’m using a Mac so I assumed that it would be Command (⌘) instead of CTRL, as most keyboard shortcuts are translated to MacOS, but in this case, it really is CTRL (⌃). Alt is Option (⌥) so it is ⌃+⌥+r.
Secondly, and a much bigger gotcha, is how the code is run. I assumed that the code would be run as if I had copied and pasted the code into the Nuke script editor and run it from there. If I’m testing a function I will often load the function from the script editor, and then call it separately. This way I can call it over and over, to test different situations.
But the way this extension works is different. Whatever it runs isn’t kept in the Nuke session, so you can’t load a function from Atom and then call it from the Nuke script editor because Nuke doesn’t remember whatever Atom just ran. To actually define a function, and then run it, you have to call the function at the end of your script in Atom like this:
def myFunction():
nuke.message('Hello World')
myFunction()
I would usually do that as two steps in the Nuke script editor, so that I could just run myFunction()
again and again.
It also means you might have to remember to remove the call to your function from your code once you are done testing it, as you might not want to include it in your final .py file.
I’m not sure why it works this way, but once I figured it out, it was nice to be able to write code directly in Atom and run it straight in Nuke. It saved copying and pasting, and also stopped me from fixing code in the Nuke script editor and forgetting to copy it back to my .py file.
I hope you find it useful too.
Hi!
Thank you for taking your time and explaining this!
You said you hade some indentation issues. I fixed those as well, I think, but I can’t open nuke afterwards. All I get is “error interpreting this plugin”.
I get this error on both 12.2 and 13.0.
Do you know what ells could be wrong?
Best regards
Christoffer
Hi Christoffer,
I haven’t actually used this extension for a while. I think it stopped working when Nuke 13 jumped to Python 3 and I got out of the habit of using it. I haven’t checked for an update.
That ‘error interpreting plug-in’ message usually just means there is a syntax issue somewhere in your python scripts that you are loading on import. If you launch Nuke for a terminal, rather than double clicking the icon, it will give you more information about what the problem is. It will at least tell you what line of code is causing problem.
Sorry I can’t be any more help.