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)
댓글