Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as mc
- def on_make_selection_button_clicked(*args):
- selected_objects = mc.ls(selection=True)
- if not selected_objects:
- mc.warning("Please select at least one object.")
- return
- if mc.radioButton("Head_RadioButton", q=True, sl=True):
- for selected_object in selected_objects:
- # Add a new double attribute with a range of 0 to 1 and a default value of 0
- mc.addAttr(selected_object, ln="Head", at="double", min=0, max=1, dv=0)
- # Make the new attribute keyable
- mc.setAttr("{0}.Head".format(selected_object), e=True, keyable=True)
- elif mc.radioButton("Hips_RadioButton", q=True, sl=True):
- for selected_object in selected_objects:
- # Add a new double attribute with a range of 0 to 1 and a default value of 0
- mc.addAttr(selected_object, ln="Hips", at="double", min=0, max=1, dv=0)
- # Make the new attribute keyable
- mc.setAttr("{0}.Hips".format(selected_object), e=True, keyable=True)
- elif mc.radioButton("Body_RadioButton", q=True, sl=True):
- for selected_object in selected_objects:
- # Add a new double attribute with a range of 0 to 1 and a default value of 0
- mc.addAttr(selected_object, ln="Body", at="double", min=0, max=1, dv=0)
- # Make the new attribute keyable
- mc.setAttr("{0}.Body".format(selected_object), e=True, keyable=True)
- # Create a new group and name it after the selected object, if it doesn't exist yet
- group_name = selected_objects[0] + "_spaceGrp"
- if not mc.objExists(group_name):
- new_group = mc.group(selected_objects, name=group_name)
- mc.xform(new_group, centerPivots=True)
- def on_new_selection_button_clicked(*args):
- selected_objects = mc.ls(selection=True)
- if not selected_objects:
- mc.warning("Please make a new selection.")
- return
- else:
- print("Selected objects:", selected_objects)
- existing_groups = [g for g in mc.ls(sl=True, type="transform") if g.endswith("_spaceGrp")]
- if not existing_groups:
- mc.warning("No previous group found.")
- else:
- for group_name in existing_groups:
- # Create a parent constraint between the new selection and the group
- mc.parentConstraint(selected_objects, group_name, mo=True)
- def create_gui():
- if mc.window("attribute_adder_gui", exists=True):
- mc.deleteUI("attribute_adder_gui")
- mc.window("attribute_adder_gui", title="Add Attributes", sizeable=1)
- mc.columnLayout(adjustableColumn=True)
- mc.separator(height=10)
- mc.rowLayout(nc=3, columnWidth3=[80,80,80])
- mc.radioCollection("attr_radioCollection")
- mc.radioButton("Head_RadioButton", label="Head")
- mc.radioButton("Hips_RadioButton", label="Hips")
- mc.radioButton("Body_RadioButton", label="Body")
- mc.setParent('..')
- mc.separator(height=20)
- mc.button(label="Add new Space", command=on_make_selection_button_clicked)
- mc.button(label="Connect to", command=on_new_selection_button_clicked)
- mc.showWindow("attribute_adder_gui")
- create_gui()
Advertisement
Add Comment
Please, Sign In to add comment