6
« Last post by RayG2261 on June 14, 2024, 10:11:26 AM »
Greetings- as promised in my Intro Post- I am curious about this routine. I am trying to figure a way to extract the Default Page Setup for multiple dwg files in a directory. It is not available in any Data Extraction command in Acad. Yes, I have a lsp setup in the acaddoc that will delete old Page Setups and bring in the correct Setups from a standard dwg located on the Network. I also have a routine that I use in ScriptPro that will set a particular Page Setup to multiple dwgs in a directory. However- on occasion, if we receive a file from a vendor or similar, or a rogue block contains an oddball Page Setup it can change the default Setup. So... I have asked around (mostly in that Cad Managers FB page) to see if anyone knew of such a routine. I basically got the suggestions that I listed above: acaddoc, Template stuff, etc... But that isn't what I was looking for. And using the ScriptPro takes 10-30 seconds per dwg to go through the routine. I just want to pick a list of dwgs, get the Default Page Setup, open the file and change the default. As I said, I am in no way a lsp'er, so I took the plunge into ChatGPT and asked if it could write one. The first effort was a disaster, btw. I rephrased the second attempt and did get something of a result. It opened up a file window, DID allow me to choose a file (not multiple), but it returned the "Too Many Arguments" error. That means nothing to me, other than it doesn't work. In a nutshell, I would like to be able to pick multiple files and have it generate a list (txt is fine) of the default Page Setups. (I hope I don't get shunned for using the ChatGPT thingee) Thanks...
Here is what ChatGPT wrote:
(defun c:ExtractPageSetup ()
(setq dwglist (getfiled "Select drawings to extract page setup" "" "dwg" 4))
(if dwglist
(progn
(setq pageSetupList nil)
(foreach dwg dwglist
(setq doc (vla-open (vla-get-documents (vlax-get-acad-object)) dwg))
(setq layout (vla-get-layouts doc))
(setq count (vla-get-count layout))
(setq pageSetups '())
(vlax-for lyt layout
(if (= (vla-get-Objectname lyt) "AcDbLayout")
(progn
(setq name (vla-get-name lyt))
(setq pageSetup (vla-get-PageSetup lyt))
(setq pageSetups (cons (list name pageSetup) pageSetups))
)
)
)
(setq pageSetupList (cons (cons dwg pageSetups) pageSetupList))
(vla-close doc)
)
(setq outFile (getfiled "Save page setup data to" "" "txt" 1))
(if outFile
(progn
(setq outF (open outFile "w"))
(foreach dwgData pageSetupList
(setq dwg (car dwgData))
(write-line (strcat "Drawing: " dwg) outF)
(setq pageSetups (cdr dwgData))
(foreach ps pageSetups
(setq name (car ps))
(setq setup (cdr ps))
(write-line (strcat "Layout: " name) outF)
(write-line (strcat "Paper size: " (vla-get-Papersize setup)) outF)
(write-line (strcat "Plot origin: " (strcat (rtos (car (vla-get-Plotorigin setup))) 2 2) ", " (strcat (rtos (cadr (vla-get-Plotorigin setup)) 2 2))) outF)
(write-line (strcat "Plot rotation: " (rtos (vla-get-Plotrotation setup)) 2 2) outF)
(write-line "" outF)
)
)
(close outF)
(alert "Page setup data extracted successfully.")
)
)
)
)
(princ)
)