Extract Rectangle Dimension To Table (Count & Numbering)

Extract Rectangle Dimension To Table (Count & Numbering)

AlexR7UZ2
Explorer Explorer
8,309 Views
56 Replies
Message 1 of 57

Extract Rectangle Dimension To Table (Count & Numbering)

AlexR7UZ2
Explorer
Explorer

Hi,

 

First off I have little to no experience reading/editing a LISP. I'm trying to see if its possible to combine these two LISPS attached to get what I'm looking for. The AreaLabelV1-9.1 is a great lisp. Unfortunately, it doesn't account for duplicates to create a count # for picked areas or objects like the rectangle_dims LISP does. I need it to have the ability to consolidate duplicate areas so I don't have multiples in the table. 

I'd appreciate any help/advice.🤓

 

-Me

 

0 Likes
8,310 Views
56 Replies
Replies (56)
Message 41 of 57

Sea-Haven
Mentor
Mentor

Updated code above. Post 34. Trying to keep just last version posted. Will add some more later on on start with blank dwg.

Message 42 of 57

ancrayzy
Advocate
Advocate

Thank you so much @Sea-Haven , it's work perfect.

It's better if it can be sorted by layer, but I can handle that in Excel and will figure out how to do it later. Your help has already taken up so much of your time.

I sincerely appreciate all your help.

0 Likes
Message 43 of 57

Sea-Haven
Mentor
Mentor

Ok will have a look again so select all rectangles but make 1 table.

 

; resort here lst3 based on layer name and other values can do up to 5 values deep.
(foreach val lst3
Message 44 of 57

r2GAUUS
Community Visitor
Community Visitor

I am working on curtainwall shop drawing task in which I need to give unique number and need to make table with area and dimension of each glass panel, and this is useful to me.
But Is it Possible to Add Number with Prefix and Suffix (for example GL1-1,GL1-2,GL1-3) Automatically instead of just 1, 2, 3 ,4..... type number?
Can you please help with this?

0 Likes
Message 45 of 57

Sea-Haven
Mentor
Mentor

Something like this, but add a label to each panel.

 

Message 46 of 57

cizimcenter
Participant
Participant

Hi,

I need numbering from bottom left to right. Can you help me to edit the code?

 

cizimcenter_0-1735299709279.png

 

0 Likes
Message 47 of 57

Crisger4VSG7
Observer
Observer

Hello,

 

I am doing a list of a lot rectangles. The LISP file has been very helpful, thank you! But in my project, I needed the dimensions such that the X direction dimension will always be the length, and the Y-dir dimension will always be the width. And not arranged such that the width shall always be the shorter dimension.

Appreciate if you can help me on this.

 

Thanks a lot. 

0 Likes
Message 48 of 57

Sea-Haven
Mentor
Mentor

Post a sample dwg with before and table output.

0 Likes
Message 49 of 57

cizimcenter
Participant
Participant

here is a sample file. @Sea-Haven can you help me?

0 Likes
Message 50 of 57

Crisger4VSG7
Observer
Observer

See image below for sample scenario. I need all Y-dir dimensions to be width, and X-dir dimensions to be the length. In this case, last shape takes the shorter dimension as width, which is not supposed to be. Any help is appreciated.

 

Thank you so much. 

Screenshot 2024-12-30 201823.jpg

0 Likes
Message 51 of 57

Sea-Haven
Mentor
Mentor

@Crisger4VSG7 Don't need to look at the dims just select the rectangs, May have time later today.

 

Try this.

 

(defun c:rectsize ( / AH:table_make cnt lst lst3 my-count objtable pointmin pontmax ss txtsz val1 val2 xd yd)

(defun remove-duplicates (lst)
  (cond
    ((null lst) nil)
    ((member (car lst) (cdr lst)) (remove-duplicates (cdr lst)))
    (T (cons (car lst) (remove-duplicates (cdr lst))))
  )
)

(defun AH:table_make (numcolumns txtsz / numrows curspc colwidth numcolumns  objtable rowheight sp doc)
(vl-load-com)
(setq sp (vlax-3d-point (getpoint "Pick top left"))); or use getpoint
(setq doc  (vla-get-activedocument (vlax-get-acad-object) ))
(if (= (vla-get-activespace doc) 0)
  (setq  curspc (vla-get-paperspace doc))
  (setq curspc (vla-get-modelspace doc))
)
(setq numrows 2)
(setq rowheight (* 2.0 txtsz))
(setq colwidth 20)
(setq objtable (vla-addtable curspc sp numrows numcolumns rowheight colwidth))
(vla-SetTextHeight Objtable (+ acDataRow acTitleRow acHeaderRow) txtsz)
(vla-settext objtable 0 0 "RECTANGLES")
(vla-settext objtable 1 0 "Length")
(vla-settext objtable 1 1 "Height")
(vla-settext objtable 1 2 "PC's")
(princ)
)

; By Gile
(defun my-count (a L)
  (cond
   ((null L) 0)
   ((equal a (car L)) (+ 1 (my-count a (cdr L))))
   (t (my-count a (cdr L))))
)

; starts here
(setq txtsz (getreal "Enter text size "))

(setq ss (ssget '((0 . "LWPOLYLINE"))))

(setq lst '())
(repeat (setq x (sslength ss))
 (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
 (vla-GetBoundingBox obj 'minpoint 'maxpoint)
 (setq pointmin (vlax-safearray->list minpoint))
 (setq pointmax (vlax-safearray->list maxpoint))
 (setq xd (atof (rtos (abs (- (car pointmin)(car pointmax))) 2 4)))
 (setq yd (atof (rtos (abs (- (cadr pointmin)(cadr pointmax))) 2 4)))
 (setq lst (cons (list xd yd) lst))
)
(setq lst (vl-sort lst
	 '(lambda (a b)
	    (cond
	      ((< (car a) (car b)))
	      ((= (car a) (car b)) 
		  (< (cadr a) (cadr b)))
	    )
	  )
    )
)

(setq lst3 '())
(foreach val lst
 (setq cnt (my-count val lst))
 (setq lst3 (cons (list  (nth 0 val)(nth 1 val) cnt) lst3))
)
(setq lst3 (vl-sort lst3 '(lambda (x y) (< (car x)(car y)))))
(setq lst3 (remove-duplicates lst3))

(AH:table_make 3 txtsz)
(setq objtable (vlax-ename->vla-object (entlast)))
(setq numrows (vla-get-rows objtable))
(foreach val1 lst3
  (vla-InsertRows Objtable  numrows (vla-GetRowHeight Objtable (1- numrows)) 1)
  (vla-settext objtable numrows 0 (car val1))
  (vla-settext objtable numrows 1 (cadr val1))
  (vla-settext objtable numrows 2 (caddr val1))
  (setq numrows (1+ numrows))
)

(princ)
)

 

 

0 Likes
Message 52 of 57

Crisger4VSG7
Observer
Observer

Hello sir,

Happy New Year. It works fine, and I really appreciate your help. If you could also help me add another column that identify the layer that the rectangles are in, same as shown below.

 

Thank you so much.

 

Crisger4VSG7_0-1735843155876.png

 

0 Likes
Message 53 of 57

ec-cad
Collaborator
Collaborator

Here's an update to add the LAYER as Column 4.

 

ECCAD

 

0 Likes
Message 54 of 57

Crisger4VSG7
Observer
Observer

Hello sir,

 

May I know if you also have ready lisp file with the same function as above. Instead of rectangles, I am dealing with lines and I want to tabulate each line with corresponding length and layer.

 

Your help really meant a lot to me and to the job I'm working on. Thank you so much.

0 Likes
Message 55 of 57

Sea-Haven
Mentor
Mentor

Need a sample dwg with your desired Table so can match column widths, text size etc. Should be able to sort on layer name and length.

0 Likes
Message 56 of 57

Crisger4VSG7
Observer
Observer

Hello, thanks for giving me feedback. The output table will look like below screenshot:

Crisger4VSG7_1-1742903508937.png

 

0 Likes
Message 57 of 57

Sea-Haven
Mentor
Mentor

Give this a try

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/extract-rectangle-dimension-to-table-count-amp-numbering/td-p/10321468
; wants table of line lengths.
; By AlanH March 2025

(defun c:linetable ( / my-count remove_doubles sp vgms txtht numrows numcolumns colwidth rowheight colwidth objtable x ss)

(defun my-count (a L)
  (cond
   ((null L) 0)
   ((equal a (car L)) (+ 1 (my-count a (cdr L))))
   (t (my-count a (cdr L))))
)

; By Gile
(defun remove_doubles (lst)
  (if lst
    (cons (car lst) (remove_doubles (vl-remove (car lst) lst)))
  )
)


(setq sp (vlax-3d-point (getpoint "\nPick point for table")))
(Setq vgms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq txtht 3.0)
(setq numrows 3)
(setq numcolumns 3)
(setq rowheight (* 2.0 txtht))
(setq colwidth 35)
(setq objtable (vla-addtable vgms sp numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "Line summary")
(vla-settext objtable 1 0 "QTY")
(vla-settext objtable 1 1 "LENGTH")
(vla-settext objtable 1 2 "LAYER")
(vla-setcolumnwidth objtable 0 15)

(setq ss (ssget '((0 . "LINE"))))
(setq lst '() lst3 '())
(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq len (atof (rtos (vlax-get obj 'length) 2 3)))
  (setq lay (vlax-get obj 'layer))
  (setq lst (cons (list lay len) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (cadr x)(cadr y)))))

(setq lst2 (remove_doubles lst))
(foreach val lst2
  (setq cnt (my-count val lst))
  (setq lst3 (cons (list (car val) (cadr val) cnt) lst3))
)

(setq row 2)
(foreach val lst3
  (vla-settext objtable row 0 (caddr val))
  (vla-settext objtable row 1 (rtos (cadr val) 4))
  (vla-settext objtable row 2 (car val))
  (vla-insertrows objtable (setq row (1+ row)) txtht 1)
)

(princ)
)
(c:linetable)