Jump to content

Recommended Posts

Posted

table.thumb.png.6dcf696cc0dc67c4cb75e06be839a033.png

 

 

 

 

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback
import wx  # wxPython
import openpyxl as xl
from openpyxl.drawing.image import Image as xlImage
from openpyxl.utils.cell import get_column_letter


@Ap.Command()
def doit():
    try:

        db = Db.curDb()

        ps, id, _ = Ed.Editor.entSel("\nSelect a table: ", Db.Table.desc())
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps))

        wb = xl.Workbook()
        ws = wb.active

        table = Db.Table(id)
        opts = Db.TableIteratorOption.kTableIteratorSkipMerged
        for cell in table.cells(opts):
            if table.cellType(cell.row, cell.column) == Db.CellType.kBlockCell:
                blk = table.blockTableRecordId(cell.row, cell.column)
                img: wx.Image = Gs.Core.getBlockImage(blk, 64, 64, 1.0, [0, 0, 0])
                img.SetMaskColour(0, 0, 0)
                img.SetMask(True)
                imgpath = "E:\\temp\\Icons\\{}.png".format(blk.handle())
                img.SaveFile(imgpath, wx.BITMAP_TYPE_PNG)
                xlimg = xlImage(imgpath)
                xlimg.width = 64
                xlimg.height = 64
                cellref = "{}{}".format(get_column_letter(cell.column + 1), cell.row + 1)
                ws.add_image(xlimg, cellref)
            else:
                ws.cell(
                    row=cell.row + 1,
                    column=cell.column + 1,
                    value=table.textString(cell.row, cell.column),
                )
        wb.save("E:\\temp\\logo.xlsx")
    except Exception as err:
        traceback.print_exception(err)

 

  • Like 1
  • Thanks 1
Posted (edited)
2 hours ago, Danielm103 said:

table.thumb.png.6dcf696cc0dc67c4cb75e06be839a033.png

 

 

 

 

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback
import wx  # wxPython
import openpyxl as xl
from openpyxl.drawing.image import Image as xlImage
from openpyxl.utils.cell import get_column_letter


@Ap.Command()
def doit():
    try:

        db = Db.curDb()

        ps, id, _ = Ed.Editor.entSel("\nSelect a table: ", Db.Table.desc())
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps))

        wb = xl.Workbook()
        ws = wb.active

        table = Db.Table(id)
        opts = Db.TableIteratorOption.kTableIteratorSkipMerged
        for cell in table.cells(opts):
            if table.cellType(cell.row, cell.column) == Db.CellType.kBlockCell:
                blk = table.blockTableRecordId(cell.row, cell.column)
                img: wx.Image = Gs.Core.getBlockImage(blk, 64, 64, 1.0, [0, 0, 0])
                img.SetMaskColour(0, 0, 0)
                img.SetMask(True)
                imgpath = "E:\\temp\\Icons\\{}.png".format(blk.handle())
                img.SaveFile(imgpath, wx.BITMAP_TYPE_PNG)
                xlimg = xlImage(imgpath)
                xlimg.width = 64
                xlimg.height = 64
                cellref = "{}{}".format(get_column_letter(cell.column + 1), cell.row + 1)
                ws.add_image(xlimg, cellref)
            else:
                ws.cell(
                    row=cell.row + 1,
                    column=cell.column + 1,
                    value=table.textString(cell.row, cell.column),
                )
        wb.save("E:\\temp\\logo.xlsx")
    except Exception as err:
        traceback.print_exception(err)

 

 

YES!!!

quite impressive i must say.

 

now,

how do I run this code (Python, right?)  in autocad\bricscad?......😁😵‍💫

 

thanks,

 

Edited by aridzv
Posted

Sorry, I noticed your running BricsCAD 2021? If so, I’m sorry to say only v24-v25 is supported.

Or maybe you forgot to update your profile?

 

1, head over to https://github.com/CEXT-Dan/PyRx?tab=readme-ov-file#installation and have look at the project

 

2, Download and install 3.12.10 x64 from https://www.python.org/downloads/windows/  (all users is NOT checked, and PATH is checked)

 

3, Open up PowerShell and type “pip install cad-pyrx” without the quotes.    

 

4, in BricsCAD, type “appload”, navigate to:  “AppData\Programs\Python\Python312\Lib\site-packages\pyrx\RxLoaderV25.0.brx”

 

5, Make sure it’s loaded, type “pyload” at the bricscad prompt

 

6, if the load dialog box shows, then were successful so far

 

7, close bricscad

 

8, back in powershell type  “pip install openpyxl” , this will install the excel library.

 

9, copy paste the sample code above into a file into a text file, “myfirstmodule.py”

 

10, using a text editor, edit the paths in the sample, maybe rename the “doit” command

 

11, open BricsCAD, type in “pyload”, load your module, run your new command

 

If you get this far, you might want to grab a python editor like VsCode and install the python plugins  

 

  • Like 2
Posted

@Danielm103

I'm working with V25.2.05.

thanks for the guide.

I'll work on it and if I'll have questions I'll be back...😁

 

thanks!!

aridzv

Posted

@Danielm103

Hi.

after doing all I get this massege after running "doit":

 File "c:\users\aridzv\appdata\local\programs\python\python312\Lib\site-packages\openpyxl\drawing\image.py", line 13, in _import_image
    raise ImportError('You must install Pillow to fetch image objects')
ImportError: You must install Pillow to fetch image objects

 

also see attached screenshot.

what am I doing wrong?

 

aridzv.

Screenshot 2025-04-16 162729.jpg

Posted (edited)

pip install pillow

 

you will need to restart bricscad

Edited by Danielm103
Posted

 

I also noticed I had a BricsCAD support request

 

SR 180584 AcGsView::getSnapShot does not pickup shademode, so the icons will come out wireframe.

But, I made a work around.. I'll make a build

  • Like 1
Posted (edited)

ignore.

changed the path in the code

Edited by aridzv
Posted (edited)

ignore....

changed the path in the code

Edited by aridzv
  • Like 1
Posted

you missed, 10, edit the paths


 

Quote

 

imgpath = "E:\\temp\\Icons\\{}.png".format(blk.handle())

wb.save("E:\\temp\\logo.xlsx")

 

 

just make a folder c:\\temp and do


 

Quote

 

imgpath = "C:\\temp\\{}.png".format(blk.handle())

wb.save("C:\\temp\\logo.xlsx")

 

 

Posted (edited)

 

 

Replace AppData\Programs\Python\Python312\Lib\site-packages\pyrx\ PyRxV25.0.brx

 

with this

 

set the current shademode to realistic before running doit

Edited by Danielm103
remove file, will update the package
  • Thanks 1
Posted (edited)

@Danielm103

ignore...

again...😁

I fixed the path as you wrote.

 

its working good with shade visual style.

 

another question:

is it possible to set the rows hight to a value of 60 for example?

 

edit:

and set the cell alignment to middle-center?

Edited by aridzv
Posted

did you create folder(s) did you see my note above?

 

change the code to something like, make sure the folder exists and you have write permissions
 

Quote

 

imgpath = "C:\\temp\\{}.png".format(blk.handle())

wb.save("C:\\temp\\logo.xlsx")

 

 

Posted
7 minutes ago, Danielm103 said:

did you create folder(s) did you see my note above?

 

change the code to something like, make sure the folder exists and you have write permissions
 

 

yes,eventually...

my bad.

Posted
14 minutes ago, aridzv said:

 

is it possible to set the rows hight to a value of 60 for example?

 ws.add_image(xlimg, cellref)

 ws.row_dimensions[ cell.row + 1].height = 64  ##add this line

Posted

add alignment

 

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback
import wx  # wxPython
import openpyxl as xl
from openpyxl.drawing.image import Image as xlImage
from openpyxl.utils.cell import get_column_letter
from openpyxl.styles import Alignment #---------------------


@Ap.Command()
def doit():
    try:

        db = Db.curDb()

        ps, id, _ = Ed.Editor.entSel("\nSelect a table: ", Db.Table.desc())
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps))

        wb = xl.Workbook()
        ws = wb.active

        table = Db.Table(id)
        opts = Db.TableIteratorOption.kTableIteratorSkipMerged
        for cell in table.cells(opts):
            if table.cellType(cell.row, cell.column) == Db.CellType.kBlockCell:
                blk = table.blockTableRecordId(cell.row, cell.column)
                img: wx.Image = Gs.Core.getBlockImage(blk, 64, 64, 1.0, [0, 0, 0])
                img.SetMaskColour(0, 0, 0)
                img.SetMask(True)
                imgpath = "E:\\temp\\Icons\\{}.png".format(blk.handle())
                img.SaveFile(imgpath, wx.BITMAP_TYPE_PNG)
                xlimg = xlImage(imgpath)
                xlimg.width = 64
                xlimg.height = 64
                cellref = "{}{}".format(get_column_letter(cell.column + 1), cell.row + 1)
                ws.add_image(xlimg, cellref)
                ws.row_dimensions[ cell.row + 1].height = 60
                currentCell = ws.cell(cell.row + 1,cell.column + 1)#---------------------
                currentCell.alignment = Alignment(horizontal='center',vertical='center')#---------------------
            else:
                ws.cell(
                    row=cell.row + 1,
                    column=cell.column + 1,
                    value=table.textString(cell.row, cell.column),
                )
        wb.save("E:\\temp\\logo.xlsx")
    except Exception as err:
        traceback.print_exception(err)

 

  • Like 1
Posted

also, you can change the icon size

 

#id width, height, zoom, RGB

img: wx.Image = Gs.Core.getBlockImage(id, 64, 64, 1.0, [0, 0, 0])

 

could be 128 128, you'll need to change the cell size to match

  • Like 1
Posted

@Danielm103

GREAT!!!

 

question about autoload the file:

I inserted in to my "on_start.lsp" and "on_doc_load.lsp" files this code:

(SETVAR "FILEDIA" 0)
(command "pyload" "C:\\Users\\AridZv\\AppData\\Roaming\\Bricsys\\BricsCAD\\Lsp\\Python\\TableWimagetoExcel.py")
(SETVAR "FILEDIA" 1)

 

now,

if I open I file from the "welcome" screen it dosn't load.

if I then open other file it is loading.

any idea on why (probebally...) the "on_start.lsp" don't take effect?

Posted

try this,

Make a file pyrx_onload.py

Make sure the file is in a search path, maybe in the same folder as "on_start.lsp" and "on_doc_load.lsp"

 

guts

from pyrx import Ap

Ap.Application.loadPythonModule(
    "C:\\Users\\AridZv\\AppData\\Roaming\\Bricsys\\BricsCAD\\Lsp\\Python\\TableWimagetoExcel.py"
)

 

Posted

@Danielm103

for some reason the alignment don't take effect.

the row hight dose.

 

here is the code that i'm usuing:

 

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback
import wx  # wxPython
import openpyxl as xl
from openpyxl.drawing.image import Image as xlImage
from openpyxl.utils.cell import get_column_letter
from openpyxl.styles import Alignment #---------------------


@Ap.Command()
def doit1():
    try:

        db = Db.curDb()

        ps, id, _ = Ed.Editor.entSel("\nSelect a table: ", Db.Table.desc())
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps))

        wb = xl.Workbook()
        ws = wb.active

        table = Db.Table(id)
        opts = Db.TableIteratorOption.kTableIteratorSkipMerged
        for cell in table.cells(opts):
            if table.cellType(cell.row, cell.column) == Db.CellType.kBlockCell:
                blk = table.blockTableRecordId(cell.row, cell.column)
                img: wx.Image = Gs.Core.getBlockImage(blk, 64, 64, 1.0, [0, 0, 0])
                img.SetMaskColour(0, 0, 0)
                img.SetMask(True)
                imgpath = "C:\\temp\\{}.png".format(blk.handle())
                img.SaveFile(imgpath, wx.BITMAP_TYPE_PNG)
                xlimg = xlImage(imgpath)
                xlimg.width = 64
                xlimg.height = 64
                cellref = "{}{}".format(get_column_letter(cell.column + 1), cell.row + 1)
                ws.add_image(xlimg, cellref)
                ws.row_dimensions[ cell.row + 1].height = 60
                currentCell = ws.cell(cell.row + 1,cell.column + 1)#---------------------
                currentCell.alignment = Alignment(horizontal='center',vertical='center')#---------------------
            else:
                ws.cell(
                    row=cell.row + 1,
                    column=cell.column + 1,
                    value=table.textString(cell.row, cell.column),
                )
        wb.save("C:\\temp\\logo.xlsx")
    except Exception as err:
        traceback.print_exception(err)

 

if you could help with the alignment it whould be grate.

 

thanks,

aridzv.

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