Guest User

Untitled

a guest
May 10th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.18 KB | None | 0 0
  1. import maya.cmds as mc
  2.  
  3.  
  4. def on_make_selection_button_clicked(*args):
  5.     selected_objects = mc.ls(selection=True)
  6.     if not selected_objects:
  7.         mc.warning("Please select at least one object.")
  8.         return
  9.  
  10.     if mc.radioButton("Head_RadioButton", q=True, sl=True):
  11.         for selected_object in selected_objects:
  12.             # Add a new double attribute with a range of 0 to 1 and a default value of 0
  13.             mc.addAttr(selected_object, ln="Head", at="double", min=0, max=1, dv=0)
  14.  
  15.             # Make the new attribute keyable
  16.             mc.setAttr("{0}.Head".format(selected_object), e=True, keyable=True)
  17.  
  18.     elif mc.radioButton("Hips_RadioButton", q=True, sl=True):
  19.         for selected_object in selected_objects:
  20.             # Add a new double attribute with a range of 0 to 1 and a default value of 0
  21.             mc.addAttr(selected_object, ln="Hips", at="double", min=0, max=1, dv=0)
  22.  
  23.             # Make the new attribute keyable
  24.             mc.setAttr("{0}.Hips".format(selected_object), e=True, keyable=True)
  25.  
  26.     elif mc.radioButton("Body_RadioButton", q=True, sl=True):
  27.         for selected_object in selected_objects:
  28.             # Add a new double attribute with a range of 0 to 1 and a default value of 0
  29.             mc.addAttr(selected_object, ln="Body", at="double", min=0, max=1, dv=0)
  30.  
  31.             # Make the new attribute keyable
  32.             mc.setAttr("{0}.Body".format(selected_object), e=True, keyable=True)
  33.  
  34.     # Create a new group and name it after the selected object, if it doesn't exist yet
  35.     group_name = selected_objects[0] + "_spaceGrp"
  36.     if not mc.objExists(group_name):
  37.         new_group = mc.group(selected_objects, name=group_name)
  38.         mc.xform(new_group, centerPivots=True)
  39.  
  40.  
  41. def on_new_selection_button_clicked(*args):
  42.     selected_objects = mc.ls(selection=True)
  43.     if not selected_objects:
  44.         mc.warning("Please make a new selection.")
  45.         return
  46.     else:
  47.         print("Selected objects:", selected_objects)
  48.         existing_groups = [g for g in mc.ls(sl=True, type="transform") if g.endswith("_spaceGrp")]
  49.         if not existing_groups:
  50.             mc.warning("No previous group found.")
  51.         else:
  52.             for group_name in existing_groups:
  53.                 # Create a parent constraint between the new selection and the group
  54.                 mc.parentConstraint(selected_objects, group_name, mo=True)
  55.  
  56.  
  57. def create_gui():
  58.     if mc.window("attribute_adder_gui", exists=True):
  59.         mc.deleteUI("attribute_adder_gui")
  60.  
  61.     mc.window("attribute_adder_gui", title="Add Attributes", sizeable=1)
  62.     mc.columnLayout(adjustableColumn=True)
  63.     mc.separator(height=10)
  64.    
  65.     mc.rowLayout(nc=3, columnWidth3=[80,80,80])
  66.     mc.radioCollection("attr_radioCollection")
  67.     mc.radioButton("Head_RadioButton", label="Head")
  68.     mc.radioButton("Hips_RadioButton", label="Hips")
  69.     mc.radioButton("Body_RadioButton", label="Body")
  70.     mc.setParent('..')
  71.    
  72.     mc.separator(height=20)
  73.     mc.button(label="Add new Space", command=on_make_selection_button_clicked)
  74.     mc.button(label="Connect to", command=on_new_selection_button_clicked)
  75.  
  76.     mc.showWindow("attribute_adder_gui")
  77.    
  78. create_gui()
Advertisement
Add Comment
Please, Sign In to add comment