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 < squashnstret...@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_maya+unsubscr...@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/CAPGFgA0ozdWmGhWeu3RfAt%2Bk-gWeRvBhfgNs%2BM7iOmutWD%2Besw%40mail.gmail.com.