Skip to content

Instantly share code, notes, and snippets.

@duartevictorino
Created November 28, 2018 07:47
Show Gist options
  • Save duartevictorino/b8d46e6ceb9fede904a438f1544138f1 to your computer and use it in GitHub Desktop.
Save duartevictorino/b8d46e6ceb9fede904a438f1544138f1 to your computer and use it in GitHub Desktop.
import sys
import toolutils
outputitem = None
inputindex = -1
inputitem = None
outputindex = -1
num_args = 1
h_extra_args = ''
pane = toolutils.activePane(kwargs)
if not isinstance(pane, hou.NetworkEditor):
pane = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
if pane is None:
hou.ui.displayMessage(
'Cannot create node: cannot find any network pane')
sys.exit(0)
else: # We're creating this tool from the TAB menu inside a network editor
pane_node = pane.pwd()
if kwargs.has_key("outputnodename") and kwargs.has_key("inputindex"):
outputitem = pane_node.item(kwargs["outputnodename"])
inputindex = kwargs["inputindex"]
h_extra_args += 'set arg4 = "' + kwargs["outputnodename"] + '"\n'
h_extra_args += 'set arg5 = "' + str(inputindex) + '"\n'
num_args = 6
if kwargs.has_key("inputnodename") and kwargs.has_key("outputindex"):
inputitem = pane_node.item(kwargs["inputnodename"])
outputindex = kwargs["outputindex"]
h_extra_args += 'set arg6 = "' + kwargs["inputnodename"] + '"\n'
h_extra_args += 'set arg9 = "' + str(outputindex) + '"\n'
num_args = 9
if kwargs.has_key("autoplace"):
autoplace = kwargs["autoplace"]
else:
autoplace = False
# If shift-clicked we want to auto append to the current
# node
if kwargs.has_key("shiftclick") and kwargs["shiftclick"]:
if inputitem is None:
inputitem = pane.currentNode()
outputindex = 0
if kwargs.has_key("nodepositionx") and kwargs.has_key("nodepositiony"):
try:
pos = [ float( kwargs["nodepositionx"] ),
float( kwargs["nodepositiony"] )]
except:
pos = None
else:
pos = None
if not autoplace and not pane.listMode():
if pos is not None:
pass
elif outputitem is None:
pos = pane.selectPosition(inputitem, outputindex, None, -1)
else:
pos = pane.selectPosition(inputitem, outputindex,
outputitem, inputindex)
if pos is not None:
if kwargs.has_key("node_bbox"):
size = kwargs["node_bbox"]
pos[0] -= size[0] / 2
pos[1] -= size[1] / 2
else:
pos[0] -= 0.573625
pos[1] -= 0.220625
h_extra_args += 'set arg2 = "' + str(pos[0]) + '"\n'
h_extra_args += 'set arg3 = "' + str(pos[1]) + '"\n'
h_extra_args += 'set argc = "' + str(num_args) + '"\n'
pane_node = pane.pwd()
child_type = pane_node.childTypeCategory().nodeTypes()
if not child_type.has_key('subnet'):
hou.ui.displayMessage(
'Cannot create node: incompatible pane network type')
sys.exit(0)
# First clear the node selection
pane_node.setSelected(False, True)
h_path = pane_node.path()
h_preamble = 'set arg1 = "' + h_path + '"\n'
h_cmd = r'''
if ($argc < 2 || "$arg2" == "") then
set arg2 = 0
endif
if ($argc < 3 || "$arg3" == "") then
set arg3 = 0
endif
# Automatically generated script
# $arg1 - the path to add this node
# $arg2 - x position of the tile
# $arg3 - y position of the tile
# $arg4 - input node to wire to
# $arg5 - which input to wire to
# $arg6 - output node to wire to
# $arg7 - the type of this node
# $arg8 - the node is an indirect input
# $arg9 - index of output from $arg6
\set noalias = 1
set saved_path = `execute("oppwf")`
opcf $arg1
# Node $_obj_geo1_dvVelocityGenerator (Sop/subnet)
set _obj_geo1_dvVelocityGenerator = `run("opadd -e -n -v subnet dvVelocityGenerator")`
oplocate -x `$arg2 + 0` -y `$arg3 + 0` $_obj_geo1_dvVelocityGenerator
opset -d on -r on -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off $_obj_geo1_dvVelocityGenerator
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator
opcf $_obj_geo1_dvVelocityGenerator
# Node $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator (Sop/attribwrangle)
set _obj_geo1_dvVelocityGenerator_dvVelocityGenerator = `run("opadd -e -n -v attribwrangle dvVelocityGenerator")`
oplocate -x `$arg2 + 1.9395700000000007` -y `$arg3 + 1.7518349999999996` $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opspareds ' group { name "folder2" label "Velocity Generator Parms" groupsimple { name "folder3" label "Control Noise" grouptag { "group_type" "simple" } parm { name "cd_viz" label "Visualize Noise" type toggle default { "1" } } parm { name "noise_frequency" label "Noise Frequency" type float default { "1" } range { 0 1 } } parm { name "noise_seed" label "Noise Seed" type float default { "1" } range { 0 1000 } } parm { name "in_noise_min_val" label "In Noise Min Val" type float default { "0" } range { 0 1 } } parm { name "in_noise_max_val" label "In Noise Max Val" type float default { "1" } range { 0 1 } } parm { name "out_noise_min_val" label "Out Noise Min Val" type float default { "0" } range { 0 1 } } parm { name "out_noise_max_val" label "Out Noise Max Val" type float default { "1" } range { 0 1 } } parm { name "power" label "Power" type float default { "2" } range { 0 1 } } parm { name "rand_min" label "Rand Min" type float default { "0.25" } range { 0 1 } } parm { name "rand_max" label "Rand Max" type float default { "0.75" } range { 0 1 } } parm { name "velocity_multiplier" label "Velocity Multiplier" type float default { "1" } range { 0 1 } } } groupsimple { name "folder1" label "Custom Direction" grouptag { "group_type" "simple" } parm { name "label_string" label "Custom Direction Note" type string nolabel default { "" } parmtag { "editor" "0" } parmtag { "export_disable" "1" } } parm { name "customdir" label "Custom Direction" type toggle default { "0" } } parm { name "custom_direction" label "Custom Direction" type vector size 3 default { "0" "1" "0" } hidewhen "{ customdir == 0 }" range { 0 1 } } } } group { name "folder2_1" label "Code" parm { name "group" baseparm label "Group" export none bindselector points "Modify Points" "Select the points to affect and press Enter to complete." 0 1 0xffffffff 0 grouptype 0 } parm { name "grouptype" baseparm label "Group Type" export none } parm { name "class" baseparm label "Run Over" export none } parm { name "vex_numcount" baseparm label "Number Count" export none } parm { name "vex_threadjobsize" baseparm label "Thread Job Size" export none } parm { name "snippet" baseparm label "VEXpression" export all } parm { name "exportlist" baseparm label "Attributes to Create" export none } parm { name "vex_strict" baseparm label "Enforce Prototypes" export none } } group { name "folder2_2" label "Bindings" parm { name "autobind" baseparm label "Autobind by Name" export none } multiparm { name "bindings" label "Number of Bindings" baseparm default 0 parmtag { "autoscope" "0000000000000000" } parmtag { "multistartoffset" "1" } parm { name "bindname#" baseparm label "Attribute Name" export none } parm { name "bindparm#" baseparm label "VEX Parameter" export none } } parm { name "groupautobind" baseparm label "Autobind Groups by Name" export none } multiparm { name "groupbindings" label "Group Bindings" baseparm default 0 parmtag { "autoscope" "0000000000000000" } parmtag { "multistartoffset" "1" } parm { name "bindgroupname#" baseparm label "Group Name" export none } parm { name "bindgroupparm#" baseparm label "VEX Parameter" export none } } parm { name "vex_cwdpath" baseparm label "Evaluation Node Path" export none } parm { name "vex_outputmask" baseparm label "Export Parameters" export none } parm { name "vex_updatenmls" baseparm label "Update Normals If Displaced" export none } parm { name "vex_matchattrib" baseparm label "Attribute to Match" export none } parm { name "vex_inplace" baseparm label "Compute Results In Place" export none } parm { name "vex_selectiongroup" baseparm label "Output Selection Group" export none } } ' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opparm $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator bindings ( 0 ) groupbindings ( 0 )
opparm $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator snippet ( '\n//INPUT 1 - OBJECT TO EMIT FROM\n//INPUT 2 - SINGLE POINT THAT PROVIDES THE VELOCITY DIRECTION (i.e. emitting object -> pack -> transform)\n\n//Initiate Values\nvector cdir = chv("custom_direction");\nvector p1 = point(1,"P",0);\nfloat r1 = rand(@ptnum*123.321);\n\n\n//NOISE\nfloat val = noise(@P * chf("noise_frequency") + chf("noise_seed"));\nval = fit(val,chf("in_noise_min_val"),chf("in_noise_max_val"),chf("out_noise_min_val"),chf("out_noise_max_val"));\nval = pow(val,chf("power"));\n\n//Visualise Noise\nif(ch("cd_viz")==1)\n @Cd = set(val,val,val);\nelse if(ch("cd_viz")==0)\n @Cd = @Cd;\n\n\n//DIRECTION\nif(ch("customdir")==1)\n v@direction = normalize(cdir);\nelse if(ch("customdir")==0)\n v@direction = normalize(@P - p1);\n\n\n//SPEED\nfloat speed = fit01(r1,ch("rand_min"),ch("rand_max"));\n\n\n//SET VELOCITY\nv@v = speed * @direction;\nv@v *= val;\n\n\n//VELOCITY MULTIPLIER\n@v *= chf("velocity_multiplier");\n' ) noise_frequency ( 2.2959999999999998 ) noise_seed ( 223 ) in_noise_min_val ( 0.50800000000000001 ) in_noise_max_val ( 0.72499999999999998 ) out_noise_min_val ( 0.16 ) out_noise_max_val ( 0.82299999999999995 ) power ( 3 ) rand_max ( 0.92800000000000005 ) velocity_multiplier ( 20 ) label_string ( 'When custom direction is off, it uses the direction from input 1' )
chlock $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator +label_string
opcomment -c 'Created from Gallery Entry: dvVelocityGenerator\n\nCustomized Attribute Wrangle Sop node.' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opset -d on -r on -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opuserdata -n '___Version___' -v '' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opcf ..
opcf $_obj_geo1_dvVelocityGenerator
# Node $_obj_geo1_dvVelocityGenerator_add1 (Sop/add)
set _obj_geo1_dvVelocityGenerator_add1 = `run("opadd -e -n -v add add1")`
oplocate -x `$arg2 + 2.3725500000000004` -y `$arg3 + 3.9234799999999996` $_obj_geo1_dvVelocityGenerator_add1
opparm $_obj_geo1_dvVelocityGenerator_add1 points ( 1 ) prims ( 1 )
opparm -V 16.5.508 $_obj_geo1_dvVelocityGenerator_add1 usept0 ( on ) pt0 ( 0 -1.224 0 )
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off $_obj_geo1_dvVelocityGenerator_add1
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator_add1
opuserdata -n '___Version___' -v '16.5.508' $_obj_geo1_dvVelocityGenerator_add1
# Node $_obj_geo1_dvVelocityGenerator_scatter1 (Sop/scatter::2.0)
set _obj_geo1_dvVelocityGenerator_scatter1 = `run("opadd -e -n -v scatter::2.0 scatter1")`
oplocate -x `$arg2 + 0` -y `$arg3 + 3.9234799999999996` $_obj_geo1_dvVelocityGenerator_scatter1
opparm -V 16.5.508 $_obj_geo1_dvVelocityGenerator_scatter1 npts ( 100000 )
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off $_obj_geo1_dvVelocityGenerator_scatter1
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator_scatter1
opuserdata -n '___Version___' -v '16.5.508' $_obj_geo1_dvVelocityGenerator_scatter1
# Node $_obj_geo1_dvVelocityGenerator_sphere1 (Sop/sphere)
set _obj_geo1_dvVelocityGenerator_sphere1 = `run("opadd -e -n -v sphere sphere1")`
oplocate -x `$arg2 + 0` -y `$arg3 + 5.2176` $_obj_geo1_dvVelocityGenerator_sphere1
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off $_obj_geo1_dvVelocityGenerator_sphere1
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator_sphere1
opuserdata -n '___Version___' -v '16.5.508' $_obj_geo1_dvVelocityGenerator_sphere1
oporder -e dvVelocityGenerator add1 scatter1 sphere1
opcf ..
opset -p on $_obj_geo1_dvVelocityGenerator
opcf $arg1
opcf $_obj_geo1_dvVelocityGenerator
opwire -n $_obj_geo1_dvVelocityGenerator_scatter1 -0 $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opwire -n $_obj_geo1_dvVelocityGenerator_add1 -1 $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator
opwire -n $_obj_geo1_dvVelocityGenerator_sphere1 -0 $_obj_geo1_dvVelocityGenerator_scatter1
opcf ..
set oidx = 0
if ($argc >= 9 && "$arg9" != "") then
set oidx = $arg9
endif
if ($argc >= 5 && "$arg4" != "") then
set output = $_obj_geo1_dvVelocityGenerator
opwire -n $output -$arg5 $arg4
endif
if ($argc >= 6 && "$arg6" != "") then
set input = $_obj_geo1_dvVelocityGenerator
if ($arg8) then
opwire -n -i $arg6 -0 $input
else
opwire -n -o $oidx $arg6 -0 $input
endif
endif
opcf $saved_path
'''
hou.hscript(h_preamble + h_extra_args + h_cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment