code-google-com / pymel

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

Creating object with name clash to another object not in top level throws MayaNodeError #286

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Describe the problem.

-- If you attempt to create a new object (e.g. a locator) with an explicit name 
set and another object with the same name exists outside of the top level (e.g. 
in a group) the node requested will be created and the name the name will be 
set to the same as the existing node prepended with a |, but you'll also have a 
MayaNodeError thrown

What Version of Maya are you using?
-- Maya 2012

On what operating system? (be as specific as possible and include service 
packs, 64bit vs 32bit, etc)
-- Win 7 SP1 x64

What Version of PyMEL are you using?
-- 1.0.3 

What is the expected output? What do you see instead?
-- Ideally, I'd like to have the exception not thrown, and the name selection 
to match what I'd get if i used the rename function (i.e. if there's a clash, 
it'll return a name suffixed with a number that's one higher than any other 
object in the scene with the same base number)

If possible, provide a few lines of code to reproduce the problem. It helps us 
if your code will reproduce the problem from a new scene.

# setup and cleanup
import pymel.core as pm
import traceback
pm.newFile(force=True)
pm.flushUndo()

# begin reproduction:
locatorList = list()
# create ten locators called 'theLocator[1:10]'
for x in range(10):
    locatorList.append(pm.spaceLocator(name="theLocator1"))

# group objects to move them into a non-root level
pm.group(locatorList)

# try create a new locator, "theLocator5"
# throws a MayaNodeError, but creates the node anyway.
# run this block again, and you'll find a locator created with a name of 
theLocator11
try:
    # just to prove it's not specific to the 'first' number
    theLocator = pm.spaceLocator(name="theLocator5") 
except:
    traceback.print_exc()

# Traceback (most recent call last):
#   File "<maya console>", line 21, in <module>
#   File "C:\Program 
Files\Autodesk\Maya2012\Python\lib\site-packages\pymel\internal\factories.py", 
line 883, in newFuncWithReturnFunc
#     res = returnFunc(res[0])
#   File "C:\Program 
Files\Autodesk\Maya2012\Python\lib\site-packages\pymel\core\general.py", line 
1679, in __new__
#     raise _objectError( name )
# MayaNodeError: Maya Node does not exist: u'theLocator5'

Does maya.cmds exhibit the same problem?
-- No. Maya.cmds will not throw an exception but the node created will still be 
named with the duplicate name, and subsequent calls will also increment from 
the top.

Please provide any additional information below.
--No idea if it helps, but just poking around a little further, if I catch the 
exception and check what theLocator is, it's surprisngly (to me) theLocator11. 
--Again, no idea, but is this related to issues 225 and 221? 

Original issue reported on code.google.com by anthony....@greenworm.net on 6 Oct 2012 at 11:53