ūüíĶ Website Ad Revenue Calculator

HPaste - simple exchange of nodes snippets for Houdini

What is HPaste

HPaste is a small and useful utility that makes an exchange of node snippets really easy and fast. You can send them directly through any text messaging application

when you add the plugin to your project; a new shelf HPaste will become available.

It has some buttons, but the most useful are HCopyWeb and HPasteWeb.

When you select some nodes in the node editor and press HCopyWeb - a link appears in your system clipboard, and you can paste it into any messenger as text. It looks kinda like this:

 "8BIQqJvciteWgQNx@WePaste"

Then anyone who sees this link can select it, copy it to his system clipboard and press the HPasteWeb button in Houdini, creating the same node structure that the sender chose, with all animations, channels, expressions and connections! Note that received nodes will be pasted into the active Node Editor window.

If the current Node Editor window shows a different context from what the sender sent (for ex., OBJ, when the sender copied SOP nodes) - the receiver will be prompted about the correct context, and no nodes will be pasted.

The plugin and installation manual will be found on the GitHub page: https://github.com/pedohorse/hpaste.

You can use it for free.

How does it work

  • The core of nodes serialization is based on a hou functions saveItemsToFile and loadItemsFromFile, that became available in Houdini16, but has a fallback to saveChildrenToFile and loadChildrenFromFile functions for previous versions of Houdini that do quite the same job in general.

  • Generated serialized code is then compressed with bzip and converted into URL safe base64 to be safely stored in any text-based storage, such as URL, or ASCII text message

  • Code is passed to a web plugin that returns a short URL that he can decrypt back into the code and that you can paste into a messenger to share with someone

The HCopy and HPaste buttons work in the same way as the HCopyWeb and HPasteWeb buttons, but with processed code instead of short URLs.

You can work with this code directly without using web versions of buttons if you wish. Still, the code tends to be pretty big and clumsy, more extensive than most messengers' maximum message size, making it very hard to exchange this kind of raw snippets.

So that's where web plugins come in.

Web Plugins

Folder hpastewebplugins is scanned for modules that contain classes derived from WebClipBoardBase; all classes are loaded and stored for use.

The main abstract methods there are webPackData and webUnpackData. webPackData one should be able to receive an ASCII string and return a short URL that identifies it, and that can be passed to webUnpackData that will convert it to the exact same data that was passed to the first method. This means

 webUnpackData(webPackData(string))==string (1)

The HPaste picks one of the plugins (based generally on network speed), cuts it up based on the value of the maxStringLength method, that the plugin must also define, and cuts the compressed serialized ASCII nodes code into pieces that fit into maxStringLength value, feeds each part to webPackData (in general parts can be of different size and each component can be going to the separate plugin) that returns web id that is appended with @pluginName string concatenated with all other parts with a # symbol, so in general, the final link would look like:

 randomid1@plugin1#randomid2@plugin2#randomid3@plugin3

The receiving part of the plugin does the same in reverse: splits that URL above by # into parts, detects each part's plugin by @plugin, and feeds random id to the corresponding plugin's webUnpackData method, then concatenates all the parts, debase64 it, decompresses it and feeds into Houdini.

It is entirely up to the developer what exactly methods webPackData and webUnpackData do.

As long as condition (1) is met, the result of webPackData is a string that consists only of URL-safe ASCII symbols, WITHOUT @ and # symbols.

All current plugins use some online clipboard now to save the long code, so beware - theoretically, your pasted code is public, and its lifetime is up to the hosting site.

Custom plugin

To create your plugin you have to implement four methods:

  • webPackData(str) -> str

  • webUnpackData(str) -> str¬†

  • maxStringLength() -> int¬†

  • speedClass() -> int

The first three have been described before.

The last one should return an integer of range 0-9, representing a priority of use.

HPaste will sort plugins according to this priority level and randomly choose a plugin from the highest priority list.

If all of them fail, HPaste will fall back to the next priority, and so on, until no plugins are left.

Inherit WebClipBoardBase class and implement those methods. Put that py file into hpastewebplugins folder.

Your new plugin will be added to the list on Houdini restart or the hpaste.hpastewebplugins.rescanPlugins method called (which you can call manually when testing/debugging your plugin).

In the examples folder, you will find an example plugin that saves serialized code to a local network drive that can be used inside the company network and inaccessible from outside even if someone has an id of the snippet.

Original article: https://cgallin.blogspot.com/2017/09/hpaste.html

GitHub repository: https://github.com/pedohorse/hpaste