Creating a dimension table using Lisp

Creating a dimension table using Lisp

fgarbint
Community Visitor Community Visitor
1,368 Views
1 Reply
Message 1 of 2

Creating a dimension table using Lisp

fgarbint
Community Visitor
Community Visitor

Does anyone have a Lisp code in which i can select 1 text (not Mtext) and 2 dimensions and put it in a table such it is shown in the photo. I need it for linear dimensions.

 

 

Captura.PNG

0 Likes
1,369 Views
1 Reply
Reply (1)
Message 2 of 2

hak_vz
Advisor
Advisor

Here is a code I've written to solve your case without too much table decorating and various case testing.

 

Function CRTABLE will create new table object with title and header rows as shown in your sample.

Function TAR (Table add row) will add a row to last created table after you select an window area that encompasses drawing object with that has numbering and horizontal and vertical dimension object. Code assume that all three object exist, a text and two dim objects (if not you'll receive an error). Also dimension object shoud not have overridden original measurement.   

 

This is only a sample to show you how to code it, for anything else I would need additional information, a sample drawing ..... If you find it useful set it ass a final solution.

 

(defun c:crtable()
(vl-load-com)
(or *acdoc* (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object))))
(setq table 
    (vla-addtable
        (vla-get-modelspace *acdoc*)
        (vlax-3d-point (getpoint "\nSelect table insertion point >"))
            2           ; number of rows
            3			; number of colums
            5			; cell height
            30			; row width
    )
)
(vla-setText table 0 0 "DIMENSIONS")
(vla-setText table 1 0 "Number")
(vla-setText table 1 1 "Width")
(vla-setText table 1 2 "Length")
(princ)
)
(defun c:tar ( / p1 p2 ss nrow e ent i num wdt len )
(princ "\nAdd row to last table created with command crtable !")

(setq
    p1 (getpoint "\nSelect first corner point >")
    p2 (getcorner p1 "\nSelect second corner point >")
    ss (ssget "W" p1 p2 '((0 . "TEXT,DIMENSION")))
    newrow (vla-Get-Rows table)
    i 0
)
(repeat 3
    (setq 
        e (ssname ss i)
        ent (entget e)
        i (+ i 1)
    )        
    (cond 
        ((= (cdr (assoc 0 ent)) "TEXT") (setq num (cdr (assoc 1 ent))))
        ((= (cdr (assoc 0 ent)) "DIMENSION")
            (if (= (- (cadr (assoc 13 ent))(cadr (assoc 14 ent))) 0.0)
                (setq wdt (cdr (assoc 42 ent)))
                (setq len (cdr (assoc 42 ent)))       
            )
        )
    )
)
(vla-InsertRows table newrow 1 1)
(vla-setText table newrow 0 num)
(vla-setText table newrow 1 (rtos wdt 2 2))
(vla-setText table newrow 2 (rtos len 2 2))
(princ)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes