All Activity
- Past hour
-
George4414 joined the community
- Today
-
Isaac26a started following Why is DXF code 10 different from the Start Point in Properties for an ARC and CIRCLE
-
Why is DXF code 10 different from the Start Point in Properties for an ARC and CIRCLE
Isaac26a replied to p7q's topic in AutoLISP, Visual LISP & DCL
I'm not sure if I got pretty late to the party but hope this helps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;; Program masp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Program to Modify an Arc's Start Point ;;; ;;; 20250416 V1.0 Created ;;; ;;; ;;; ;;; ;;; ;;; By Isaac A. ;;; ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vl-load-com) (defun c:masp (/ a b c d dw) ; (vl-cmdf "_.undo" "_begin") (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object)))) (setvar 'cmdecho 0) (setq a (car (entsel "\nSelect the arc to modify: \n")) b (cdr (assoc 10 (entget a))) ) (setq c (getpoint "\nSelect the new start point: ") d (angle b c) ) (entmod (subst (cons 50 d) (assoc 50 (entget a)) (entget a))) (setq c (getpoint "\nSelect the new end point: ") d (angle b c) ) (entmod (subst (cons 51 d) (assoc 51 (entget a)) (entget a))) ; (vl-cmdf "_.undo" "_end") (vla-endundomark dw) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; End of file ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If for any reason you don't want to use any vla commands you can replace the vla with the ones with the semicolon (vl-cmdf ...) -
export table with blocks to excel with Python
Danielm103 replied to Danielm103's topic in .NET, ObjectARX & VBA
Was this a question for me? the code translation would be https://help.autodesk.com/view/OARX/2025/ENU/?guid=GUID-4F19B20D-BF8C-4505-A13A-4B6102778E24 import traceback from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax @Ap.Command() def dtop(): try: axApp = Ap.Application.acadApplication() axApp.loadDVB("c:/drawline.dvb") axApp.runMacro("Module1.Drawline") except Exception as err: traceback.print_exception(err) That would be great, you know since its open source, I (we) could always use input from a master -
SJJ joined the community
-
Danielm103 changed their profile photo
-
Elements of a Python module for Cad
Danielm103 replied to Danielm103's topic in .NET, ObjectARX & VBA
In Python, ent is a smart pointer, almost exactly like its C++ counterpart ent = Db.Entity(id, Db.OpenMode.kForWrite) AcDbEntityPointer pEnt(eid, AcDb::OpenMode::kForWrite); ent is closed when it goes out of scope An actual wrapper PyDbEntity::PyDbEntity(const PyDbObjectId& id) : PyDbObject(openAcDbObject<AcDbEntity>(id, AcDb::OpenMode::kForRead), false) { } PyDbEntity::PyDbEntity(const PyDbObjectId& id, AcDb::OpenMode mode) : PyDbObject(openAcDbObject<AcDbEntity>(id, mode), false) { } PyDbEntity::PyDbEntity(const PyDbObjectId& id, AcDb::OpenMode mode, bool erased) : PyDbObject(openAcDbObject<AcDbEntity>(id, mode, erased), false) { } -
Elements of a Python module for Cad
Danielm103 replied to Danielm103's topic in .NET, ObjectARX & VBA
Next, choose your style, ARX vs AX Ax is ActiveX, the coding style most Lisp or VB(A) users are used to. You don’t need to manage an open close state for the objects. Perfect for quick scripts ARX style, you pass around collections of ObjectIds, in which you open objects with. In this style you may have to manage open close state. Python will help you manage this along the way. Unlike .NET, you don’t need to use transactions, you don’t need to use a transaction to open objects then cast, there's no commit, Just pass the id and the open state. Python will do all the closing for you import traceback from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax @Ap.Command() def py_arx_vs_ax(): try: # for VBA users axApp = Ap.Application.acadApplication() axDoc = axApp.activeDocument() axSpace = axDoc.modelSpace() for ent in axSpace: ent.setLayer("0") # ARX users cdoc = Ap.curDoc() db = Db.curDb() space = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForRead) for id in space: ent = Db.Entity(id, Db.OpenMode.kForWrite) ent.setLayer("0") except Exception as err: traceback.print_exception(err) -
Danielm103 started following Elements of a Python module for Cad
-
import traceback from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax @Ap.Command() def mynewcommand(): try: print("\nhello world!") except Exception as err: traceback.print_exception(err) So, you’ve decided to take the red pill. from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax You can think of these as similar to .NET references, or name spaces. Ge = AcGe from ObjectArx, Ax = ActiveX @Ap.Command() Tells the system to register a new command, you can also register lisp functions, so you can use python to help extend lisp (more on that later) Body of the function. Command functions should have a try catch to prevent python exceptions from escaping into C++, it’s not the end of the world if it happens, but it’s advised. You don’t need to have try catches in your subroutines. print("\nhello world!") Since Python is now running in CAD’s process, I have redirected Python’s std_out to AutoCAD’s command line. Yay! Stuff like this is forbidden lol! Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage Just print will do
-
@BIGAL Hi. No, I was busy with the python code that @Danielm103 posted and also I created other way to do this task with tow VBA code modules, one run inside the cad software exporting the images to .png files and the second run from within Excel importing them to the spreadsheet. so I was quite busy... but that other issue of Excel leave a ghost process in the task manager is still there, The code to unload it you gave in the other place didn't solve it unfortunately... I'll try to give it a look in the coming days. Aridzv.
-
export table with blocks to excel with Python
BIGAL replied to Danielm103's topic in .NET, ObjectARX & VBA
Thanks @Danielm103 for the instructions about running python in Bricscad. may give it a try. What is corrrect syntax for python, did see open BricsCAD, type in “pyload”, load your module, run your new command (defun C:dtop () (vl-vbaload "P:/AutoDESK/VBA/xxx filecopy.dvb") (vl-vbarun "xxxfilecopy") ) -
Copy multiple text and paste automatically add alphabet.
BIGAL replied to Ish's topic in AutoLISP, Visual LISP & DCL
Just a comment, using ssget may end up with A1 A3 A2 as order as ssget gets in creation order, may still be better to do pick pick. Does the number go above 26 ? If so this is helpful based on Excel columns. ; Number2Alpha - Converts Number into Alpha string ; Function By: Gilles Chanteau from Marseille, France ; Arguments: 1 ; Num# = Number to convert ; Syntax example: (Number2Alpha 731) = "ABC" (NUMBER2ALPHA 1) "A" (NUMBER2ALPHA 27) "AA" -
export table with blocks to excel with Python
Danielm103 replied to Danielm103's topic in .NET, ObjectARX & VBA
I found this https://stackoverflow.com/questions/13197574/openpyxl-adjust-column-width-size new code 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), ) #nested function def as_text(value): if value is None: return "" return str(value) # make another pass to set the widths + a little extra for column_cells in ws.columns: length = max(len(as_text(cell.value)) for cell in column_cells) ws.column_dimensions[column_cells[0].column_letter].width = length * 1.25 wb.save("{}/{}.xlsx".format(xlpath, xlname)) except Exception as err: traceback.print_exception(err) -
-
Did you test my code worked for me and I tested in Bricscad. I am sure @Danielm103 will advise on how to load the Python run time needed.
- Yesterday
-
Extracting data to excel from selected objects on different layers
BIGAL replied to Hsanon's topic in AutoLISP, Visual LISP & DCL
Try this ;https://www.cadtutor.net/forum/topic/74256-extracting-data-to-excel-from-selected-objects-on-different-layers/page/2/ ; pick object and send result to Excel. ; BY AlanH March 2025 (defun c:obs2XL ( / dopline doline plent myxl typ ent) (defun dopline (plent / start closed XY ) (setq row (1+ row)) (xlsetcelltext row 1 (vlax-get plent 'Objectname)) (xlsetcelltext row 2 (vlax-get plent 'Layer)) (xlsetcelltext row 3 (vlax-get plent 'Color)) (setq start (vlax-curve-getstartPoint plent)) (setq XY (strcat (rtos (car start) 2 2) "," (rtos (cadr start) 2 2) "," (rtos (caddr start) 2 2))) (xlsetcelltext row 4 xy) (xlsetcelltext row 5 (vlax-get plent 'length)) (xlsetcelltext row 6 (vlax-get plent 'Linetype)) (xlsetcelltext row 7 (vlax-get plent 'area)) (setq closed (vlax-get plent 'closed)) (if (= closed -1) (xlsetcelltext row 8 "Yes") (xlsetcelltext row 8 "No") ) (princ) ) (defun doline (plent / startpt xy) (setq row (1+ row)) (xlsetcelltext row 1 (vlax-get plent 'Objectname)) (xlsetcelltext row 2 (vlax-get plent 'Layer)) (xlsetcelltext row 3 (vlax-get plent 'Color)) (setq startpt (vlax-curve-getstartPoint plent)) (setq XY (strcat (rtos (car startpt) 2 2) "," (rtos (cadr startpt) 2 2) "," (rtos (cadr startpt) 2 2))) (xlsetcelltext row 4 xy) (xlsetcelltext row 5 (rtos (vlax-get plent 'length) 2 2)) (xlsetcelltext row 6 (vlax-get plent 'Linetype)) ) ; starts here (setq myxl1 (vlax-get-object "Excel.Application")) (if (= myxl1 nil) (setq myxl (vlax-get-or-create-object "excel.Application")) (setq myxl myxl1) ) (vla-put-visible myXL :vlax-true) (vlax-put-property myxl 'ScreenUpdating :vlax-true) (vlax-put-property myXL 'DisplayAlerts :vlax-true) (vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add) ;; Thanks to fixo ;; = Set Excel cell text = ;; (defun xlsetcelltext ( row column text) (setq cells (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Cells")) (vl-catch-all-apply 'vlax-put-property (list cells 'Item row column (vlax-make-variant (vl-princ-to-string text) vlax-vbstring))) ) (setq row 1 col 0) (foreach val (list "Name" "Layer" "Color" "X,Y,Z" "Length" "Linetype" "Area" "Closed") (xlsetcelltext row (setq col (1+ col)) val) ) (foreach val (list (list "A1" 15) (list "B1" 15) (list "D1" 27)) (vlax-put-property (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Range" (car val)) 'columnwidth (cadr val)) ) (setq ss (SSget (list (cons 0 "*line")))) (if (= ss nil) (progn (alert "you have no lines or plines selected will exit ")(exit)) ) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x))))) (setq typ (vlax-get obj 'ObjectName)) (cond ((= typ "AcDbPolyline")(dopline obj)) ((= typ "AcDbLine")(doline obj)) ) ) (if (not (vlax-object-released-p myXL))(progn(vlax-release-object myXL)(setq myXL nil))) (princ) ) -
My $0.05, I would add a width to the edit boxes as they are all over the place. mc_dialog : dialog { label = "NHAP THONG SO MAT CAT DOC"; : column { : edit_box { label = "Ty le ngang 1/?"; key = "hf"; } : edit_box { label = "Ty le dung 1/?"; key = "vf"; } : edit_box { label = "Cao do so sanh (m)"; key = "level"; } : edit_box { label = "Ly trinh diem dau (m)"; key = "st"; } : edit_box { label = "Chieu cao Text Title"; key = "th"; } : edit_box { label = "Chieu cao Text cao do"; key = "th1"; } : edit_box { label = "File du lieu TXT"; key = "file"; } : button { label = "Chon File..."; key = "chonfile"; } } : row { : button { label = "Ve"; is_default = true; key = "accept"; } : button { label = "Thoat"; key = "cancel"; } } } Have a look at writing the dcl as part of the lisp code, you use write line and the (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) to write a temporary file just delete the file at end of dcl use. Have a look at Multi getvals.lsp will write a dcl for you based on a list of edit boxes. Around 3 lines of code to make a dcl. You can set file name so can see the dcl code. Then use the rlx code to make lisp code. Convert dcl 2 lisp rlx.lspMulti GETVALS.lsp
-
AllanR joined the community
-
export table with blocks to excel with Python
aridzv replied to Danielm103's topic in .NET, ObjectARX & VBA
-
export table with blocks to excel with Python
aridzv replied to Danielm103's topic in .NET, ObjectARX & VBA
Yes... Align the image within the cell.. It's strange that there is no way to determine the position of the image relative to the cell. But in any case this is a great program, many Thanks!!! aridzv. -
export table with blocks to excel with Python
aridzv replied to Danielm103's topic in .NET, ObjectARX & VBA
@Danielm103 thanks... I got as far as load "pathlib" and tried to work with it before you post your comment... see the (poor..) attemptes I did: from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax import traceback import wx # wxPython import openpyxl as xl import pyautocad from pathlib import Path from openpyxl.drawing.image import Image as xlImage from openpyxl.utils.cell import get_column_letter from openpyxl.styles import Alignment #--------------------- @Ap.Command() def doit2(): try: a="this is best" b="no" c=a+b print(c) axApp = Ap.Application.acadApplication() axDoc = axApp.activeDocument() #acad = pyautocad.Autocad() print(axDoc.name) #print(acad.doc.Name) #p = Path(__file__).resolve() #p = Path(axDoc).resolve() #print(p) is there a way to set the column width like you set the row height: ws.row_dimensions[cell.row + 1].height = 64 thanks, aridzv -
export table with blocks to excel with Python
Danielm103 replied to Danielm103's topic in .NET, ObjectARX & VBA
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. -
;; PurgeImages.lsp by Trevor Bird ;; Removes Unreferenced Images ;; 2021-02-20 ;;------------------------------------------------------------------------------ (defun purgeimages ( / ACAD_IMAGE_DICT__dxf ACAD_IMAGE_DICT__ename ACAD_REACTORS__dxf assoc_330 count_imagedef count_imageref count_purged dps_3 dps_330 entity_dxf entity_ename entity_type imagedef_dxf imagedef_ename ImageFile imageref_dxf imageref_ename list_ImageNames ) (setq count_purged 0) (cond ( (not (setq ACAD_IMAGE_DICT__dxf (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")))) ( (not (setq ACAD_IMAGE_DICT__ename (cdr (assoc -1 ACAD_IMAGE_DICT__dxf))))) ;; dps_3 = xrecord names = image names ( (not (setq dps_3 (vl-remove-if-not '(lambda ( _dp ) (= (car _dp) 3)) ACAD_IMAGE_DICT__dxf)))) ;; List of xrecord names = list of image Names ( (not (setq list_ImageNames (mapcar 'cdr dps_3)))) (list_ImageNames (foreach fe__ImageName list_ImageNames (setq imagedef_dxf (dictsearch ACAD_IMAGE_DICT__ename fe__ImageName) imagedef_ename (cdr (assoc -1 imagedef_dxf)) ImageFile (cdr (assoc 1 imagedef_dxf)) );setq (cond ( (not (setq ACAD_REACTORS__dxf (member '(102 . "{ACAD_REACTORS") imagedef_dxf)))) ( (not (setq ACAD_REACTORS__dxf (reverse (member '(102 . "}") (reverse ACAD_REACTORS__dxf))) dps_330 (vl-remove-if-not '(lambda ( _dp ) (= (car _dp) 330)) ACAD_REACTORS__dxf) );setq );not ); (dps_330 (setq count_imagedef 0 count_imageref 0 );setq (foreach fe__dp dps_330 (setq entity_ename (cdr fe__dp) entity_dxf (entget entity_ename) entity_type (cdr (assoc 0 entity_dxf)) );setq (cond ( (not (= entity_type "IMAGEDEF_REACTOR"))) ( (not (setq count_imagedef (1+ count_imagedef)))) ;; 330 - Object ID for associated image object (image reference) ( (not (setq assoc_330 (assoc 330 entity_dxf)))) (assoc_330 (setq imageref_ename (cdr assoc_330) imageref_dxf (entget imageref_ename) );setq (cond ( (not imageref_dxf) ;; Image reference was deleted. );(not imageref_dxf) (imageref_dxf (setq count_imageref (1+ count_imageref)) );imageref_dxf );cond );assoc_330 );cond );fe__dp (if (zerop count_imageref) (progn ;; Delete image definition xrecord. (setq count_purged (1+ count_purged)) (entdel imagedef_ename) (dictremove ACAD_IMAGE_DICT__ename fe__ImageName) (princ "\nDeleting image ") (prin1 fe__ImageName) (princ ".") );progn );if );dps_330 );cond` );fe__ImageName );list_ImageNames );cond (cond ( (not (zerop count_purged)) (princ "\n") (prin1 count_purged) (if (> count_purged 1) (princ " images ") (princ " image ") );if (princ "deleted.") );(not (zerop count_purged)) ( (zerop count_purged) (princ "\nNo unreferenced images found.") );(zerop count_purged) );cond (princ) ) ;c:purgeimages
-
Does anyone have the Windows 3.1 drivers, engine software, or ADF file for this card? https://ardent-tool.com/video/Nth_Double_Edge.html
-
Hello Replace the 4 * with ?
-
Alextan3906 joined the community
-
Changed the code to: (setq drawingName (getvar "DWGNAME")) (setq prefix (substr drawingName 1 4)) ;; Construct the xref file path (setq xrefPath (strcat xrefPath prefix "-CP-SITE-BASE.dwg")) and this seems to be working!
-
I’m working on a lips to add an xref to a drawing. The filename begins with a 4 letter project designator that changes but the rest of the name is static. I’m using * as wildcards but it’s not working. For filename I have: (setq wildcard "****-CP-SITE-BASE.dwg") ; Define the wildcard pattern to match xref names (setq xrefFiles (vl-directory-files xrefPath wildcard 1)) ; Get a list of xref files matching the wildcard (foreach xref xrefFiles (setq xrefFile (strcat xrefPath wildcard)) (command "_.-XREF" "Attach" xrefFile "0,0,0" "1" "1" "0") When I run it, I get this error: Error: "..\01_Basefiles\****-CP-SITE-BASE.dwg" is not a valid file name. *Invalid* ; error: Function cancelled I'd appreciate any help, Thanks
-
pkenewell started following Copy multiple text and paste automatically add alphabet.
-
Copy multiple text and paste automatically add alphabet.
pkenewell replied to Ish's topic in AutoLISP, Visual LISP & DCL
@Ish Have you looked at these from the great Lee Mac? https://www.lee-mac.com/incrementalarray.html https://www.lee-mac.com/numinc.html -
export table with blocks to excel with Python
aridzv replied to Danielm103's topic in .NET, ObjectARX & VBA
@Danielm103 and one last question: how do I set the save path to the drawing folder automatically? like using the "DWGPREFIX" in lisp? -
export table with blocks to excel with Python
aridzv replied to Danielm103's topic in .NET, ObjectARX & VBA
@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.