- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi forum
Below is a lisp I use to generate a .csv list of all layouts that exist in the active document to a subfolder in the same directory named "table of contents".
The problem with this lisp is that is that the layouts are listed alphabetically instead of following the order in which they are organized in the dwg.
Can somebody help me to transform the lisp into following the document order, so I can actually consider this list as a table of contents? Thanks!
(defun c:ExportLayoutsToCSV ()
(if (not (vl-load-com)) (vl-load-com)) ; Load COM support if not already loaded
;; Get the full path of the active document
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq doc-path (vlax-get-property doc 'Path))
(setq doc-name (vlax-get-property doc 'Name))
;; Ensure the document path exists
(if doc-path
(progn
;; Construct the "table of contents" folder path
(setq toc-folder (strcat doc-path "\\table of contents"))
;; Check if folder exists, if not create it
(if (not (vl-file-directory-p toc-folder))
(vl-mkdir toc-folder)
)
;; Construct the CSV file path
(setq csv-file-name (strcat "Table of Contents - " (vl-filename-base doc-name) ".csv"))
(setq csv-file-path (strcat toc-folder "\\" csv-file-name))
;; Get the list of layout names
(setq layout-list (layoutlist))
;; Open file for writing
(setq file-handle (open csv-file-path "w"))
(if file-handle
(progn
;; Write the layout names to the file
(foreach layout layout-list
(write-line layout file-handle)
)
(princ (strcat "\nLayout names exported to: " csv-file-path))
(close file-handle)
)
(princ "\nError: Unable to open file for writing.")
)
)
(princ "\nError: Unable to determine the document path.")
)
(princ) ; Suppress return value in the command line
)
Solved! Go to Solution.