Hello again, update.... I managed to make it work a bit better but still not as I need to... thanks to your suggestions I'm able now to check channels and create locators, constraints etc ... So I have a script that checks everything and if selections have both rotations and translations available, it runs the function properly; if there is something locked it stop and warn. And I can also have several objects selected.
Now Im trying something more... I'd like the script to check what channel is available and act accordingly, if there is only translation, it contstraint just the translations, if only rotations available, it works only with that.... I ended up make it work by adding the skipRotation or skipTranslation flag but it works only selecting one object at a time, if I select several object in the scene where some has both T and R and some had just translation and no rotations, it fails for all the object but work only for the first one.... I guess I need a loop or another condition which checks inside my 'userSel' variable but not sure how to do..... Probably the problem is in the sel[0] call, which looks only on the first obj selected, I tried to add a loop but it works only with translation, seems that it doesnt connect the rotations anyways this is what I have so far which works only selecting obj 1 by 1: # this works fine BUT 1 obj x time import maya.cmds as mc LocList = [] userSel = [] len(userSel) sel = [] sel = mc.ls(sl=1) userSel.append(sel) if len(sel) != 0: _has_trans = mc.getAttr (sel[0]+'.translate', settable=True) _has_rot = mc.getAttr (sel[0]+'.rotate', settable=True) else : mc.warning('Please make a selection') # check if there is rotations # create a loc for ech selected obj and constraint to it if _has_rot ==1 and _has_trans ==1: for obj in sel: newLoc = mc.spaceLocator() newCon = mc.parentConstraint(obj, newLoc, mo=0) LocList.append(newLoc) elif _has_rot ==0 and _has_trans ==1: for obj in sel: newLoc = mc.spaceLocator() newCon = mc.parentConstraint(obj, newLoc, mo=0, sr=['x', 'y', 'z']) LocList.append(newLoc) elif _has_rot ==1 and _has_trans ==0: for obj in sel: newLoc = mc.spaceLocator() newCon = mc.parentConstraint(obj, newLoc, mo=0, st=['x', 'y', 'z']) LocList.append(newLoc) # select all new Loc if len(sel) != 0: for loc in LocList: mc.select (loc, add=1) start = mc.playbackOptions(q=True, min=True) end = mc.playbackOptions(q=True, max=True) mc.bakeResults(sm=1, sr=1, t=(start, end)) #else: #mc.warning('Please make a selection') for loc in LocList: mc.select (loc, add=1) mc.delete(cn=1) # reverse connection if _has_rot ==1 and _has_trans ==1: for idx, item in enumerate(LocList): ctl = item makeParentCons = mc.parentConstraint(ctl, userSel[0][idx], mo=True, w=1) elif _has_rot ==0 and _has_trans ==1: for idx, item in enumerate(LocList): ctl = item makeParentCons = mc.parentConstraint(ctl, userSel[0][idx], mo=True, w=1, sr=['x', 'y', 'z']) elif _has_rot ==1 and _has_trans ==0: for idx, item in enumerate(LocList): ctl = item makeParentCons = mc.parentConstraint(ctl, userSel[0][idx], mo=True, w=1, st=['x', 'y', 'z']) Il giorno sabato 25 marzo 2023 alle 22:18:19 UTC SquashnStretch net ha scritto: > that's great Justin, yes with settable I can what is available, now I'll > try to check with a condition.....I'll let you know if im able to :D > > thanks > F > > Il giorno sabato 25 marzo 2023 alle 21:20:47 UTC Justin Israel ha scritto: > >> The getAttr function can tell you if an attribute is locked, or even >> "settable": >> >> https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/getAttr.html >> >> On Sun, Mar 26, 2023 at 9:05 AM SquashnStretch net <squashn...@gmail.com> >> wrote: >> >>> Hello everyone, >>> I wrote (with a lot of difficulties :) my first python script where I >>> wanted to create a locator constraint to any selected animated object, bake >>> the anim and reverse the constraint , basically to easily change space if >>> needed ..... >>> the script works well but only if the animated object has translate and >>> rotate channels available, if they are locked or hidden, the script fails. >>> >>> Basically I dont know how to check first which channel is available and >>> based on the result, constraint only available channels.... >>> hope it makes sense to you .... >>> >>> this is what I have so far and thanks in advance for any helps! >>> ____________________________________ >>> import maya.cmds as mc >>> >>> #loc list >>> userSel = [] >>> LocList = [] >>> len(userSel) >>> # get the user selection >>> sel = mc.ls(sl=1) >>> userSel.append(sel) >>> >>> # create a loc for ech selected obj and constraint to it >>> for obj in sel: >>> if len(sel)!=0: >>> newLoc = mc.spaceLocator() >>> newCon = mc.parentConstraint(obj, newLoc, mo=0) >>> LocList.append(newLoc) >>> else: >>> mc.warning('Please make a selection') >>> >>> # select all new Loc >>> if len(sel) != 0: >>> for loc in LocList: >>> mc.select (loc, add=1) >>> start = mc.playbackOptions(q=True, min=True) >>> end = mc.playbackOptions(q=True, max=True) >>> mc.bakeResults(sm=1, sr=1, t=(start, end)) >>> else: >>> mc.warning('Please make a selection') >>> >>> for loc in LocList: >>> mc.select (loc, add=1) >>> mc.delete(cn=1) >>> >>> # reverse connection >>> for idx, item in enumerate(LocList): >>> ctl = item >>> makeParentCons = mc.parentConstraint(ctl, userSel[0][idx], mo=True, w=1) >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to python_inside_m...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/5c5853a4-ec08-40fa-bfea-2bb39ee333d5n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/python_inside_maya/5c5853a4-ec08-40fa-bfea-2bb39ee333d5n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4a3f2b41-209c-4868-a257-640db3a3bb41n%40googlegroups.com.