Author Topic: Extract Default Page Setup Error  (Read 982 times)

0 Members and 1 Guest are viewing this topic.

RayG2261

  • Mosquito
  • Posts: 4
Extract Default Page Setup Error
« 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)
)

stevej

  • Newt
  • Posts: 31
Re: Extract Default Page Setup Error
« Reply #1 on: June 15, 2024, 02:17:20 PM »

BIGAL

  • Swamp Rat
  • Posts: 1474
  • 40 + years of using Autocad
Re: Extract Default Page Setup Error
« Reply #2 on: June 15, 2024, 07:25:08 PM »
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.
A man who never made a mistake never made anything

RayG2261

  • Mosquito
  • Posts: 4
Re: Extract Default Page Setup Error
« Reply #3 on: June 18, 2024, 08:56:24 AM »
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.

PKENEWELL

  • Bull Frog
  • Posts: 324
Re: Extract Default Page Setup Error
« Reply #4 on: June 18, 2024, 03:46:16 PM »
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:
https://www.theswamp.org/index.php?topic=53277.0
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-get-the-page-setup-name-associated-with-the-current/td-p/1515543
https://www.cadtutor.net/forum/topic/60547-page-setup-lisp/

Perhaps you can put something together with these.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 324
Re: Extract Default Page Setup Error
« Reply #5 on: June 18, 2024, 04:08:32 PM »
Here is a bit of code I threw together Based on JTBworld.com code, that will return a list of sublists for each Layout type plot configuration containing the Name, Papersize Width and Height, Origin, and rotation. I still don't know how to identify the "Default" configuration.
Code - Auto/Visual Lisp: [Select]
  1. ;; Original code from JTBworld.com, Modified by PJK
  2. ;; Usage: (GetLayoutPageSetups (vla-get-activedocument (vlax-get-acad-object)))
  3. (defun GetLayoutPageSetups (doc / plrt aps wid hgt)
  4.     (if (= (vla-get-ModelType pc) :vlax-false)
  5.       (setq aps
  6.          (cons
  7.             (list
  8.                (vla-get-name pc)
  9.                (progn
  10.                   (vla-GetPaperSize pc 'wid 'hgt)
  11.                   (list wid hgt)
  12.                )
  13.                (vlax-safearray->list (vlax-variant-value (vla-get-plotorigin pc)))
  14.                (cond
  15.                  ((= (setq plrt (vla-get-plotrotation pc)) 1) 0.0)
  16.                  ((= plrt 2) 90.0)
  17.                  ((= plrt 3) 180.0)
  18.                  ((= plrt 4) 270.0)
  19.                )
  20.             )
  21.          aps)
  22.       )
  23.     )
  24.   )
  25. )
  26.  
« Last Edit: June 18, 2024, 04:18:53 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

RayG2261

  • Mosquito
  • Posts: 4
Re: Extract Default Page Setup Error
« Reply #6 on: June 20, 2024, 10:50:12 AM »
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:
https://www.theswamp.org/index.php?topic=53277.0
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-get-the-page-setup-name-associated-with-the-current/td-p/1515543
https://www.cadtutor.net/forum/topic/60547-page-setup-lisp/

Perhaps you can put something together with these.

Ah, okay- that is a good explanation of the problem- non-existent or invalid properties. And I will check out the Autodesk Forum thing. I did a search and also asked about it there at one time or another and never came across that post. Not sure why. But, thanks for the pointers...

As it turns out, none of those routines will actually do what I am looking for. I appreciate the help, but I guess I'll have to stick with the current method of fixing them on the fly as the pop up.