Description
Selects all the blocks with the same definition as the selected blocks.
Author and license
Script by Ejnar Brendsdal under MIT License.
Code
#******* Imports ********************
#************************************
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Geometry as G
#******* Main function ********************
#******************************************
def RunCommand( is_interactive ):
if sc.escape_test(False):
print "script cancelled" #do something
print "Selecting all blocks of same definition..."
#******* Get blocks *****************
#************************************
objectIds = rs.GetObjects("Pick some blocks", 4096, preselect=True)
if not objectIds:
print "No objects"
return False
#pause viewport redraw
rs.EnableRedraw(False)
#******* Sort blocks by Name ********
#************************************
blockNames = []
for id in objectIds:
blockName = rs.BlockInstanceName(id)
if blockName not in blockNames:
blockNames.append(blockName)
#******* Get block instances by name ********
#********************************************
selIds = []
for name in blockNames:
blockIds = rs.BlockInstances(name)
selIds.extend(blockIds)
#******* Select blocks **************
#************************************
rs.SelectObjects(selIds)
rs.EnableRedraw(True)
print "...aaand its done."
#End RunCommand()
#end sane
return 0
RunCommand(True) #Run script