Jump to content

Recommended Posts

Posted

updating samples, this one is cool

 

import traceback
from pyrx import Rx, Ge, Gs, Db, Ap, Ed
import wx
import os


# extract the image and save it
def extractThumbnailsFromDb(db: Db.Database, path: str, targetpath: str):
    path_without_extension, _ = os.path.splitext(path)
    dwgname = os.path.basename(path_without_extension)
    bt = Db.BlockTable(db.blockTableId())
    for name, id in bt.asDict().items():
        blk = Db.BlockTableRecord(id)
        if (
            blk.isLayout()
            or blk.isAnonymous()
            or blk.isFromExternalReference()
            or blk.isFromOverlayReference()
        ):
            continue
        img: wx.Image = Gs.Core.getBlockImage(id, 128, 128, 1.0, [0, 0, 0])
        img.SaveFile("{}/{}_{}_128.png".format(targetpath, dwgname, name), wx.BITMAP_TYPE_PNG)


# read the database in its own function so the database object
# gets disposed after the blocks (gc is fifo)
def extractThumbnails(path: str, targetpath: str):
    db = Db.Database(False, True)
    db.readDwgFile(path)
    db.closeInput(True)
    extractThumbnailsFromDb(db, path, targetpath)


# register a new command
# ensure the targetpath exists
@Ap.Command()
def doit():
    try:
        targetpath = "E:/temp/icons"
        os.makedirs(targetpath, exist_ok=True)
        for path in Ap.Application.listFilesInPath("E:\\temp", ".dwg"):
            extractThumbnails(path, targetpath)

    except Exception as err:
        traceback.print_exception(err)

 

icons.png.ea45b0ba849f6c3c5e8ab9cd37b50836.png

  • Like 1

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...