Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Learning something new

Hans Palacios morphingdesign

💭
Learning something new
View GitHub Profile
@morphingdesign
morphingdesign / hou_padPieceNumber.h
Created May 14, 2021
Rename fracture piece @name attribute with padded numbering in Houdini VEX.
View hou_padPieceNumber.h
// Fractured pieces are generated with @name such as 'piece0', 'piece1', etc.
// The following prim wrangle renames each piece with a padded number.
// String var to hold padded piece number.
string new_name = sprintf("piece_%04d", opdigits(@name));
// Update piece name.
s@name = new_name;
@morphingdesign
morphingdesign / hou_staticDynamicValues.h
Created May 12, 2021
Differentiation between initializing static and dynamic values in Houdini VEX.
View hou_staticDynamicValues.h
// Static Values
variable = {0,1,2};
// Dynamic Values
variable = set(x,y,z);
@morphingdesign
morphingdesign / hou_roundToSpecdDigits.h
Created Apr 6, 2021
Setup to round parameter value digits to specified number of digits, such as to 3 digits.
View hou_roundToSpecdDigits.h
// Replace <value> with value intended to be rounded.
round(<value> * 1000) / 1000
@morphingdesign
morphingdesign / markdown_SubAndSuperscript.md
Created Feb 22, 2021
Formatting for subscript and superscript in markdown.
View markdown_SubAndSuperscript.md

Add subscript with the <sub></sub> tags.

ni

kni

Add superscript with the <sup></sup> tags.

x2

@morphingdesign
morphingdesign / hou_trailingNumFromNodeName.py
Created Feb 10, 2021
Extract consecutive trailing numerical digits from a Houdini node name.
View hou_trailingNumFromNodeName.py
# Extract consecutive trailing numerical digits from a node's name.
import hou
return pwd().digitsInName()
# For example, a node named 'NEW_GEO_101' will return the int 101
# into the field. Returns 0 if name does not include any trailing
# numerical digits.
@morphingdesign
morphingdesign / hou_dataTypeConversions.h
Created Feb 9, 2021
Data type conversion operations specified for use in Houdini Vex
View hou_dataTypeConversions.h
//Convert integer to string
s@string_attribute = itoa(i@int_attribute);
//Convert string to integer
i@int_attribute = atoi(s@string_attribute);
//Convert string to float
f@float_attribute = atof(s@string_attribute);
@morphingdesign
morphingdesign / hou_networkEditorPref.py
Last active Dec 7, 2021
Access all available UI preferences for a Network Editor pane in a Houdini desktop/session via Python.
View hou_networkEditorPref.py
# Access panes in the current Houdini desktop using the
# the hou.ui class with/out the hou.Desktop class.
panes = hou.ui.currentPaneTabs()
panes = hou.ui.curDesktop().currentPaneTabs()
(<hou.NetworkEditor panetab1>, <hou.PythonShell panetab2>)
# View current setting for each available preference for
# the selected Network Editor pane.
pane = panes[0]
pane.getPrefs()
@morphingdesign
morphingdesign / hou_inlineTernaryIf.h
Created Feb 4, 2021
Variations in formatting simple inline if statements in Houdini Vex. Complex conditionals should utilize base formatting for clarity.
View hou_inlineTernaryIf.h
// Base formatting:
// Curly brackets for encapsulating multiple statements.
if(v@P.x > 0){
v@Cd = {1, 0, 0};
}
else{
v@Cd = {0, 1, 0};
}
// Inline formatting:
@morphingdesign
morphingdesign / hou_setNsetExpression.py
Last active Aug 3, 2021
Method for setting parameter values with specified data type or expressions.
View hou_setNsetExpression.py
rotateNode = hou.node('obj/box1/transform1')
speed = 20
# set() used to specify param value with corresponding data type.
rotateNode.parm('rz').set(10)
# However, it cannot be used to set the value with a non-compatible
# data type, such as a string channel reference. The use of
# setExpression() allows for such instances.
rotateNode.parm('ry').setExpression('ch("../box1/divrate2") * {}'.format(speed))
# Reference: https://www.sidefx.com/docs/houdini/hom/hou/Parm.html
@morphingdesign
morphingdesign / hou_connectNearPts.h
Created Jan 26, 2021
Connect near points with polyline in Houdini Vex with user-defined radius and max point count.
View hou_connectNearPts.h
// Set Wrangle to 'Run Over Points'.
// Collect closest pts for each pt, based on radius and max pts.
// Includes user-managed channels for radius and max pts.
// Note that this list will include the current point being run
// through this point wrangle.
int pts[] = pcfind(0,"P",@P,chf('search_radius'),chi('max_points'));
// Used to visualize list in geo spreadsheet; for debugging.
i[]@pts = pts;