Prefix all block names

Hello all,
I’d like to add a prefix to all block names in a file, either with custom string or the file name.
Could some one help give me some pointers in how to do that in python?
Many thanks

Something like this perhaps?

import rhinoscriptsyntax as rs

def AddPrefixToBlkNames():
    blk_names=rs.BlockNames()
    if not blk_names: return
    
    prefix=rs.StringBox("Prefix to add")
    if prefix is None: return
    
    for blk_name in blk_names: rs.RenameBlock(blk_name,prefix+blk_name)
AddPrefixToBlkNames()

AddPrefixToBlkNames.py (302 Bytes)

2 Likes

Excellent - thanks!