LISP to generate a table showing length of each selected line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My target function of this below lisp is to output a table showing the length of each selected lines. But for some reasons my AutoCAD 2023 wouldn't run it, and tell me an error:
Select objects: Specify opposite corner: 3 found
Select objects:
Enter base point for table: ; error: ActiveX Server returned the error: unknown name: AddTable
My current LISP codes (generated by ChatGPT) below, can someone please help making it work?
(defun c:RebarTable ()
(setq selectedLines (ssget '((0 . "LINE"))))
(if selectedLines
(progn
(setq tableData '())
(setq totalLength 0.0)
; Prompt the user to specify the base point for the table
(setq basePoint (getpoint "\nEnter base point for table: "))
(setq table (vla-AddTable
(vla-get-activedocument
(vlax-get-acad-object))
(vlax-3d-point basePoint)
3
4
(- (sslength selectedLines) 1)
1
"Rebar Length Table"
selectedLines
)
)
(repeat (sslength selectedLines)
(setq line (ssname selectedLines 0))
(setq selectedLines (ssdel line selectedLines))
(setq startPoint (vlax-curve-getstartpoint line))
(setq endPoint (vlax-curve-getendpoint line))
(setq length (distance startPoint endPoint))
(setq totalLength (+ totalLength length))
(setq tableData (cons (list startPoint endPoint length) tableData))
)
(setq rowIndex 0)
(foreach row tableData
(setq rowIndex (1+ rowIndex))
(setq cellIndex 0)
(foreach cell row
(setq cellIndex (1+ cellIndex))
(vla-put-text table rowIndex cellIndex (strcat "" (rtos cell 2 2)))
)
)
(setq rowIndex (1+ rowIndex))
(setq totalRowIndex rowIndex)
(vla-put-text table totalRowIndex 0 "Total Length:")
(vla-put-text table totalRowIndex 1 (strcat "" (rtos totalLength 2 2)))
(vla-resize table)
(princ "\nTable generated successfully.")
)
(princ "\nNo lines were selected.")
)
(princ)
)