This routine allows the user to select closed polylines, and it will create a TABLE with two columns. One containing the area, and the other containing the ObjectID. The last row totals up the area. You could easily adapt this to show the layer, color or any other property.
The TABLE is creating on the current tablestyle, so depending on the settings of your current tablestyle, you may have to adjust the sizing arguments in the (vla-addTable...) function in order for the table to look acceptable. These sizes used here work with the Standard tablestyle in a new empty drawing.
; load (vl-load-com) first
(defun C:POLYTABLE ( / *MS* A CNT I LST MYTABLE PT1 ROW SSET TLST)
; create an empty list, set a counter variable, and
; set a reference to the current model space.
(setq lst '()
; prompt the user to select closed polylines
(princ "\n Select closed polylines ")
(if (setq sset (ssget '((0 . "POLYLINE,LWPOLYLINE")(-4 . "&")(70 . 1))))
; if a valid selection set was generated, then proceed.
; for each closed polyline selected, grab the ObjectID and Area
; and store these values in a list.
(repeat (setq cnt (sslength sset))
(setq a (vlax-ename->vla-object (ssname sset i)))
(setq tlst (list (vla-get-Area a) (vla-get-ObjectID a)))
(setq lst (cons tlst lst))
(setq i (1+ i))
; pick a point for the table
(setq pt1 (getpoint "\nPick point for table "))
; add the new table
(setq myTable (vla-AddTable
(+ 3 cnt)
; the next three lines set the header text
(vla-setText mytable 0 0 "Polyline Table")
(vla-setText mytable 1 0 "Area")
(vla-setText mytable 1 1 "Object ID")
(setq row 2)
; loop through the list of polyline properties
; adding a line to the table that contains the
; area and the ObjectID
(foreach item lst
(strcat "%<\\AcObjProp Object(%<\\_ObjId "
(itoa (last item))
">%).Area \\f \"%lu2\">%"))
(vla-setText mytable row 1 (last item))
(setq row (1+ row))
; On the last row, total up the area
"%<\\AcExpr (Sum(A3:A" (itoa (+ 2 cnt)) ")) \\f \"%lu2\">%"))
; release "myTable" and *ms*
); end progn
; if no closed polylines were selected,
; end the program with this message
(princ "\nNo closed polylines selected. ")
); end if
); end defun
PermaLink Posted 8/13/2007 07:44:00 AM