How to skip non mesh objects?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

shagwana
Posts: 12
Joined: Wed Oct 16, 2002 6:18 am
Location: UK

How to skip non mesh objects?

Postby shagwana » Mon Oct 21, 2002 9:37 pm

:oops: Well, im kind of new to this python coding lark so be kind!

Im currently trying to access all selected objects from a pyhton script, like so;

Code: Select all

from Blender import *


print "Running..."

#Pull in the selected object information...
Selected_Objects=Object.GetSelected()
Number_Of_Selected_Objects=len(Selected_Objects)

#If the user has selected some objects, get to work ....
if Number_Of_Selected_Objects>0:
   #The user has selected something!
   for Working_Object in Selected_Objects:
      #Scan through each of the objects available, grab the object in question
      #If its a usable type ...
      if Working_Object.data==None:
         print "Axis"+str(Working_Object)
         #<<< problem!?! >>>
else:
   #No work to do, exit!
   print "Nothing selected!."


Now my problem is, how can I tell a non mesh object (Mesh & empty) apart from a curve (and other blender object types)?

When trying to access .data of a curve/surface (for example), I get a python module missing error :(

All I want to be able to so is skip non mesh objects in the selection, any pointers or ideas would be ace :P

chromit
Posts: 3
Joined: Fri Oct 18, 2002 12:55 pm

Postby chromit » Wed Oct 23, 2002 8:01 pm

hope this helps, in my version (2.20) it works. dont know why i had to import Blender210. with the Blender namespace it didnt work.

Code: Select all

from Blender import *
import Blender210
import string

print "Running..."

#Pull in the selected object information...
Selected_Objects=Object.GetSelected()
Number_Of_Selected_Objects=len(Selected_Objects)

#If the user has selected some objects, get to work ....
if Number_Of_Selected_Objects>0:
   #The user has selected something!
   for Working_Object in Selected_Objects:
      #Scan through each of the objects available, grab the object in question
      #If its a usable type ...
     
      if Blender210.isMesh(Working_Object.name):
         print "mesh"
         print "Axis"+str(Working_Object)
      else:
         print "somethingelse"
 
else:
   #No work to do, exit!
   print "Nothing selected!."

chromit
Posts: 3
Joined: Fri Oct 18, 2002 12:55 pm

Postby chromit » Wed Oct 23, 2002 8:21 pm

installed 2.25. here you can get the Type with the getType() method.

Code: Select all

from Blender import *

Selected_Objects=Object.GetSelected()
Number_Of_Selected_Objects=len(Selected_Objects)

if Number_Of_Selected_Objects>0:
   for Working_Object in Selected_Objects:
      print "-- "+Working_Object.getType()
else:
   print "Nothing selected!."
Last edited by chromit on Sun Oct 27, 2002 6:51 pm, edited 1 time in total.

shagwana
Posts: 12
Joined: Wed Oct 16, 2002 6:18 am
Location: UK

Postby shagwana » Thu Oct 24, 2002 3:46 pm

Thanks, the getObject() method helps tons. :)


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest