Sunday, February 27, 2011

Can You Complete Cube Field

Blender: the selector of instances grows ...

Continue work on the script ... for what is to me is actually already finished.
now defines an operator that can be used as a shortcut (screen.select_instances ()) and that I have assigned to "SHIFT + I"
There is an active selection and control over a report in the console and the main window blender.

Things to do: select by name. I do not want in any case it becomes a heavy tool windows and more: it is a small utility for internal whose merits must be fast and lightweight.
Sorry for writing a bit 'but I botched studied python last Thursday and Friday API blender, among other things, the API is subject to constant change and many examples on the site do not always work.

Here is the expanded code:


#! Bpy
"" "
Name: 'Select object instances'
Blender: 256
Group: 'Object'
Tooltip: 'Select object instances'
"" "
#author: Pietro Grandi (pietro909.blogspot.com)
#
#Release 0.4
# - now the script is an operator that can be added as a shortcut
# under Preferences->Input->Screen
# - the script performs a control in order to check if there is something active
# - messages are printed in console (verbose output) and as report on the top
#
# TODO: select by name, i'd like to have a popup to choose the selection type.
#


import bpy
class SelectInstances (bpy.types.Operator):
bl_idname = "screen.select_instances"
bl_label = "Select Instances "
def execute (self, context):
top = '[si-0.4]' # header to the messages on the console scene
= bpy. context.scene # points to the active scene

i = 0 # counter for loop
k = 0 # counter selected objects

sel_obj bpy.context.active_object = # active object
if sel_obj == None: # If there are active objects
print (top + 'Error: no object selected') # indicates error in console
self.report ({'ERROR'}, ' no object selected ') # Indicates the report
return {'CANCELLED'} # and exit

# otherwise, if the selection and 'still valid #
sel_obj_type = sel_obj.data. name # object type selected
sel_obj_name sel_obj.name = # name of the selected


print (top + 'Active object:' + sel_obj_name + '->' + sel_obj_type)
print ('Instances:')

for object in scena.objects: # for each object in the scene
current_obj scena.objects = [i] # get the name of
if current_obj.data.name == sel_obj_type: # check if the selected type
print ('Selected' current_obj.name +) # print it
current_obj.select = True # select
k + = 1
i + = 1 # advance the counter
print ('Total objects found and selected:' + str (k)) # print the result in console
report_string = str (k) + 'instances of 'sel_obj_type + +' found '
self.report ({' INFO '}, report_string) # and the report
{return' FINISHED '} # end

if __name__ ==
"__main__":
bpy.ops.screen.select_instances ()

EDIT: The script has been tested with a scene of over 2.7 million polygons and about 8000 instances of the object (cubes, cones, spheres, boxes)

0 comments:

Post a Comment