HAS MOVED TO http://cadpanacea.com
13 August 2007
Create a TABLE using lisp          
Here is an example of creating a TABLE entity using lisp. This example also creates some FIELDS using lisp.

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
(vl-load-com)
(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 '()
i 0
*ms* (vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
)
; 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.
(progn

; 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
*ms*
(vlax-3d-point pt1)
(+ 3 cnt)
2
0.7
2.5))
; 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
(vla-setText mytable
row
0
(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
(vla-setText mytable
row
0
(strcat "Total=\\P"
"%<\\AcExpr (Sum(A3:A" (itoa (+ 2 cnt)) ")) \\f \"%lu2\">%"))
; release "myTable" and *ms*
(vlax-release-object myTable)
(vlax-release-object *ms*)
); end progn

; if no closed polylines were selected,
; end the program with this message

(princ "\nNo closed polylines selected. ")
); end if
(princ)
); end defun




Labels: ,


PermaLink       Posted 8/13/2007 07:44:00 AM     
0 COMMENTS!

Post a comment