個人的に大嫌いな1行forや1行ifをつぶしていくサンプルコードたち。
class Acla:
def unite_selection(self):
#selected = [x for x in cmds.ls(sl=True) if cmds.listRelatives(x, type="mesh")]
selected=[]
for x in cmds.ls(sl=True):
xx= cmds.listRelatives(x, type="mesh")
if xx:
selected.append(xx)
if not selected:
print("not selected")
return
#invalid_meshes = [x for x in cmds.listRelatives(selected, type="mesh", f=True) if not cmds.listConnections(x)]
invalid_meshes = []
for x in cmds.listRelatives(selected, type="mesh", f=True):
xx= cmds.listConnections(x)
if not xx:
invalid_meshes.append(xx)
if invalid_meshes:
print("invalid", invalid_meshes)
return
res = cmds.polyUnite(*cmds.ls(sl=True), ch=0, op=True, muv=1)
print(res)
ClassIns=Acla()
ClassIns.unite_selection()