Description

Sélectionne les blocs en fonction d’un préfixe. Utile si les blocs sont correctement nommés, par exemple si tous les blocs de menuiserie 3D sont nommés avec le préfixe 3D - MI, ce script permet de les sélectionner simplement.

Le script suivant fonctionne sur :

  • Rhino pour Windows ;
  • Rhino pour macOS.

Script par MLAV.LAND, sous licence GNU GPL 3.

Code

import rhinoscriptsyntax as rs
 
def select_blocks_starting_with(prefix):
    rs.EnableRedraw(False)
    # Get all block definitions in the document
    block_definitions = rs.BlockNames()
    
    if block_definitions:
        for block_name in block_definitions:
            # Check if the block name starts with the specified prefix
            if block_name.startswith(prefix):
                # Get all instances (insert points) of this block definition
                block_instances = rs.BlockInstances(block_name)
                # Select each instance of the block
                for instance in block_instances:
                    rs.SelectObject(instance)
 
def main():
    # Prompt the user to enter a string
    user_input = rs.StringBox("Enter the prefix for the block names", "3D - MI", "Block Prefix")
    if user_input:
        select_blocks_starting_with(user_input)
    else:
        print("No prefix entered. Operation cancelled.")
 
if __name__ == "__main__":
    main()