ECToo / pymel

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

Accessing components on Mesh object fails on empty mesh objects #209

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Describe the problem.
Accessing components on Mesh object fails on empty mesh objects

What Version of Maya are you using?
2009

On what operating system? (be as specific as possible and include service
packs, 64bit vs 32bit, etc)
Fedora 8

What Version of PyMEL are you using?
1.0

What is the expected output? What do you see instead?
Expected return = None or an empty list,
Errors out

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.

Creating an empty shape node:
m = pm.createNode('mesh')

Accessing its components
m.vtx
returns nothing
m.getParent().vtx
returns nothing

but if you try looping throug the returns, or checking the bool state of the 
result:
if m.vtx: print 'OK'
or
for v in m.vtx: print(v)

it will error out

The issue applies to all (edges, verts and faces)

Does maya.cmds exhibit the same problem?

n/a

Please provide any additional information below.

Error:
# Error: (kInvalidParameter): Object is incompatible with this method
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 1794, in __nonzero__
#     return self.exists()
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 1899, in exists
#     if self.__apiobject__() :
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3290, in __apiobject__
#     return self.__apimobject__()
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3283, in __apimobject__
#     handle = self.__apihandle__()
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3294, in __apihandle__
#     handle = self._makeComponentHandle()
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3487, in _makeComponentHandle
#     indices = self._standardizeIndices(self._indices)
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3561, in _standardizeIndices
#     indices.update(self._flattenIndex(indexObjs))
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3603, in _flattenIndex
#     partialIndex=oldPartial))
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 3845, in _sliceToIndices
#     start, stop, step = slice(start, stop, 
step).indices(self._dimLength(partialIndex))
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/core/gener
al.py", line 4249, in _dimLength
#     return self.node().numVertices()
#   File "<string>", line 2, in numVertices
#   File 
"/opt/aardman/lib/python2.5/site-packages/pymel-1.0.0-py2.5.egg/pymel/internal/f
actories.py", line 1962, in wrappedApiFunc
#     mfn = apiClass( self.__apiobject__() )
#   File 
"/engserv/rbuild/197/build/wrk/optim/runTime/lib/python2.5/site-packages/maya/Op
enMaya.py", line 3421, in __init__
# RuntimeError: (kInvalidParameter): Object is incompatible with this method # 

Original issue reported on code.google.com by orw...@gmail.com on 16 Sep 2010 at 10:13

GoogleCodeExporter commented 9 years ago
Fixed... the problem is due to the fact that MFnMesh can't be initialized with 
a mesh that is completely empty.
I wrapped a number of methods to either use mel methods instead, or return 
default values if there's no mesh... but a number of other methods simply won't 
work on an empty mesh.  However, it makes sense that most of these won't work, 
as they would require an actual mesh to work on.
At some point, might want to make a more informative error message though...

Original comment by elron...@gmail.com on 6 Oct 2010 at 1:37