pymel duplicate shape

1,063 views
Skip to first unread message

Mikkel Caiafa

unread,
Feb 6, 2014, 1:45:58 PM2/6/14
to python_in...@googlegroups.com

Hello all,

 

I noticed this in the pymel docs for the duplicate command:

 

Modifications:

·         new option: addShape

If addShape evaluates to True, then all arguments fed in must be shapes, and each will be duplicated and added under the existing parent transform, instead of duplicating the parent transform. The following arguments are incompatible with addShape, and will raise a ValueError if enabled along with addShape:

renameChildren (rc), instanceLeaf (ilf), parentOnly (po), smartTransform (st)

 

Decided to try it out but I’m getting an error.  Any ideas what I’m doing wrong?

 

node = pm.circle()[0]

curves = node.getChildren(type='nurbsCurve')

newCurves = pm.duplicate(curves, addShape=True)

 

# Error: Maya Attribute does not exist: u"[nt.NurbsCurve(u'nurbsCircleShape1')]"

# Traceback (most recent call last):

#   File "<maya console>", line 1, in <module>

#   File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\core\general.py", line 1265, in duplicate

#     for origShape in [PyNode(x) for x in args]:

#   File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\core\general.py", line 1787, in __new__

#     raise _objectError( name )

# MayaAttributeError: Maya Attribute does not exist: u"[nt.NurbsCurve(u'nurbsCircleShape1')]" #

 

 

Thanks!

-Mikkel.

Geordie Martinez

unread,
Feb 6, 2014, 8:24:47 PM2/6/14
to python_inside_maya
try this. you were passing a list which is what getChildren gives you.
in this case you're getting the shape node (not a list). Hope this helps!


import pymel.core as pm
node = pm.circle()[0]
curves = node.getShape()
newCurves = pm.duplicate(curves, addShape=True)



--
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/bc286db7ae354cf2a6cfa4c54f7840ac%40CO1PR05MB362.namprd05.prod.outlook.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mikkel Caiafa

unread,
Feb 7, 2014, 6:32:38 PM2/7/14
to python_in...@googlegroups.com
Thanks Geordie!  Seems kind of obvious now.  I do have cases where there could be multiple shape nodes, (and just found out .getShape() only returns the first shape) so I'll just expand my list.

node = pm.circle()[0]

curves = node.getChildren(type='nurbsCurve')

newCurves = pm.duplicate(*curves, addShape=True)


Cheers!

-Mikkel.




From: python_in...@googlegroups.com <python_in...@googlegroups.com> on behalf of Geordie Martinez <geordie...@gmail.com>
Sent: Thursday, February 06, 2014 7:24 PM
To: python_inside_maya
Subject: Re: [Maya-Python] pymel duplicate shape
 

Paul Molodowitch

unread,
Feb 8, 2014, 10:23:57 AM2/8/14
to python_inside_maya
Also, FYI, there's a "getShapes()", which returns all shapes. IIRC, it also takes type kwargs (though, at that point, it's really no different than .getChildren()...)


Reply all
Reply to author
Forward
Message has been deleted
0 new messages