Houdini is a wonderful software but when starting probably one of its biggest difficulty is to understand graph flow and single nodes semantic, developing a simple script which automatically populates and display as the node comment the headline from the official documentation may help beginners learn faster nodes and projects.
Create a python script with your favorite editor, name it OnCreated.py and save into HOUDINI /scripts folder
Here is the script (remember, python requests to use TABS to be syntactically correct, so where you see space you have to use one or more tab/s):
import hou import os import zipfile ZIPFOLDER = os.environ['HFS']+"/houdini/help/nodes.zip".replace("/",os.sep) ARCHIVE = zipfile.ZipFile(ZIPFOLDER, 'r') def getHeader(path): path = path.replace("operator:","").replace("object/", "obj/").split("?") path = path.lower() nodeHelpContent = ARCHIVE.read(path+".txt") splitted = nodeHelpContent.split("\"\"\"") return splitted if len(splitted)>1 else "Not found" def main(kwargs): node = kwargs["node"] if len(node.comment())==0 : description = getHeader(node.type().defaultHelpUrl()) node.setComment(description) node.setGenericFlag(hou.nodeFlag.DisplayComment,True) main(kwargs)
If you created the file inside the /scripts folder with Houdini already opened, better to close and restart it to load properly the script, after this you are free to modify the script and see its results in realtime (every time you create a new node).
Code is quite simple:
- main() is called when a new node is created
- kwargs contains the node generated
- if node comment is empty (this simple check is to avoid overwriting comments generated by other plugins or scripts) we get the node description calling getHeader() method
- getHeader() simply read nodes.zip file, an archive which contains the whole documentation file placed into houdini/help sub-folder, and extract the headline which is delimitated by three " characters. .split("?") is required to remove ?version=x get parameter. ZIPFOLDER is the path of the zip file and should work in any OS because it uses slash or backslash depending on correct configuration.
- A ternary operator return the content or not found
- when getHeader() returns node headline we set it as a comment and enable display of the comment.