Jump to content

Create Table with Blocks using Python for AutoCAD


Recommended Posts

Posted (edited)
import traceback
from pyrx import Rx, Ge, Gi, Db, Ap, Ed, command


@command(name="doit")
def justDoit():

    binfo = {}
    db = Db.curDb()
    bt = Db.BlockTable(db.blockTableId())
    for name, id in bt.asDict().items():
        btr = Db.BlockTableRecord(id)
        if btr.isAnonymous() or btr.isLayout():
            continue
        if btr.isFromExternalReference() or btr.isFromOverlayReference():
            continue
        binfo[name] = id

    table = Db.Table()
    table.setDatabaseDefaults(db)
    table.setTableStyle(db.tablestyle())
    table.setSize(len(binfo) + 2, 5)
    table.generateLayout()

    irow = 2
    icol = 0
    for name, id in binfo.items():
        table.setBlockTableRecordId(irow, icol, id, True)
        table.setTextString(irow, icol + 1, name)
        irow += 1
        icol = 0

    db.addToModelspace(table)

 

table.png.445dd2ccb83ba7166e2e8eba1400f8ea.png

Edited by Danielm103
typo

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...