Length and area of selected objects

Length and area of selected objects

Bart_Dheere
Advocate Advocate
4,531 Views
10 Replies
Message 1 of 11

Length and area of selected objects

Bart_Dheere
Advocate
Advocate

The lisp attached create a table with the selected lines of a drawing. These are placed under each other with the lengths per layer.

 

I would like to be in the same table also had the surfaces of selected hatches. It also listed by layer. Is there anyone who can help me?

 

grt, Bart

 

(defun C:LAYLENGTH ( / *error* acdoc ss p i e a d l) (vl-load-com)
  (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark acdoc)

  (defun *error* (msg)
    (and
      msg
      (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*"))
      (princ (strcat "\nError: " msg))
    )
    (if
      (= 8 (logand (getvar 'undoctl) 8))
      (vla-endundomark acdoc)
    )
    (princ)
    )
  
  (if
    (and
      (setq ss (ssget ":L" '((0 . "LINE,POLYLINE,LWPOLYLINE,ARC,CIRCLE,ELLIPSE,SPLINE"))))
      (setq p (getpoint "\nTable scale depend on annotation scale.\nSpecify table insert point: "))
      )
    (progn
      (repeat
        (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
              a (cdr (assoc 8 (entget e)))
              d (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
        )
        (if
          (setq o (assoc a l))
          (setq l (subst (list a (+ (cadr o) d)) o l))
          (setq l (cons (list a d) l))
        )
      )
      (setq l (vl-sort l '(lambda (a b) (< (car a) (car b)))))
      (insert_table l p)
      )
    )
  (*error* nil)
  (princ)
  )

(defun insert_table (lst pct / tab row col ht i n space)
  (setq space (vlax-get acDoc (if (= 1 (getvar 'cvport)) 'PaperSpace 'ModelSpace))
        ht  (/ 2.5 (cond ((getvar 'cannoscalevalue)) (1.0)))
        pct (trans pct 1 0)
        n   (trans '(1 0 0) 1 0 T)
        tab (setq tab (vla-addtable space (vlax-3d-point pct) (+ 2 (length lst)) (length (car lst)) (* 2.5 ht) ht))
        )
  (vlax-put tab 'direction n)
  
  (mapcar
    (function
      (lambda (rowType)
        (vla-SetTextStyle  tab rowType (getvar 'textstyle))
        (vla-SetTextHeight tab rowType ht)
      )
    )
   '(2 4 1)
  )
  
  (vla-put-HorzCellMargin tab (* 0.14 ht))
  (vla-put-VertCellMargin tab (* 0.14 ht))

  (setq lst (cons (mapcar '(lambda (a) (strcat "Col" (itoa (1+ (vl-position a (car lst)))))) (car lst)) lst))

  (setq i 0)
  (foreach col (apply 'mapcar (cons 'list lst))
    (vla-SetColumnWidth tab i
      (apply
        'max
        (mapcar
          '(lambda (x)
             ((lambda (txb) (+ (abs (- (caadr txb) (caar txb))) (* 2.0 ht)))
              (textbox (list (cons 1 (vl-princ-to-string x)) (cons 7 (getvar 'textstyle)) (cons 40 ht)))
              )
             )
          col
          )
        )
      )
    (setq i (1+ i))
    )
  
  (setq lst (cons '("TITLE") lst))
  
  (setq row 0)
  (foreach r lst
    (setq col 0)
    (vla-SetRowHeight tab row (* 1.5 ht))
    (foreach c r
      (vla-SetText tab row col (if (numberp c) (rtos c) (vl-princ-to-string c)))
      (setq col (1+ col))
      )
    (setq row (1+ row))
    )
  )
0 Likes
Accepted solutions (2)
4,532 Views
10 Replies
Replies (10)
Message 2 of 11

phanaem
Collaborator
Collaborator
Hi Bart
This is my lisp.
I would like to help you, but I'm not sure what you are after. A hatch doesn't have length and a line doesn't have area. So how should the table look like?

PS I would expect you to contact me directly on the site from where you downloaded the lisp, but here it's just fine too.
0 Likes
Message 3 of 11

Bart_Dheere
Advocate
Advocate

Thank you for wanting to help me. I try my questions about placing a lisp that central, that's why I throw in this.

 

Kimprojects.com would indeed have been a good place to communicate, but this way is your site even more popular.

 

The lisp does exactly what I'm looking for. Displaying total of the selected lines per layer in a table. With this I get a good overview of all applied linear elements in the construction of roads.

 

In addition to the linear elements, I also need the surfaces. These are referred to the plan with hatches. The surface of these hatches, together with the respective layers, I would like to see appear in the table.

 

Did you want to help me that would be a huge step forward.

 

Greetings and thanks, Bart

Google translate doesn't work 100% but I think you'll understand what I want to mean.

0 Likes
Message 4 of 11

phanaem
Collaborator
Collaborator
Accepted solution

Try the lisp in attachment.

 

The only thing added is a third column with hatch area.

Message 5 of 11

Bart_Dheere
Advocate
Advocate
Tested and approved.
Thanks.
0 Likes
Message 6 of 11

Bart_Dheere
Advocate
Advocate

Hello, 

 

The lisp works great. 

 

Is it possible to add a column with a total count of selected blocks per layer?

 

I look forward. 

 

grtz, 

Bart

0 Likes
Message 7 of 11

phanaem
Collaborator
Collaborator
Accepted solution

H Bart

Please try the attached lisp.

 

Message 8 of 11

Anonymous
Not applicable

Hi. I would like to add a fourth column (at the beginning of the table), with a solid hatch with the layer color of the selected object.

0 Likes
Message 9 of 11

eng.cmagalhaes
Community Visitor
Community Visitor

Hi, I've just intalled lisp and apparentally it's working correctly but the area information (numbers) it's not appering on the AREA row. I would ask you please to check if the code is suit able for AutoCAD 2019 version. Thank you very much.

0 Likes
Message 10 of 11

dlanorh
Advisor
Advisor
If you read post 4 the area column is for hatch objects

I am not one of the robots you're looking for

0 Likes
Message 11 of 11

javier.longueira
Participant
Participant

Hi! Excuse me for my poor english.. If possible add filter (or column) by global width plines (width by pline, no by layer)???

0 Likes