How can I skip non mesh objects?

:o How would I skip all non mesh/empty objects in the selected list. Currently, when I try to access the .data of a curve/surface - Blender pops up with a pyhton pops up with a missing module error.

Anyone got any ideas?


import Blender
MeshList = [ob for ob in Blender.Object.GetSelected() if ob and ob.data and ob.data.Block_Type == "NMesh"]

I’m not sure about the Block_Type property though, you’ll have to check for the correct spelling.

this creates a list of all the selected Mesh objects.

Martin

Thanks for the help, but thats something close to that is what i already have - the problem is;

when you try to access the .data part of a curve/surface then python pops up a error message of a missing module. So the poblem with the above snippet is, that it will halt and not ship non mesh objects. :frowning:

Python error is…

File “…/modules/Blender/shadow.py”, line 156, in getattr
File “…/modules/Blender/shadow.py”, line 97, in _getattrEx
SystemError: unable to create Block for data

Is there any way to work around this missing module?

what Blender version are you using?

I’m pretty sure it works with 2.23, since the “if ob.data” part takes care of the object where data is inextistant.

if not, you could use this:


import Blender

ObList = Blender.Object.Get()
MeshList = []
for Ob in ObList:
        try:
                if Ob and Ob.data and Ob.data.Block_Type == "NMesh":
                        MeshList.append(OB)
        except:
                pass


Martin

Blender version is publisher (2.25) as in from the downloads on blender.org . Just off to test a few bits, will report back soon.

Woot!!, the 2nd snippet does the trick :slight_smile: - or at least points me in the right direction! :smiley:

Thanks again

Although ob.data works in Publisher, the advised method from the docs is to use ob.getData(). When using dir(), the results are different too.

I forgot, to get the type of the object, use ob.getType(), this will return ‘Mesh’ for a mesh, for anything else that is not supported it will return ‘<unsupported>’