app/dat principle
In SOPs, I often use the app/dat pair of nodes. This pair is made just by naming the nodes properly, using the naming convention. For example:
Materials:
- "matapp_earth" will be Material SOP, it applies the materials to the earth geo
- "matdat_earth" will be Material Network, it contains material builders and VOPs
CHOPnets:
- "chopapp_lag" will be Channel SOP, it applies the CHOP data
- "chopdat_lag" will be Chop Network, it creates the CHOP data
Reference system:
- "refapp_circle" will be Circle SOP, it reads (usually animated) data from the detail attribute of the peer node:
- "refdat_circle" will be Attribute Wrangle, it creates animated data (Arc Angles)
Preview (draft) system:
- "preapp_resample" will be Resample SOP, it reads data from the following peer node:
- "predat_resample" will be Attribute Wrangle, it has the checkbox "Preview". If it is on, then Length is 0.5 if off, then 0.1
app/dat layout
I have my own Network Editor Layout feature that also aligns the DAT node to its APP node.
node_data (node_app, prefix)
Finds a "peer" node that belongs to a pair of APP / DAT.
snippet_preview (parms)
Creates a "preview" snippet to selected parameters.
snippet_reference (parms)
Creates a "reference" snippet to selected parameters.
parm_ref_appdat (node_app, node_dat, parm_name):
Sets the parameter to the APP node so that it reads the detail of the attribute from the appropriate DAT node.
parmmenu_pre (node_app, parms):
Finds DAT peer node and reads kwargs (right button click). Generates a "preview" snippet and puts it in a peer node.
parmmenu_ref (node_app, parms):
Finds DAT peer node and reads kwargs (right button click). Generates a "reference" snippet and puts it in a peer node.
source code
the following code is maintained also on my github
thank you, great people, I couldn't do this without you.
import re import hou def node_data_peer (node_app, prefix) : node_con = node_app.parent() path_con = node_con.path() name_app = node_app.name() name_app_done = re.findall('.*app_(.*)',name_app) if not name_app_done : name_app = prefix + "app_" + name_app node_app.setName(name_app) name_dat = name_app.replace("app_", "dat_") path_dat = path_con + "/" + name_dat node_dat = hou.node(path_dat) if node_dat : existed = 1 else : existed = 0 node_dat = node_con.createNode('attribwrangle',name_dat) posx = node_app.position()[0] + 3 posy = node_app.position()[1] + 0 node_dat.setPosition( [posx,posy] ) node_dat.parm("class").set("detail") return node_dat def node_data_parent (node_app, parmname) : node_dop = node_app.parent() node_con = node_dop.parent() path_con = node_con.path() name_app = node_app.name() name_dat = name_app + "_" + parmname path_dat = path_con + "/" + name_dat node_dat = hou.node(path_dat) if node_dat : existed = 1 else : existed = 0 node_dat = node_con.createNode('attribwrangle',name_dat) posx = node_dop.position()[0] + 3 posy = node_dop.position()[1] + 0 node_dat.setPosition( [posx,posy] ) node_dat.parm("class").set("detail") node_dat.setUserData("nodeshape", "circle") node_dat.setColor(hou.Color(0.0, 0.0, 0.0)) node_dat.setComment("`") return node_dat def snippet_preview (parms) : snippet = 'n' snippet += 'qqincn' snippet += '// delete one of those:n' snippet += 'qqpreview_intn' snippet += 'qqpreview_float n' snippet += 'n' for parm in parms : snippet += 'fi@' + parm.name() + 'n' return snippet def snippet_reference (parms) : snippet = 'n' for parm in parms : snippet += 'qq@f.' + parm.name() + 'n' return snippet def parm_ref_appdat (node_app, node_dat, parm_name) : relpath = str(node_app.relativePathTo(node_dat)) expression = 'detail("' + relpath + '","' + parm_name + '",0)' parm = node_app.parm(parm_name) parm.setExpression(expression) def parmmenu_pre (node_app, parms) : prefix = 'PRE' node_dat = node_data_peer(node_app,prefix) snip_parm = node_dat.parm('snippet') snippet = snip_parm.unexpandedString() snippet += snippet_preview (parms) snip_parm.set(snippet) for parm in parms : parm_ref_appdat (node_app, node_dat, parm.name()) def parmmenu_ref_peer (node_app, parms) : prefix = 'REF' node_dat = node_data_peer(node_app,prefix) snip_parm = node_dat.parm('snippet') snippet = snip_parm.unexpandedString() snippet += snippet_reference (parms) snip_parm.set(snippet) for parm in parms : parm_ref_appdat (node_app, node_dat, parm.name()) def parmmenu_ref_parent (node_app, parms) : node_dat = node_data_parent(node_app,parms[0].name()) snip_parm = node_dat.parm('snippet') snippet = snip_parm.unexpandedString() snippet += snippet_reference (parms) snip_parm.set(snippet) for parm in parms : parm_ref_appdat (node_app, node_dat, parm.name())