here is the prev version with no globals, i ddnt connect the attributes here because i wanted to solde the parentConstraint first...:
import maya.cmds as mc
def add_attribute_and_create_group(*args):
attribute_name = mc.textField(attribute_field, query=True, text=True)
selected_objects =
mc.ls(selection=True)
created_groups = []
for selected_object in selected_objects:
if not mc.objExists("{0}.{1}".format(selected_object, attribute_name)):
mc.addAttr(selected_object, ln=attribute_name, at="double", min=0, max=1, dv=0, keyable=True)
group_name = selected_object + "_spaceGrp"
if not mc.objExists(group_name):
new_group = mc.group(selected_object, name=group_name)
mc.xform(new_group, centerPivots=True)
created_groups.append(new_group)
print('Returned object is:', created_groups)
return created_groups
def create_parent_constraint(*args):
selected_objects =
mc.ls(selection=True)
if not selected_objects:
print("Nessun oggetto selezionato.")
return
groups =
mc.ls("*_spaceGrp")
if not groups:
print("Nessun gruppo creato.")
return
for selected_object in selected_objects:
mc.parentConstraint(selected_object, groups[0], maintainOffset=True)
print("ParentConstraint creato tra", selected_object, "e", groups[0])
# Creazione della finestra
window = mc.window(title="Add Attribute")
mc.columnLayout(adjustableColumn=True)
attribute_field = mc.textField(text="")
mc.button(label="Esegui", command=add_attribute_and_create_group)
mc.button(label="Parent", command=create_parent_constraint)
mc.showWindow(window)