Here is most of what you want.
Command EPL
There are a few problems though.
- The order. If you want the same order as the numbers you wrote next to the polylines, then you must pick them one by one, in that same order
- The circle is a bit of a problem. I think only returns half its length. Maybe better not use circles.
- units. My table will return the same values as you can see in the properties. You divide by a factor 100 for some reason. I don't.
(vl-load-com)
(defun inserttable (lst pt / ht htc tab i j row tb acObj acDoc space width_cols)
;; settings, text height, cel height
(setq ht 12.0)
(setq htc 30.0)
(setq width_cols (list
80.0 270.0 110.0 120.0 160.0
))
;; document, model space, ...
(setq acObj (vlax-get-acad-object)
acDoc (vla-get-activedocument acObj)
space (vlax-get acDoc (if (= 1 (getvar 'cvport)) 'PaperSpace 'ModelSpace))
)
(setq tab (vla-addtable space (vlax-3d-point pt) (length lst) (length (cadr lst)) (* 1.1 ht) (* 10.0 ht) )) ;;
(vla-SetTextHeight tab 1 ht)
(vla-SetTextHeight tab 2 ht)
(vla-SetTextHeight tab 4 ht)
(vla-put-VertCellMargin tab (* 0.3 ht))
(vla-put-HorzCellMargin tab (* 0.3 ht))
(setq i 0)
(repeat (length lst) ;; iterates the rows
(vla-setrowHeight tab i htc)
(setq row (nth i lst))
(setq j 0)
(repeat (length row) ;; iterates the cols in the row
;; (textbox (list (cons 1 (to_string x)) (cons 7 (getvar 'textstyle)) (cons 40 ht) ))
(vla-SetColumnWidth tab j (nth j width_cols) )
(vla-SetText tab i j (nth j row) )
(setq j (+ j 1))
)
(setq i (+ i 1))
)
;; default Autocad expects a title row. If the first row has more than 1 cel, let's unmerge this row
(if (> (length (nth 0 lst)) 1)
(vla-unMergeCells tab 0 0 0 0)
)
;; Merge last row, to show total
;; MergeCells minRow, maxRow, minCol, maxCol
(vla-MergeCells tab (- (length lst) 1) (- (length lst) 1) 0 3)
tab
)
;; test of inserttable
(defun c:ila ( / )
(inserttable
(list
(list "P.NO" "EASTING" "NORTHING" "ELEV." "REMARKS")
(list "P1" "20.5" "30.5" "40.5" "Hello")
(list "P2" "50.5" "60.5" "70.5" "World!")
)
(getpoint "\nInsert point of table: ")
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; length of polyline, or most other (curved) lines, spline, ...
(defun length_curve (ent / )
(vlax-curve-getdistatparam ent (vlax-curve-getendparam ent))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Export Polyline Lengths
(defun c:EPL ( / plines i pline data lay len hei tot total)
(setq hei (getreal "\nHeight: "))
(setq plines (ssget (list (cons 0 "LWPOLYLINE,POLYLINE,CIRCLE"))))
(setq data
(list
(list " ") ;; Empty Title
(list "NO" "Layer" "Length" "Height" "Total") ;; column titles
)
)
(setq i 0)
(setq total 0.0)
(repeat (sslength plines)
(setq pline (ssname plines i))
;;(setq lst (vlax-get (vlax-ename->vla-object pline) 'coordinates))
;;(if (= "AcDb2dPolyline" (vla-get-ObjectName (vlax-ename->vla-object pline))) ;; polyline or 2D polyline ?
;; (setq pts (3d-coord->pt-lstrjp lst))
;; (setq pts (2d-coord->pt-lst lst))
;;)
(setq len (length_curve pline))
(setq tot (* len hei))
(setq lay (cdr (assoc 8 (entget pline))))
(setq data (append data (list
(list
(itoa (+ i 1)) ;; number
lay ;; Layer
(rtos len 2 3) ;; length
(rtos hei 2 3) ;; height
(rtos tot 2 3) ;; total
)
)))
(setq total (+ total tot))
(setq i (+ i 1))
)
(setq data (append data (list
(list
"Total"
""
""
""
(rtos total 2 3) ;; total
)
)))
(inserttable
data
(getpoint "\nInsert point of table: ")
)
)