Hi there, You don't really need to remove duplicates or get the parent in a list comprehension, maya cmds will deal with it anyways. The following code is basically the same you suggested, but should be much faster (way less maya calls).
from maya import cmds crvs = cmds.ls(typ='nurbsCurve', ni=True, o=True, r=True) xfos = cmds.listRelatives(crvs, p=True, typ="transform") cmds.select(xfos) Cheers! On Mon, Mar 9, 2015 at 9:52 AM, Gerard v <[email protected]> wrote: > import maya.cmds as cmds > curve_transforms = [cmds.listRelatives(i, p=1, type='transform')[0] for i > in cmds.ls(type='nurbsCurve', ni=1, o=1, r=1)] > curve_transforms = list(set(curve_transforms)) > cmds.select(curve_transforms) > > line 3 removes duplicates. Happy to get feedback from real programmers on > the use of converting a list to set and back to remove duplicates... > > On Mon, Mar 9, 2015 at 9:44 AM, Gerard v <[email protected]> wrote: > >> Hi. >> >> import maya.cmds as cmds >> curve_transforms = [cmds.listRelatives(i, p=1, type='transform')[0] for i >> in cmds.ls(type='nurbsCurve', o=1, r=1, ni=1)] >> cmds.select(curve_transforms) >> >> List comprehension is probably not the best way to explain it, and there >> may be a one command way to do it instead but: >> you just need an additional step: after you generate a list of nurbs >> curves in your scene pass that list through another command that finds the >> transform for each of the curves. >> If you really want to do it right you could also make sure that there are >> no duplicate names (ie the same transform name in the resulting list >> (perhaps there's a transform with more than one curve shape under it) and >> you could also filter any resulting transform to exclude say.. joints that >> have curve shapes as handles.. >> >> >> >> On Mon, Mar 9, 2015 at 8:52 AM, <[email protected]> wrote: >> >>> heyyy, >>> >>> i need to select all the curves present in my scene. But when i use this >>> command i only get the shape node which isn't too useful. >>> >>> curves=cmds.ls(type='nurbsCurve') >>> >>> i need it to return the scene name of the curve that i have given it >>> before. >>> >>> >>> thanks alot, >>> Sam >>> >>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/5c511357-544d-4530-bbde-c5e59b17441a%40googlegroups.com >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CADKA4CrUfp0HedNetTQ-jrZoyOps5Tdqf3FfOg%3DdU6RZZoAVUA%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CADKA4CrUfp0HedNetTQ-jrZoyOps5Tdqf3FfOg%3DdU6RZZoAVUA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPamJi-YJ%3D2Lm53Zbsu4Cc48YpBazz3-mOviV9pN0UXZ96p8Dw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
