maahee Posted 7 hours ago Posted 7 hours ago (defun c:ctf (/ bm num i obj db p1 p2 midpt point_list table pt) (setvar "osmode" 0) ; Select all lines (setq bm (ssget '((0 . "LINE")))) (if bm (progn ; Get number of lines (setq num (sslength bm)) (setq i 0) (setq point_list '()) ; Initialize list to store points ; Loop through each line (repeat num (setq obj (ssname bm i)) ; Get entity name (setq db (entget obj)) ; Get entity data (setq p1 (cdr (assoc 10 db))) ; Start point (setq p2 (cdr (assoc 11 db))) ; End point ; Calculate midpoint (setq midpt (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))) ; Store points in list (setq point_list (cons (list p1 p2 midpt) point_list)) (setq i (1+ i)) ) (setq pt (getpoint "\nSpecify table insertion point: ")) (if pt (progn ; Create table (command "._TABLE" 4 3 pt) ; Set header (command "._TABLEdit" "A1" "TEXT" "sr.no") (command "._TABLEdit" "B1" "TEXT" "Start Point") (command "._TABLEdit" "c1" "TEXT" "endPoint") (command "._TABLEdit" "D1" "TEXT" "mid Point") ; extract data of the lines and filling in cells of table ; point_list data stored ;autocad ver 2025 ) (princ "\nNo insertion point specified.") ) ) (princ "\nNo lines selected.") ) (setvar "osmode" 511) (princ) ) I need to help data automatically fill in the cells of the table table.dwg Quote
Tsuky Posted 3 hours ago Posted 3 hours ago Perhaps this ? (vl-load-com) (defun c:lines2cell ( / js AcDoc Space nw_style oldim oldlay ins_pt_cell h_t w_c lst_id-seg lst_pt n obj dxf_10 dxf_11 mid_pt nb nw_obj ename_cell n_row n_column) (princ "\nSelect points.") (while (null (setq js (ssget '((0 . "LINE"))))) (princ "\nSelection empty, or is not a lines!") ) (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)) Space (if (= 1 (getvar "CVPORT")) (vla-get-PaperSpace AcDoc) (vla-get-ModelSpace AcDoc) ) ) (cond ((null (tblsearch "LAYER" "Table-Lines")) (vla-add (vla-get-layers AcDoc) "Table-Lines") ) ) (cond ((null (tblsearch "STYLE" "Text-Cell")) (setq nw_style (vla-add (vla-get-textstyles AcDoc) "Text-Cell")) (mapcar '(lambda (pr val) (vlax-put nw_style pr val) ) (list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag) (list (strcat (getenv "windir") "\\fonts\\arial.ttf") 0.0 (/ (* 15.0 pi) 180) 1.0 0.0) ) (command "_.ddunits" (while (not (zerop (getvar "cmdactive"))) (command pause) ) ) ) ) (setq oldim (getvar "dimzin") oldlay (getvar "clayer") ) (setvar "dimzin" 0) (setvar "clayer" "Table-Lines") (initget 9) (setq ins_pt_cell (getpoint "\nLeft-Up insert point of table: ")) (initget 6) (setq h_t (getdist ins_pt_cell (strcat "\nHigth text <" (rtos (getvar "textsize")) ">: "))) (if (null h_t) (setq h_t (getvar "textsize")) (setvar "textsize" h_t)) (initget 7) (setq w_c (getdist ins_pt_cell "\nWidth of cells: ")) (setq lst_id-seg '() lst_pt '() nb 0 ) (repeat (setq n (sslength js)) (setq obj (ssname js (setq n (1- n))) dxf_10 (cdr (assoc 10 (entget obj))) dxf_11 (cdr (assoc 11 (entget obj))) mid_pt (mapcar '* (mapcar '+ dxf_10 dxf_11) '(0.5 0.5 0.5)) lst_pt (cons (list dxf_10 dxf_11 mid_pt) lst_pt) nb (1+ nb) lst_id-seg (cons nb lst_id-seg) ) ) (mapcar '(lambda (p tx) (setq nw_obj (vla-addMtext Space (vlax-3d-point p) 0.0 tx ) ) (mapcar '(lambda (pr val) (vlax-put nw_obj pr val) ) (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation) (list 5 h_t 5 p "Text-Cell" "Table-Lines" 0.0) ) ) (mapcar 'caddr lst_pt) lst_id-seg ) (vla-addTable Space (vlax-3d-point ins_pt_cell) (+ 2 nb) 10 (+ h_t (* h_t 0.25)) w_c) (setq ename_cell (vlax-ename->vla-object (entlast)) n_row (1+ nb) n_column -1) (vla-SetCellValue ename_cell 0 0 (vlax-make-variant (strcat "Summary of " (itoa (sslength js)) " LINES") 8 ) ) (vla-SetCellTextStyle ename_cell 0 0 "Text-Cell") (vla-SetCellTextHeight ename_cell 0 0 (vlax-make-variant h_t 5)) (vla-SetCellAlignment ename_cell 0 0 5) (foreach n (mapcar'list (append lst_id-seg '("N°")) (append (mapcar 'rtos (mapcar 'caar lst_pt)) '("Start X")) (append (mapcar 'rtos (mapcar 'cadar lst_pt)) '("Start Y")) (append (mapcar 'rtos (mapcar 'caddar lst_pt)) '("Start Z")) (append (mapcar 'rtos (mapcar 'caadr lst_pt)) '("End X")) (append (mapcar 'rtos (mapcar 'cadadr lst_pt)) '("End Y")) (append (mapcar 'rtos (mapcar 'caddar (mapcar 'cdr lst_pt))) '("End Z")) (append (mapcar 'rtos (mapcar 'caaddr lst_pt)) '("Middle X")) (append (mapcar 'rtos (mapcar 'cadadr (mapcar 'cdr lst_pt))) '("Middle Y")) (append (mapcar 'rtos (mapcar 'caddar (mapcar 'cddr lst_pt))) '("Middle Z")) ) (mapcar '(lambda (el) (vla-SetCellValue ename_cell n_row (setq n_column (1+ n_column)) (vlax-make-variant el 8)) (vla-SetCellTextStyle ename_cell n_row n_column "Text-Cell") (vla-SetCellTextHeight ename_cell n_row n_column (vlax-make-variant h_t 5)) (if (eq n_row 1) (vla-SetCellAlignment ename_cell n_row n_column 5) (vla-SetCellAlignment ename_cell n_row n_column 6) ) ) n ) (setq n_row (1- n_row) n_column -1) ) (setvar "dimzin" oldim) (setvar "clayer" oldlay) (prin1) ) 1 Quote
Recommended Posts
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.