Jump to content

Leaderboard

  1. GLAVCVS

    GLAVCVS

    Community Member


    • Points

      1

    • Posts

      673


  2. aridzv

    aridzv

    Community Member


    • Points

      1

    • Posts

      331


  3. Danielm103

    Danielm103

    Community Member


    • Points

      1

    • Posts

      208


  4. bbankston

    bbankston

    Community Member


    • Points

      1

    • Posts

      372


Popular Content

Showing content with the highest reputation on 04/21/2025 in Posts

  1. Nice! Autofit to the rescue! Note that PyRx has a full GUI in wxPython (wx), so you can use that instead of ctypes if you want. Then there’s also alert from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax, Brx import traceback import wx @Ap.Command() def doit(): try: wx.MessageBox("Now you have done it") Ed.Core.alert("Now you have done it") except Exception as err: traceback.print_exception(err) Welcome to Python
    1 point
  2. @Danielm103 1. about aligning the image to the center of the cell: I changed the X offset value (A process of trial and error and depends on the length of the header text): {"x_offset": 35, "y_offset": 0, "x_scale": 0.8, "y_scale": 0.8} 2. the first column was invisible because "val" for those cells was empty after the header's row and those tow lines return empty string after the first row which set the column width to 0: w, h =table.calcTextExtents(val,table.textStyle(cell.row, cell.column)) ws.set_column(cell.column,cell.column, w, cell_format) so I did this change with "autofit": else: #val = table.textString(cell.row, cell.column) #try to get a text width #w, h =table.calcTextExtents(val,table.textStyle(cell.row, cell.column)) ws.set_column(cell.column,cell.column, 1, cell_format)#minimum width,autofit wil set at the end ws.write(cell.row, cell.column, table.textString(cell.row, cell.column)) ws.autofit() wb.close() here is the final code I'm using: #https://www.cadtutor.net/forum/topic/97450-export-table-with-blocks-to-excel-with-python/ from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax, Brx import traceback import pathlib import xlsxwriter import ctypes import wx @Ap.Command() def Py_tablewithimagetoexcel_xlsxwriter(): 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)) xlpath = pathlib.Path(db.getFilename()).parent xlname = pathlib.Path(db.getFilename()).stem fpt = "{}/{}.xlsx".format(xlpath, xlname) wb = xlsxwriter.Workbook(fpt) # create workbook ws = wb.add_worksheet() # create worksheet in workbook ws.set_default_row(40) # set default row height to 39.6 cell_format = wb.add_format() # add format cell_format.set_align("center") cell_format.set_align("vcenter") table = Db.Table(id) opts = Db.TableIteratorOption.kTableIteratorSkipMerged for cell in table.cells(opts): if table.cellType(cell.row, cell.column) == Db.CellType.kBlockCell: ws.set_column(cell.column,cell.column, 15.44, cell_format) blk = table.blockTableRecordId(cell.row, cell.column) bname = getEffectiveNameFromBtrId(blk) 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, bname) img.SaveFile(imgpath, wx.BITMAP_TYPE_PNG) ws.insert_image( cell.row, cell.column, imgpath, {"x_offset": 35, "y_offset": 0, "x_scale": 0.8, "y_scale": 0.8}, ) else: #val = table.textString(cell.row, cell.column) #try to get a text width #w, h =table.calcTextExtents(val,table.textStyle(cell.row, cell.column)) ws.set_column(cell.column,cell.column, 1, cell_format)#keep format,set minimum width,autofit will set at the end ws.write(cell.row, cell.column, table.textString(cell.row, cell.column)) ws.autofit() wb.close() ctypes.windll.user32.MessageBoxW(0, fpt , "Files Saved", 1) except Exception as err: traceback.print_exception(err) def getEffectiveNameFromBtrId(btrid: Db.ObjectId): rec = Db.BlockTableRecord(btrid) if rec.isAnonymous(): ids = rec.getBlockReferenceIds() if len(ids) > 0 and Brx.DbProperties.isValid(ids[0], "EffectiveName~Native"): val = Brx.DbProperties.getValue(ids[0], "EffectiveName~Native") return val.getString() return rec.getName() Thanks for all your help!! aridzv.
    1 point
  3. (defun c:GLVScopi (/ cj cj1 n e mx my para) (if (setq cj (ssget '((0 . "*TEXT")))) (while (not para) (setq cj1 (ssadd)) (while (setq e (ssname cj (setq n (if n (1+ n) 0)))) (setq tx (cdr (assoc 1 (setq l (entget e)))) mx (if mx (min (cadr (assoc 10 l)) mx) (cadr (assoc 10 l))) my (if my (min (caddr (assoc 10 l)) my) (caddr (assoc 10 l))) ) (entmake (subst (cons 1 (strcat (chr (+ (ascii (substr tx 1 1)) 1)) (substr tx 2))) (assoc 1 l) l)) (ssadd (entlast) cj1) ) (command "_move" cj1 "" (list mx my)) (setq cj cj1 cj1 nil n nil mx nil my nil) ) ) (princ) ) @Ish I edited it from my smartphone, so I couldn't test it. Check it yourself if it works.
    1 point
  4. For those of you that are uneasy with clicking the link you can also download the attachment to this post and look at the picture below. Please help. Thanks! CIRCLE_CLOSED.dwg
    1 point
×
×
  • Create New...