Skip to main content

Houdini Groups to Maya Sets

I need identiy points of a mouth geo that are near the teeth geo. Can't do it reliably and progmatrically in Maya, so ended up doing it in Houdini. The problem is Houdini Groups does not seem to be carried over to Maya Sets.

So I had to create scripts to export the data from Houdini and import the data in Maya

# Houdini Python
import hou
import json
import os

# Get the current node
node = hou.pwd()

# Get the detail attribute named "tag"
geo = node.geometry()
tag_value = geo.attribValue("tag")

# Get the path of the Houdini file
hip_file = hou.hipFile.name()

# Construct the path for the JSON file in the same directory
json_file_path = os.path.splitext(hip_file)[0] + "_tag_value.json"

# Save tag_value in JSON format
with open(json_file_path, 'w') as json_file:
json.dump({"tag_value": tag_value}, json_file, indent=4)

print("Tag value saved in JSON format:", tag_value)

# Maya Python
# Import Data from Houdini

import maya.cmds as cmds
import os
import json

# Load the JSON file
json_file_path = r"C:\Users\BT\Documents\projects\work\2024\09_dianne_void_eel\houdini\delete_small_parts_tag_value.json" # Replace this with the actual path
with open(json_file_path, 'r') as json_file:
data = json.load(json_file)

# Retrieve tag_value from JSON data

#print (data)
tag_value = data["tag_value"]

print (tag_value)

selection_set_name = "houdini_selection_set"
cmds.select(clear=True)
for vtx_index in tag_value:
print (type(vtx_index))
vtx_name = "body_low_wip.vtx[%d]" % vtx_index # Assuming pPlane1 is the name of your mesh
#print (vtx_name, type(vtx_name))
#cmds.select("body_low_wip.vtx[11323]", add=True)
cmds.select(vtx_name, add=True)

cmds.sets(name=selection_set_name, forceElement=True) # gives an error. create a new set yet.

# Create Rivets from the Sets
# Create Joints and Controls from the Rivets
# The sets contain point selection

# TO DO.
# Rename some joints. to the teeth
import maya.cmds as cmds

# Access specific selection set members
selected_objects = cmds.sets('houdini_selection_set', q=True)
rivet_list = []


# Create the Rivets
for p in selected_objects:
cmds.select(clear=True)
cmds.select(p, add=True)
cmds.Rivet()
constraint = cmds.ls(sl=True)
rivet_list.append(constraint)

# Create the Joints and Controls
#circle_ref = cmds.circle()[0] # returns ['nurbsCircle1', 'makeNurbCircle1']
circle_ref = 'box_ref'


for riv in rivet_list:
cmds.select(clear=True)
grp = cmds.group(em=True)
start_joint = cmds.joint() # automatic parent because riv joint is alreadyselected
end_joint = cmds.joint() # automatic parent because riv joint is alreadyselected
loc_obj = riv[1]
cmds.setAttr(loc_obj + ".localScaleX", 0.05)
cmds.setAttr(loc_obj + ".localScaleY", 0.05)
cmds.setAttr(loc_obj + ".localScaleZ", 0.05)
con = cmds.parentConstraint(loc_obj, grp, mo=False)
cmds.delete(con)
con = cmds.parentConstraint(loc_obj, start_joint, mo=False)
cmds.delete(con)
con = cmds.parentConstraint(loc_obj, end_joint, mo=False)
cmds.delete(con)
cmds.setAttr(end_joint + ".tx", 0.2)
con = cmds.parentConstraint(loc_obj, grp, mo=True)

# PARENT SHAPE CONTROLS
circle_duplicate = cmds.duplicate(circle_ref)
shape_nodes = cmds.listRelatives(circle_duplicate, shapes=True)[0]
rename_shape_node = start_joint + "_name" # Too dirty. Joint01, Joint02
cmds.rename(shape_nodes, rename_shape_node)
cmds.parent(rename_shape_node, start_joint, relative=True, shape=True)
cmds.delete(circle_duplicate)

#cmds.delete(circle_ref)