Store selected nodes using python

004

Audun Ase
-
January 8, 2021
scripts

Houdini has a lot of moving parts. And sometimes it's hard to keep control over the stuff you have done. I've time and time again had the need to re-use parts of a setup that I liked in older hipfiles. I would then have to dig around to find the correct file that had a certain workflow that I'd like to use again. This is why I thought it would be a good idea to create a script that can grab any nodes you select, and store them somewhere for later use. Then whenever you need it again simply click a button and grab it. I've come to use this script every single day as it keeps me from having to recreate essential setups.

Table of Contents

  • The Script
  • Create a shelf
  • Save Selected Nodes
  • Read stored .uti files
  • Quick walkthrough
  • Please note
  • Download shelftools
Let's get scripting

The Script

I've prepared two python snippets that are used in two parts.

1. Select the nodes you want to store, and save them to disk.

2. Read them back in.

Pretty simple! We'll be creating a handy shelf tool to store the script in. Keep in mind that this will create files with a .uti extension. Feel free to change this, as It really don't matter what it's called. Lets setup a shelf set!

Create shelf tools

Create a new shelf tool and call it whatever you like. I've called mine "Store Selected" and "Read Stored". Simply copy the following scripts into their respected shelf. Remember to switch to Python.

Save selected nodes

Here's the code used to store nodes.

<p> CODE: https://gist.github.com/Affexno/b9530a0d478af80cca33d782c525929f.js</p>

Keep in mind that you will have to change the preferred directory. Currently it's pointing at core = ('/tmp/hdump/') . This was originally created for a Linux system, but should work for any system with Houdini.

Here's an example of what I have written on my personal computer

<p> CODE: https://gist.github.com/Affexno/168fde736448c377c65d40d6d566aa7b.js</p>

As you can see, I've changed it to grab my username, and store it in the documents area in a folder called "pydump". This is just one of many ways of setting your location. If you are having issues setting your folder, feel free to let me know in the comments and I can try and help out. Either way, the goal is to define "core" as your path.

Read stored .uti files

Here's the code used to read nodes.

<p> CODE: https://gist.github.com/Affexno/a0ddaed92766bf580038aee74d30543f.js</p>

If you changed location from the previous snipped I suggest doing so here too, as it will make Houdini open the correct location by default, saving loads of time when looking for the files again.

Quick walkthrough

Here's a quick overview of how the tools work. If you've downloaded the shelftool from the bottom of the page, it will look something like this once installed.

Let's assume you've never exported something and this is the very first time you write something out.

  1. Select the nodes you want to export.

  1. Click the Write .uti icon. A window will appear asking you for a name. Type a name you want your file to be stored as and click OK.

Now your file has been saved in the location you specified inside the script. It's now what I call a .uti file, or "utility" file. The nodes you selected will now be available for you to import at a later time.

- Over to the import feature.

  1. Click the Read .uti icon. A window will appear which will allow you to select the files you have stored. Select the file, and hit accept.

The nodes will automatically appear the same way they were stored. In my example they automatically connect to IN_GEOM and WALL because they remember the way they were connected.

It's basically a ctrl + c operation.

That's it! You can now store parts of setups you use all the time and want to use at a later time.

Please note:

If you included any hda's in your export, make sure the same hda's are installed in your current Houdini session you wish to import into. If an asset don't exist, the import will likely fail and give an error.

Also, the .uti file will not remember what context the file was written into, and will likely fail if this is wrong. You could specify this in the name, or remember where it belongs yourself. Maybe I'll add a feature like this to the code in the future.

Download shelftools

If you want to skip the work of setting up a shelf tool feel free to download the shelf bellow.

All you have to do is place the shelf files in "C:\Users\YOURUSERNAME\Documents\houdini18.0\toolbar", and restart/start Houdini.

Thank you!

If you are having any issues or suggestions I'd love to hear it! Let me know in the comments bellow.

Audun out...

Associated Files

HIP FILES
No associated hip files found
ASSETS
An old fashioned disk

Store Selected Nodes

Download

Comments