Feeds:
Posts
Comments

Archive for June, 2010

Our Internet service was down for six or so days. That was the only time this year I’ve been productive.

I started playing around with Blender’s Python scripting and wanted to do something really basic just to see if I could do it. With help, I did. I present to you: Select objects by type.

It just pops up a menu and selects all the objects in the active scene that are of the type you select in the menu. I was working on multiple selection but Blender’s built-in toggle buttons — “Draw.Create(True/False)”  — hate me.

It doesn’t work with 2.5. I (kind of) tried to get it working, but I have to say I feel bad for the people porting stuff over.

It’s noobish. It’s ugly. It’s useless. It’s buggy. It…works at least. 😀

#!BPY
"""
Name: 'Select Objects by Type'
Blender: 249
Group: 'Object'
Tooltip: 'Selects all objects in a scene based on their type (camera, mesh, lamp, etc.) regardless of layer'
"""
#With help from "Find by Data Use" script by Campbell Barton
from Blender import *
import bpy
import BPyMessages

sce = bpy.data.scenes.active
for object in sce.objects:
	if object.sel == 1:
			object.sel = 0
			
			
def objectSelect(type, scene):
	objCount = 0
	for object in scene.objects:
		if object.type == type:
			object.sel = 1
			objCount += 1
	#If there aren't any objects of a particular type in the scene
	if objCount == 0:
		Draw.PupMenu("Error%t|No objects of type in scene")
	else:
		Draw.PupMenu("Selected " + str(objCount) + " object(s)")
	
			
condition = Draw.PupMenu("Which objects to select?%t"
"|Meshes|Lamps|Cameras|Curves|Surfaces|Empties"
"|Armatures|Lattices|Text|Meta|All")

if condition == 1:
	objectSelect('Mesh', sce)
		
elif condition == 2:		
	objectSelect('Lamp', sce)
	
elif condition == 3:		
	objectSelect('Camera', sce)
			
elif condition == 4:
	objectSelect('Curve', sce)
		
elif condition == 5:		
	objectSelect('Surf', sce)
			
elif condition == 6:		
	objectSelect('Empty', sce)
			
elif condition == 7:
	objectSelect('Armature', sce)
	
elif condition == 8:		
	objectSelect('Lattice', sce)
			
elif condition == 9:		
	objectSelect('Text', sce)
	
elif condition == 10:
	objectSelect('MBall', sce)

#Get all objects if we didn't pick a category
elif condition == 11:
	totalSceneObj = 0		
	for object in sce.objects:
			object.sel = 1
			totalSceneObj += 1
	Draw.PupMenu("Selected " + str(totalSceneObj) + " object(s)")
Advertisements

Read Full Post »