batch select script

This is a bulk select script I’ve knocked up. You can select by name (inl prefix and suffix) data name, data type and layer. It only works in blender 2.37.
I havent tested it heavily yet, so I would appreciate some feedback. If you find it useful, or want soem new features, left me know.


#!BPY

""" 
Name: 'Batch select' 
Blender: 237 
Group: 'Object' 
Tip: 'Apply the chosen rule to select multiple objects all at once.' 
"""

__author__ = "Zenoscope" 
__url__ = ("blender", "elysiun","www.animate.8k.com") 
__version__ = "1.0" 
__bpydoc__ = """\ 
This script is to select multiple objects by name,data name, layer or type (camera, light etc)
""" 
 
# -------------------------------------------------------------------------- 
# Batch Select by Zenoscope ver 0.1
# -------------------------------------------------------------------------- 
# ***** BEGIN GPL LICENSE BLOCK ***** 
# 
# This program is free software; you can redistribute it and/or 
# modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation; either version 2 
# of the License, or (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
# 
# ***** END GPL LICENCE BLOCK ***** 
# -------------------------------------------------------------------------- 

#ideas for 0.2
# change the behaviour so you can choose to over-write the old selection or keep it, 
# maybe with an add to selection/don't menu item
# right now it just adds to the selection. Shouldn't be too hard to add this


from Blender import * 
  
def selectLayer():
 # select objects by layer
 global gObjects
 
 # make a menu for the layers. 
 # maybe hack this to show only layers with objects in it
 
 layerStr=""
 for layers in range(1,21):
  layerStr = layerStr + "|Layer " + str(layers)
   
  # this is the closest approximation to the blender layers menu I could get. 2 just isn't pretty.
 result=Draw.PupMenu("Select A Layer%t" + layerStr,5)
 if result == -1: # mouse out
  pass
 else:
  for ob in gObjects:
   if ob.layers[0] == result:    
    ob.sel=1
   
def selectType():
 # select objects by type.
 # the list only generates objects that are in the scene.

 global gObjects
 
 pupString = "select%t" # start bulting the menu
 typeIndex = [] # index to store the object types in

 for ob in gObjects:
  #make  list of the objects.
  obStr=ob.getType()  
  # if the objectType isn't already recorded in the list(s) then add it, otherwise ignore it.
  if pupString.find(obStr) == -1:   
   pupString = pupString + "|"+ obStr
   typeIndex.append(obStr)
 
 print typeIndex

 # draw the menu
 result = Draw.PupMenu(pupString)
 if result == -1: # mouse out
   pass
 elif result > 0:
  #loop through all of the objects, checking the types. 
  result=result - 1 
  for ob in gObjects:
   #if the oject matches the type, then 
   if ob.getType() == typeIndex[result]:
    # select that object
    ob.select(1)

def selectObject(lookFor):
 global gObjects 
 #wack up a popup to look for stuff.
 findThis = Draw.PupStrInput("Object " + lookFor +":","",20)
 if findThis == None: return # empty string
  
 for ob in gObjects: #loop through all of the objects,
  checkMe = ob.name # take down its name
  if lookFor == "name":
   # if the name contains findThis 
   if checkMe.find(findThis) == 0:
    print "partial name found - " + checkMe
    # select it.
    ob.select(1)
  elif lookFor == "suffix":
   # i dunno, for some reason this only works right if it is != 0...?
   # non-matches being -1
   # if the name ends with findThis
   if checkMe.endswith(findThis) != 0: 
    # select it.
    ob.select(1)
  elif lookFor == "prefix":
   # if the name starts with findThis
   if checkMe.startswith(findThis) != 0:
    # select it.
    ob.select(1)
  
def selectData(lookFor):
 global gObjects
 
 #wack up a popup to look for stuff.
 findThis = Draw.PupStrInput("Data " + lookFor +":","",20)
 if findThis == None: return # empty string
 
 for ob in gObjects:
  # get the name of the data block
  checkMe = ob.getData(1)
  # if its not an empty...
  if str(type(checkMe)) != "<type 'NoneType'>":
   #find it!
   if lookFor == "name":
    if checkMe.find(findThis) == 0:
     print "partial name found - " + checkMe
     ob.select(1)
   elif lookFor == "suffix":
    # i dunno, for some reason this only works right if it is != 0...?
    # non-matches being -1
    if checkMe.endswith(findThis) != 0: 
     ob.select(1)
   elif lookFor == "prefix":
    if checkMe.startswith(findThis) != 0:
     ob.select(1)

# start of main code

global gObjects
# get the names of everything once.
gObjects=Object.Get()
         
name = "select%t|Object name contains|Object name prefix|Object name suffix|Data name contains|Data name prefix|Data name suffix|Layers|Object Types" #material names....
result = Draw.PupMenu(name)
if result == -1:
  pass
elif result == 1:
 selectObject("name")
elif result == 2:
 selectObject("prefix") 
elif result == 3:
 selectObject("suffix")
elif result == 4:
 selectData("name")
elif result == 5:
 selectData("prefix") 
elif result == 6:
 selectData("suffix")
elif result == 7:
 selectLayer()
elif result == 8:
 selectType()

I have thaught of doing this but there are a number of things blender can do alredy…

  • Select by type: Select > Select All By Type >> Camera… etc.
  • In the dataBrowser (shift+F4) you can use wildcards: *car for eg. Jest press enter and you have your selection.
    Selecting data that uses the same data as the Active is: Shift+L >> Obdata

Yours does 2 things Blender cant do-
1 Select objects that have matching layer config, Not that useful im guessing since you can do almost the same hing by setting the layer ans selecting all, Im aware its not the same thing tho.
2. Select be dataname- Selecting the same data isnt that usefull if you want to select a group of objects that use different meshes but those meshes have a name in common, not used by the object name.- You could still gety around this by copying the dataname to the object name and then using wildcards in teh databrowser, but somtimes you wont want this- So it could be usefull.

I wrote a script a while back: Select Similar mesh. you could select meshes that used a similatr number of faces/verts/face area, bounding box- Was an option for how exact to be… was quite usefull at times.

  • Your script is usefull for the 2 I have outlined but it might be worth learning C and writinhg it in that, good work all the same… Cheers - Cam

hi cam, thanks for the feedback.
I was aware that you can select objects with the databrowser, but didn’t know about wildcards or linked by the same data. Cheers for the tip :slight_smile: I imagine you could use datanames in the databrowser under the mesh or whatever directory instead of being in the object directory…the layer stuff is probably what i would use this script for, I find it a bit of a pain turning off and on layers, trying to remember what i had up before…i’m not sure if i’m up to coding it in C at the moment, since I know none at all!

Select Linked Menu could add “Same Layer” as a menu item- would be easy and some other Devs think it okay to add in.