Code Red > AutoLISP (Vanilla / Visual)

Extract Default Page Setup Error

(1/2) > >>

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
      (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")
              (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
          (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.")

Check this:


Have you looked at Accoreconsole it will zoom across multiple dwg's changing things as it works on the database so does not open the dwg. It does though have some not work functions, like no user input and some VLA functions.

1st step is to make sure your lisp works. You can use a Bat file to process a directory in one go. Handy maybe for new projects.

I appreciate the suggestions. As I mentioned, I have several routines to either clean up/delete Page Setups, and use ScriptPro for the default Setup on multiple files. And having the routine work for Accoreconsole is moot. THAT is the trouble, the routine doesn't work.

What I was hoping is that someone smarter than myself can figure out WHY is there a 'too many arguments' error? And what can be done to allow multiple files to be selected.

If it can't be done, fine. I'll resign myself to fixing it the way I have been.

The ChatGPT code has invalid properties that don't actually exist, such as "(vla-get-PageSetup)", that doesn't exist at all & "(vla-get-Papersize)", which is actually a method (vla-GetPaperSize) of Layouts or Plot Configurations. You have to work with "Layout" Objects or "PlotConfiguration" Objects. I personally don't know how to get the "Default" Page Setup via Lisp.

I can't say I know completely what I am doing with page setups, but a simple search yields:

Perhaps you can put something together with these.


[0] Message Index

[#] Next page

Go to full version