Skip to content

Instantly share code, notes, and snippets.

@CEXT-Dan
Created November 5, 2025 22:47
Show Gist options
  • Select an option

  • Save CEXT-Dan/af910e6c1c392215deaab45f70e62dbf to your computer and use it in GitHub Desktop.

Select an option

Save CEXT-Dan/af910e6c1c392215deaab45f70e62dbf to your computer and use it in GitHub Desktop.
multiburst
# see https://github.com/CEXT-Dan/PyRx
import traceback
from pyrx import Db, Ed, Ge, Ap, Rx, Gs
import os
# add mod to path
def make_mod_path(filepath, suffix="_mod_"):
base, extension = os.path.splitext(filepath)
new_filepath = f"{base}{suffix}{extension}"
return new_filepath
# find refs named with name in modelspace
def burst(db: Db.Database, name: str):
refdesc = Db.BlockReference.desc()
attdesc = Db.AttributeDefinition.desc()
ms = db.modelSpace(Db.OpenMode.kForWrite)
refs = [Db.BlockReference(id) for id in ms.objectIds(refdesc)]
for ref in refs:
if ref.getBlockName() == name:
#map defs with values
attexp = []
parts = ref.explode()
for part in parts:
if part.isA() == attdesc:
attexp.append(Db.AttributeDefinition.cast(part))
else:
ms.appendAcDbEntity(part)
for a, b in zip(ref.attlist(), attexp):
txt = Db.Text(b.position(), a[1])
txt.setHeight(b.height())
txt.setRotation(b.rotation())
ms.appendAcDbEntity(txt)
ref.upgradeOpen()
ref.erase()
# define a new command
@Ap.Command()
def multiburst():
try:
for file in Ap.Application.listFilesInPath("E:\\temp", ".dwg"):
sdb = Db.Database(False, True)
sdb.readDwgFile(file)
sdb.closeInput(True)
burst(sdb, "RMNUM")
sdb.saveAs(make_mod_path(file))
except Exception as err:
traceback.print_exception(err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment