Leaderboard
Popular Content
Showing content with the highest reputation on 04/16/2025 in all areas
-
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)1 point
-
I was only centering the image, this version does all the modified cells You can use AcDbDatabase.getFilename to get the path, then use python’s pathlib (built in) to play with paths from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax import traceback from openpyxl.drawing.image import Image as xlImage from openpyxl.utils.cell import get_column_letter from openpyxl.styles import Alignment import openpyxl as xl import pathlib import wx @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)) #paths xlpath = pathlib.Path(db.getFilename()).parent xlname = pathlib.Path(db.getFilename()).stem wb = xl.Workbook() ws = wb.active table = Db.Table(id) opts = Db.TableIteratorOption.kTableIteratorSkipMerged for cell in table.cells(opts): # format all cells currentCell = ws.cell(cell.row + 1, cell.column + 1) currentCell.alignment = Alignment(horizontal="center", vertical="center") 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 = "{}/{}.png".format(xlpath, 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 = 64 else: ws.cell( row=cell.row + 1, column=cell.column + 1, value=table.textString(cell.row, cell.column), ) wb.save("{}/{}.xlsx".format(xlpath, xlname)) except Exception as err: traceback.print_exception(err) apparently xl has weirdness when it comes to images and alignment with regards to aspect ratio.1 point
-
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 match1 point
-
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)1 point
-
Replace AppData\Programs\Python\Python312\Lib\site-packages\pyrx\ PyRxV25.0.brx with this set the current shademode to realistic before running doit1 point
-
1 point
-
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 build1 point
-
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 plugins1 point
-
You need to wrap your changes into a loop say make a list of old new names then loop through that list. (("STYLO-1" "STYLO-PRIMARIO")("STYLO-SECUNDARIO")...) Check 1st does style exist. (setq chk (tblobjname "style" tstyle)) this will return say nil if it does not exist. (foreach sty lst (setq chk (tblobjname "style" (car sty))) (if (= chk nil) (princ "miss style") (command "_-rename" "S" (car sty) (cadr sty)) ) (princ) )1 point
-
After Enter index text, there is a possibility modify existing text based on the cursor position, but it doesn't work for inserting new text. ; a bad attempt at code modification ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) tx) ((= (strlen tx) 2) tx) (T tx)) ) (setq ind (getint "\nEnter index text: ")) ;; ??? (setq error0 *error* *error* errores) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) )) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) )) ) ) ) ) (princ) )1 point
-
As StevenP says, to request any parameter from the keyboard, consider the following: -If it's an integer: 'getint' -If it's a decimal number: 'getreal' -If it's a text string: 'getstring' The advantage of using 'getint' or 'getreal' (as appropriate) is that the function itself will prevent the user from entering data that doesn't match the expected type. However, if you use 'getstring', any data entered will be considered a text string and will need to be converted. In this case, if the user had mistakenly entered a string beginning with a non-numeric character (for example, "y734"), converting it with 'atoi' or 'atof' would return 0. Therefore, it's advisable to use the 'get...' functions appropriately.1 point
-
1 point
-
Why not something different...? ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:txtIncrem (/ tam capa ind para a txsel lstent le l s dameTexto errores error0) (defun errores (mens) (setq *error* error0) (prin1) ) (defun dameTexto (/ tx) ;;; WRITE HERE THE CODE YOU NEED TO CUSTOMIZE THE TEXT YOU WANT TO ENTER OR CREATE (cond ((= (strlen (setq tx (itoa (setq ind (+ ind 1))))) 1) (strcat "00" tx) ) ((= (strlen tx) 2) (strcat "0" tx) ) (T tx) ) ) (while (not para) (if (setq ent (car (entsel "\nSelect index text..."))) (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "TEXT") (if (wcmatch (setq ind (cdr (assoc 1 lstent))) "#,##,###,####") (setq ind (atoi ind) capa (cdr (assoc 8 lstent)) a (cdr (assoc 40 lstent)) para T) (princ "\n*** The selected object is not valid. Please, try again... ***") ) ) (setq para T) ) ) (setq error0 *error* *error* errores ) (setq tam (* (getvar "pickbox") (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE")))) para nil) (princ "\nSelect text to modify or insert new text (RIGHT CLICK for exit)...") (while (and (setq l (grread T (if s 4 13) (if s 2 0))) (member (car l) '(5 3))) (if (setq s (ssget "_C" (list (- (car (setq p (cadr l))) tam) (- (cadr p) tam)) (list (+ (car p) tam) (+ (cadr p) tam)) (list (cons 0 "TEXT")) ) ) (cond ((= (car l) 3) (entmod (subst (cons 1 (dameTexto)) (assoc 1 (setq le (entget (ssname s 0)))) le)) ) ;Here are other possible cases ) (cond ((= (car l) 3) (entmake (list '(0 . "TEXT") (cons 8 capa) (cons 40 a) (cons 1 (dameTexto)) (cons 10 (list (car p) (cadr p) 0.0)) ) ) ) ;Here are other possible cases ) ) ) (princ) )1 point
-
1 point