Export all Blocks as PNGs with transparent background

Export all Blocks as PNGs with transparent background

bradley.wherry
Explorer Explorer
417 Views
5 Replies
Message 1 of 6

Export all Blocks as PNGs with transparent background

bradley.wherry
Explorer
Explorer

I have a series of blocks that I have created (approx 50) I would like to export them all separately as PNG files so I can use them in other software. 

 

Is there a way that I can automate this? or do it acutely and efficiently?

 

I have attached the file I have created

0 Likes
Accepted solutions (1)
418 Views
5 Replies
Replies (5)
Message 2 of 6

baksconstructor
Advocate
Advocate

Like this.

0 Likes
Message 3 of 6

Sea-Haven
Mentor
Mentor

Easy make a layout say images. Get all blocks currently in model space. insert the block into your layout, zoom

extents, then plot, erase last and keep going till all blocks are done. Erase image layout.

 

Hopefully later today.

0 Likes
Message 4 of 6

daniel_cadext
Advisor
Advisor
Accepted solution

You can do this with python.

1, you have to compute the aspect ratio, I just used 380x380 since yours is close to that.

2, Transparency is a bit of a hack, set a background color and mask it out

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback
import wx #wxPython 

@Ap.Command()
def doit():
    try:
        
        db = Db.curDb()
        bt = Db.BlockTable(db.blockTableId())
        
        for name, id in bt.toDict().items():
            btr = Db.BlockTableRecord(id)
            if btr.isLayout():
                continue
            if btr.isAnonymous():
                continue
            if name.startswith('A$'):
                continue
            
            #id imageX imageY zoom background color 
            img: wx.Image = Gs.Core.getBlockImage(id, 380, 380, 1.0, [0, 0, 0])
            img.SetMaskColour(0,0,0)
            img.SetMask(True)
            img.SaveFile("E:\\temp\\Icons\\{}.png".format(name), wx.BITMAP_TYPE_PNG)
        
    except Exception as err:
        traceback.print_exception(err)

 

tp.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 5 of 6

Sea-Haven
Mentor
Mentor

Good idea @daniel_cadext, one question to @bradley.wherry do you want all blocks in block table or just those that are used in the current dwg.

0 Likes
Message 6 of 6

bradley.wherry
Explorer
Explorer

Thanks @daniel_cadext thats a great solution. I was attempting something similar, but my coding needs some work. 

0 Likes