ECToo / pymel

Automatically exported from code.google.com/p/pymel
0 stars 0 forks source link

duplicate fails when an explicit arg is a child of another explicit arg #225

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
import pymel.core as pm
t1 = pm.nt.Transform(name='foobar')
t2 = pm.nt.Transform(name='foobar', parent='foobar')
pm.duplicate(t1, t2)

# Error: Maya Node does not exist: u'foobar'
# Traceback (most recent call last):
#   File "<maya console>", line 4, in <module>
#   File "/Volumes/lumadev/lumadev/paulm/python/pymel/pymel/core/general.py", 
line 1169, in duplicate
#     return map(PyNode, cmds.duplicate( *args, **kwargs ) )
#   File "/Volumes/lumadev/lumadev/paulm/python/pymel/pymel/core/general.py", 
line 1683, in __new__
#     raise _objectError( name )
# MayaNodeError: Maya Node does not exist: u'foobar' # 

This fails because the duplicate of t2 will still be named 'foobar' (because 
it's parent is also duplicated, so it doesn't need to change it's name), so the 
results returned from

maya.cmds.duplicate('foobar', 'foobar|foobar', returnRootsOnly=1)

will be

['foobar1', 'foobar']

...and 'foobar' is not unique.

To fix, think we need to petition autodesk for a 'fullPath' option to duplicate

Original issue reported on code.google.com by elron...@gmail.com on 5 Jan 2011 at 8:36

GoogleCodeExporter commented 9 years ago
As reported by mdfisher272 on github, in issue #14, can also get a similar 
error with:

import pymel.core as pm
trans = pm.polySphere()[0]
shape = trans.getShape()
shape.rename(trans.nodeName())
pm.duplicate(trans)

The basic issue here is the same - that there's no flag to duplicate to make 
sure we get back node names we can actually use to identify the nodes created.

Only good way is to get a 'fullPath' option for duplicate from Autodesk... as a 
workaround, could try to install a callback to track all newly-created nodes, 
and then match those against the node-names returned.  However, it's easy to 
think of situations in which we could have multiple new nodes with the same 
name, so figuring out which one is "supposed" to be returned could be tricky.

Original comment by elron...@gmail.com on 17 Jul 2012 at 5:00

GoogleCodeExporter commented 9 years ago
Fixed in
https://github.com/LumaPictures/pymel/commit/c1157d1f41c3d17cf774ed3dcf5542c584f
b3496

Original comment by elron...@gmail.com on 17 Jan 2014 at 6:21