top of page

Code snippet: Houdini group by class from path regex match

Ellie Ansell

Given a group of items with path names matching the regex pattern r".*var([A-Z]).*", e.g. '/path/pathVarA', '/pathvarB', '/path/varC', assign the match to a class attribute. #grouping #regex #houdini #vex


import re

node = hou.pwd()
geo = node.geometry()

re_match = r".*var([A-Z]).*"

geo.addAttrib(hou.attribType.Prim, "class", 0)

for p in geo.prims():
    v = p.attribValue("path")
    if re.match(re_match, v, re.IGNORECASE):
        find = re.findall(re_match, v, re.IGNORECASE)[0]
        p.setAttribValue("class", ord(find)-64)
    else:
        p.setAttribValue("class", 999)


257 views0 comments

Recent Posts

See All

댓글


  • LinkedIn // Professional Bio
  • Facebook // ellieansellart page
  • Instagram // Informal fun
  • Vimeo

© 2020 by Ellie Ansell

Happily created using Wix.com

bottom of page