How to determine type of a datablock?

Hello,

How can I determine the type of the datablock from the list of selected objects? Also, how do I access multiple datablocks in the case that the object contains more than one?

Here is what I am currently doing, which is inelegant:


# go through selected objects and get their meshes, if they exist
for obj in Blender.Object.GetSelected():
    # get the datablock name
    dataName = obj.getData(True); # argument indicates string name is desired
    # get mesh from datablock name
    try: mesh = Mesh.Get( dataName )
    except NameError:
        print "WARNING: Non-mesh object [" + obj.name + "] selected!  Object ignored."
        continue
    print "Found mesh in selected object: " + str(mesh)

I would like to identify lamps and cameras separately and handle them differently without looping through the selected objects excessively.

Thank you in advance!

Note that the following works, but is also messy:

# go through selected objects and get their meshes, if they exist
for obj in Blender.Object.GetSelected():
    # get the datablock
    data = obj.getData(False,True); # get the data itself as a mesh, not its name
    # test datablock type
    isMesh = str( type( data ) ) == "<type 'Blender Mesh'>" # converts type to string for comparison
    print "Selected object contains mesh: " + str( isMesh )

How can this be done without converting the type to a string literal? The following always seems to result in False for a mesh:

isMesh = type( data ) == Mesh

Is ‘Mesh’ actually the wrong type for mesh datablocks?

Would this work?


isMesh = type( data ) == "Mesh"

Here’s what I do in a script I’m working on. I found this in the API docs, where they say it’s the recommended way of doing things. This is for type checking an image:


if type(image) is Blender.Types.ImageType:

Link to docs.