Author Topic: Set default page setup  (Read 5103 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Set default page setup
« on: July 28, 2017, 11:34:49 AM »
Been a while since I've been in the world of LSP so I need a little help with a batch program to import page setups (got that part - psetupin) but the part I'm struggling with is iterating through each layout (sorta got that part down) then set the newly import page setup and the active setup for each layout tab.


(life is so much easier in the Revit realm....)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Set default page setup
« Reply #1 on: July 28, 2017, 01:08:59 PM »
Try the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun applypstolayouts ( cfg / doc rtn )
  2.     (if
  3.         (setq rtn
  4.             (not
  5.                 (vl-catch-all-error-p
  6.                     (setq cfg
  7.                         (vl-catch-all-apply 'vla-item
  8.                             (list
  9.                                 (vla-get-plotconfigurations
  10.                                     (setq doc
  11.                                         (vla-get-activedocument
  12.                                             (vlax-get-acad-object)
  13.                                         )
  14.                                     )
  15.                                 )
  16.                                 cfg
  17.                             )
  18.                         )
  19.                     )
  20.                 )
  21.             )
  22.         )
  23.         (vlax-for lay (vla-get-layouts doc)
  24.             (if (= :vlax-false (vla-get-modeltype lay))
  25.                 (vla-copyfrom lay cfg)
  26.             )
  27.         )
  28.     )
  29.     rtn
  30. )

Call with name of Page Setup:
Code - Auto/Visual Lisp: [Select]
  1. (applypstolayouts "mypagesetup")

Will return T if Page Setup is valid, else nil; excludes Model tab.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Set default page setup
« Reply #2 on: July 28, 2017, 02:20:35 PM »
Always when I hear "set a page setup in a layout" it reminds me of BlackBox's work.

Anyway nice job Lee! 8)
« Last Edit: July 28, 2017, 02:24:59 PM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Crank

  • Water Moccasin
  • Posts: 1503
Re: Set default page setup
« Reply #3 on: July 30, 2017, 12:11:21 PM »
Thanks Lee, very good!

This works well if all layouts have the same paper size.
Is it possible to set a pagesetup depending of the LIMMAX variable in the layout?

Something like:
Code: [Select]
(applyPS (list '((210 297) "pdf-A4") '((420 297) "pdf-A3") '((594 420) "pdf-A2") '((841 594) "pdf-A1") '((1189 841) "pdf-A0")))

My current function steps through all layouts and therefor  is very slow.
« Last Edit: July 30, 2017, 12:51:51 PM by Crank »
Vault Professional 2023     +     AEC Collection

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Set default page setup
« Reply #4 on: July 30, 2017, 09:15:55 PM »
Thanks, Lee!!  I appreciate it. This worked out great with the rest of the program I have.

Thanks again!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Set default page setup
« Reply #5 on: July 31, 2017, 12:18:21 PM »
Thanks guys  :-)

Crank, I'm not sure it is possible without iterating over the layouts, but others may know of a better way.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Set default page setup
« Reply #6 on: August 01, 2017, 05:51:29 AM »
So I decided to take a different approach and found some ODBX code and I added your code, Lee, and it's working to an extent. It's bringing in the page setup but it's not setting it as the default for each view. Any thoughts? Thanks for the help.

Code: [Select]
;; Copies plot configurations from the current drawing
;; to all drawings within a selected folder.
(defun c:copyplotconfigs (/ _getfolder _getplotconfigs adoc dir doc file l n odbx plt v)
  (vl-load-com)
  (defun _getfolder (message / sh folder result)
    (setq sh (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application"))
    (setq folder (vlax-invoke-method sh 'browseforfolder 0 message 0))
    (vlax-release-object sh)
    (if        folder
      (progn (setq result (vlax-get-property (vlax-get-property folder 'self) 'path))
                     (if (wcmatch result "*\\")
                       result
                       (strcat result "\\")
                     )
      )
    )
  )
 
  (defun _getplotconfigs (doc / out)
    (vlax-for x       (vla-get-plotconfigurations doc)
      (setq out (cons (cons (strcase (vla-get-name x)) x) out))
    )
  )
  (setq adoc (vla-get-activedocument (setq doc (vlax-get-acad-object))))
  (cond
    ((not (setq l (_getplotconfigs adoc)))
     (princ "\nNo plot configurations in current drawing!")
    )
    ((not (setq      odbx (if (< (setq v (substr (getvar 'acadver) 1 2)) "16")
                                       (vla-getinterfaceobject doc "ObjectDBX.AxDbDocument")
                                       (vla-getinterfaceobject doc (strcat "ObjectDBX.AxDbDocument." v))
                                     )
                  )
     )
     (princ "\nObject DBX interface not created!")
    )
    ((if
       (setq dir (_getfolder "Select directory to apply current drawing pagesetups to: "))
                (foreach f (vl-directory-files dir "*.dwt" 0)
                  (setq file (strcat dir f))
                  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list odbx file)))
                    (princ (strcase (strcat "\nError opening: " file)))
                    (progn (princ (strcat "\nOpening: " file))
                                   (setq plt (vla-get-plotconfigurations odbx))
                                   (if (not (zerop (setq n (vla-get-count plt))))
                                     (progn (princ (strcat "\n\t" (itoa n) " - plot configurations removed"))
                                                    (vlax-map-collection plt 'vla-delete)
                                     )
                                               
                                                 
                 
                 
                                   )
                                   (and    (vlax-invoke adoc 'copyobjects (mapcar 'cdr l) plt nil)
                                                (princ (strcat "\n\t"
                                                                       (itoa (length l))
                                                                       " - plot configurations copied from current drawing"
                                                       )
                                                )
                                                (applypstolayouts "My Page Setup 1")
                                   )
                                   (vla-saveas odbx (vla-get-name odbx))
                    )
                  )           
                )
                (princ "\nBuh bye...")
     )
    )
  )
  (princ)
)
 
 
(defun applypstolayouts ( cfg / doc rtn )
    (if
        (setq rtn
            (not
                (vl-catch-all-error-p
                    (setq cfg
                        (vl-catch-all-apply 'vla-item
                            (list
                                (vla-get-plotconfigurations
                                    (setq doc
                                        (vla-get-activedocument
                                            (vlax-get-acad-object)
                                        )
                                    )
                                )
                                cfg
                            )
                        )
                    )
                )
            )
        )
        (vlax-for lay (vla-get-layouts doc)
            (if (= :vlax-false (vla-get-modeltype lay))
                (vla-copyfrom lay cfg)
            )
                )
    )
    rtn
)
 
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Set default page setup
« Reply #7 on: August 01, 2017, 08:20:44 AM »
The applypstolayouts that I posted is iterating over layouts in the active document - this will need to be changed to the ObjectDBX document, or better yet, have the document object supplied as an argument, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun applypstolayouts ( doc cfg / rtn )
  2.     (if
  3.         (setq rtn
  4.             (not
  5.                 (vl-catch-all-error-p
  6.                     (setq cfg
  7.                         (vl-catch-all-apply 'vla-item
  8.                             (list (vla-get-plotconfigurations doc) cfg)
  9.                         )
  10.                     )
  11.                 )
  12.             )
  13.         )
  14.         (vlax-for lay (vla-get-layouts doc)
  15.             (if (= :vlax-false (vla-get-modeltype lay))
  16.                 (vla-copyfrom lay cfg)
  17.             )
  18.         )
  19.     )
  20.     rtn
  21. )

Then, in your code:
Code - Auto/Visual Lisp: [Select]
  1. (applypstolayouts odbx "My Page Setup 1")

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Set default page setup
« Reply #8 on: August 01, 2017, 09:01:03 AM »
My original code basically a glorified script that opened files and processed them.

Now with the ODBX it works great, super fast, but it's not setting the page setup as the default when you go to the print dialog. My custom page setup is copied but it's not the active one. Does it work for you on your end? I'm not getting any kinds of error messages or crashing that would indicate it's not working.

I'm stumped.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Set default page setup
« Reply #9 on: August 01, 2017, 10:09:53 AM »
Going by memory, I didn't find a way to do this automatically with LISP - just adding the named set-ups to the list, and changing the settings for the active one.  Don't think I got around to looking at it from dotNET.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Set default page setup
« Reply #10 on: August 01, 2017, 01:35:54 PM »
That's the impression I'm getting from my searches.  I may have to go through the motion of plotting but not ACTUALLY plot using the page setup to set it as the default. Not exactly what I wanted to do.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Set default page setup
« Reply #11 on: August 01, 2017, 02:22:17 PM »
Now with the ODBX it works great, super fast, but it's not setting the page setup as the default when you go to the print dialog. My custom page setup is copied but it's not the active one. Does it work for you on your end? I'm not getting any kinds of error messages or crashing that would indicate it's not working.

Sorry Matt, the suggestion in my earlier post was only based on theory - I hadn't tested the feasibility of applying a page setup through ObjectDBX.
It's unfortunate that it would appear not to be possible through an ObjectDBX interface.  :-(

MrSmith

  • Newt
  • Posts: 23
Re: Set default page setup
« Reply #12 on: May 23, 2022, 07:42:46 PM »
That's the impression I'm getting from my searches.  I may have to go through the motion of plotting but not ACTUALLY plot using the page setup to set it as the default. Not exactly what I wanted to do.

Hi Matt! I am a few years late, but what Lee Mac suggested does work. You can copy the current layout object and paste it to other layouts without having to open the files. Unfortunately, AutoCAD has many DB Document bugs and one includes exporting named page setups by copying them. This does not cause problems when printing from the file directly; however, if you try to use an exported page setup via the Publish command, it will fail saying the pagesetup is not named.

Thankfully, Lee Mac has a solution to this problem in his Steal version 1.7 and greater, which basically modifies the dictionary by pulling the plot name from the entity. Unfortunately, this modification requires opening the drawing. I have written a method that will fix this problem via the AC Core Console which drastically speeds up the solution. Here is a very strip down example how I implemented it, devoid of most DLC and error checking, but should give you a good idea how it can work. (Note: Most of the support functions come from Lee Mac or was scraped from the interwebs).

To get the command to run, simply change "(setq files nil)" to the directory path containing the files you with to export the page setups to.
Example: (setq files "C:\\Users\\You\\Desktop\\Testland\\Page Setups")
Afterwards type "PageSetupBasicExport" in the drawing that has the named page setups you wish to export to the other drawings.


Code - Auto/Visual Lisp: [Select]
  1. (defun c:PageSetupBasicExport ( / files includeSubFolders SetDefaultSetup)
  2.         (setq files nil) ;Directory or list of files
  3.         (setq includeSubFolders nil) ;Change to 1 to include DWGs in subfolders
  4.         (setq SetDefaultSetup 1) ;Will set the drawings all to the same pagesetup layout
  5.         (pageSetupExport SetDefaultSetup files includeSubFolders)
  6.        
  7. )
  8.  
  9. (defun pageSetupExport (SetDefaultSetup files subfiles / vlaPageSetups notifyExit plotConfigNames directoryFiles DBXCopyPlotConfigs currentPageSetup fixPageSetupNames runActiveXFunctionOnDwgs pageSetups amt ct dwgName doc f pageSetups)
  10.         (defun notifyExit (msg) (alert msg) (princ (strcat "\n" msg)) (exit) ) ;Prints, alerts, and also exits the function
  11.         (defun plotConfigNames ( / out)
  12.                 (vlax-for x     (vla-get-plotconfigurations *acdoc*)
  13.                         (setq out (cons (strcase (vla-get-name x)) out))
  14.                 )
  15.                 (reverse out)
  16.         )
  17.         (defun directoryFiles ( path fileFolderNamePattern searchSubFolders / temp) ;Path is entire path where files/folders reside. FileFolderNamePattern is a wcmatchable string pattern for what to include. I.e. *.dwg for all dwg files.
  18.                 (setq path (vl-string-right-trim "\\" (vl-string-translate "/" "\\" path))) ;Nil on searchsubFolders to NOT search all folders.
  19.                 (if (> 259 (strlen (strcat fileFolderNamePattern path))) ;The fileFolderNamePattern search + length of filename/path can not be 259 or longer character length
  20.                         (progn
  21.                                 (append (mapcar '(lambda ( x ) (strcat path "\\" x)) (vl-directory-files path fileFolderNamePattern 1))
  22.                                         (if (and searchSubFolders (not (= 0 searchSubFolders)))
  23.                                                 (apply 'append
  24.                                                         (mapcar
  25.                                                            '(lambda ( x )
  26.                                                                         (if (not (or (= x ".") (= x "..")))
  27.                                                                                 (if (> 259 (strlen (strcat fileFolderNamePattern (setq temp (strcat path "\\" x)))))
  28.                                                                                         (directoryFiles temp fileFolderNamePattern 1)
  29.                                                                                         (list (debug "Too long: " (strlen (strcat fileFolderNamePattern temp))) (debug "Path: " temp) (debug "Pattern: " fileFolderNamePattern))
  30.                                                                                 )
  31.                                                                         )
  32.                                                                 )
  33.                                                                 (vl-directory-files path nil -1)
  34.                                                         )
  35.                                                 )
  36.                                         )
  37.                                 )
  38.                         )
  39.                         (debug "Path too long: " path)
  40.                 )
  41.         )
  42.         (defun DBXCopyPlotConfigs (plotConfigs setDefault / plt) ;DBX Function for copying plot configs to additional drawings
  43.                 (or
  44.                         vlaPageSetups
  45.                         (vlax-for x     (vla-get-plotconfigurations *acdoc*)
  46.                                 (if (member (strcase (vla-get-name x)) plotConfigs)
  47.                                         (setq vlaPageSetups (cons x vlaPageSetups))
  48.                                 )
  49.                         )
  50.                 )
  51.                
  52.                
  53.                 (setq plt (vla-get-plotconfigurations doc))
  54.                
  55.                 (vlax-map-collection plt 'vla-delete) ;Wipe all the current page setups incase of repeats
  56.                 (vlax-invoke *acdoc* 'copyobjects vlaPageSetups plt nil) ;Copy over the page setup from the source file
  57.  
  58.                 (if setDefault
  59.                         (vlax-for it (vla-get-layouts doc)
  60.                                 (if (not (= "Model" (vla-get-name it)))
  61.                                         (progn
  62.                                                 (vla-copyfrom it (vla-get-activelayout *acdoc*))
  63.                                                 ; (vlax-invoke it 'refreshplotdeviceinfo) ;I don't think this does anything....
  64.                                         )
  65.                                 )
  66.                         )
  67.                 )
  68.                 (princ)
  69.         )
  70.  
  71.         ;Returns the current layouts current pagesetup
  72.         (defun currentPageSetup ()
  73.                 (cdr (assoc 1 (entget
  74.                         (vlax-vla-object->ename (vla-item (vla-get-layouts *acdoc*) (getvar 'ctab)))
  75.                 )))
  76.         )
  77.  
  78.         (defun fixPageSetupNames (files / batFile scriptFile txt fl) ;AutoCAD has a bug when exporting pagesetups via ObjectDB where they are given an anoynomous name. This an be easily fixed Lee Mac's solution by pulling the entities page setup name and replace the anoynomous name with the real one
  79.                 (setq batFile (strcat (getvar "TEMPPREFIX") "ACADFixPageSetupNames.bat"))
  80.                 (setq scriptFile (strcat (getvar "TEMPPREFIX") "fixPageSetupNames.scr"))
  81.                 (setq txt "")
  82.                 (foreach it files (setq txt (strcat "\"" it "\"," txt)))
  83.                 (setq txt (vl-string-right-trim "," txt))
  84.                 (setq txt (strcat "FOR %%G IN (" txt ") DO \"" (findfile "accoreconsole.exe") "\" /i %%G /s \"" scriptFile "\""))
  85.                
  86.                 ;Write Bat File
  87.                 (if (setq fl (open batFile "w"))
  88.                         (progn
  89.                                 (write-line txt fl)
  90.                                 (close fl)
  91.                         )
  92.                 )
  93.                 ;Write Script File
  94.                 (if (setq fl (open scriptFile "w"))
  95.                         (progn
  96.                                 (write-line "((lambda (dic) (entmod (mapcar (function (lambda (a b) (if (and (= 003 (car a)) (= 350 (car b))) (cons 3 (cdr (assoc 1 (entget (cdr b))))) a))) dic (append (cdr dic) '( nil )))))(dictsearch (namedobjdict) \"ACAD_PLOTSETTINGS\")) qsave" fl)
  97.                                 (close fl)
  98.                         )
  99.                 )
  100.                 (startapp batFile)
  101.         )
  102.        
  103.         (defun runActiveXFunctionOnDwgs ( / vlaRelease checkAlreadyOpenedDWG massOpenFilesCheck setDBXObject dwl)
  104.                 (defun vlaRelease (obj) (if (= 'vla-object (type obj)) (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-release-object (list obj))))))
  105.                 (defun checkAlreadyOpenedDWG (filename / dwl f lst s)
  106.                         (if (and  ;See if a DWL exists and it can't be deleted
  107.                                         (setq dwl (findfile (strcat (vl-filename-directory filename) "\\" (vl-filename-base filename) ".DWL")))
  108.                                         (not (vl-file-delete dwl))
  109.                                 )
  110.                                 (if (setq f (open dwl "r")) ;Open it to get its info
  111.                                         (progn
  112.                                                 (while (setq s (read-line f)) (setq lst (cons s lst)))
  113.                                                 (close f)
  114.                                                 (strcat "Drawing [" fileName "] is currently opened by User: " (strcase (caddr lst)) " on computer " (strcase (cadr lst)))
  115.                                         )
  116.                                         nil ;Otherwise not open
  117.                                 )
  118.                         )
  119.                 )
  120.                 (defun massOpenFilesCheck (filesToCheck / openList) ;checks to see if any of the files are already opened
  121.                         (setq filesToCheck (mapcar 'strcase filesToCheck))
  122.                         (vlax-for doc (vla-get-documents *acad*) ;We can have files we have open in our autocad
  123.                                 (setq filesToCheck (vl-remove (strcase (vla-get-fullname doc)) filesToCheck)) ;Used to make sure we are not opening already open drawings
  124.                         )
  125.                         (setq openList (vl-remove nil (mapcar 'checkAlreadyOpenedDWG filesToCheck))) ;This list is not just the fileName, includes additional information i.e. who has it open
  126.                         (if openList ;If files are open, give the user the option to close out
  127.                                 (progn ;Print the results
  128.                                         (princ "\nThe following files are opened and need to be closed:")
  129.                                         (mapcar '(lambda(x) (princ (strcat "\n" x))) openList)
  130.                                         (princ "\n")
  131.                                         (exit)
  132.                                 )
  133.                         )
  134.                 )
  135.                 (defun setDBXObject ( dbx / vrs) ;Sets the DBX Object, from Lee
  136.                         (if (or (not (eval dbx)) (= 'vla-object (type (eval dbx))))
  137.                                 (set dbx (vl-catch-all-apply 'vla-getinterfaceobject
  138.                                         (list (setq *acad* (vlax-get-acad-object))
  139.                                                 (if (< (setq vrs (atoi (getvar 'acadver))) 16) "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs)))))
  140.                                 )
  141.                         )
  142.                         (if (or (null (eval dbx)) (vl-catch-all-error-p (eval dbx))) (notifyExit "\nUnable to interface with ObjectDBX."))
  143.                 )
  144.                 (setDBXObject '*dbx*)
  145.                 (massOpenFilesCheck files)
  146.                 (vlax-for doc (vla-get-documents *acad*)
  147.                         (setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl)) ;Used to make sure we are not opening already open drawings
  148.                 )
  149.                 (setq amt (length files))
  150.                 (setq ct 1)
  151.                 (if ctrl (princ (strcat "\nBeginning to Process [" (itoa amt)"] Drawings.")))
  152.                 (foreach dwg files
  153.                         (if (not (setq dwgName (fnsplitl dwg)))
  154.                                 (princ (strcat "\nDrawing Name is unprocessable! See DWG: " dwg))
  155.                                 (progn
  156.                                         (setq dwgName (strcat (cadr dwgName) (caddr dwgName)))
  157.                                         (if
  158.                                                 (if (setq doc (cdr (assoc (strcase dwg) dwl))) ;Already Opened File, set doc to it
  159.                                                         (setq f 1) ;Set the doc is already open variable, we can use it to regen the viewport. Unopened documents will get generated when opened.
  160.                                                         (and
  161.                                                                 (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list *dbx* dwg)))) ;Else, open the drawing via *dbx*
  162.                                                                 (setq doc *dbx*)
  163.                                                         )
  164.                                                 )
  165.                                                 (progn
  166.                                                         (princ (strcat "\nCurrently in Drawing: [" (itoa ct) "] (" dwgName ") out of [" (itoa amt)"]"))
  167.                                                         (DBXCopyPlotConfigs pageSetups SetDefaultSetup) ;function uses the doc variable set above
  168.                                                         (vlax-invoke-method doc 'Saveas dwg)
  169.                                                         (if f (progn (vla-regen doc acActiveViewport) (setq f nil))) ;Drawing is already open, regen viewport just incase.
  170.                                                         (setq ct (+ ct 1))
  171.                                                 )
  172.                                                 (progn ;warn of failure
  173.                                                         (princ (strcat "\nUnable to interface with Drawing: [" (itoa ct) "] (" dwgName "). Drawing may be open!"))
  174.                                                         (setq ct (+ ct 1))
  175.                                                 )
  176.                                         )
  177.                                 )
  178.                         )
  179.                 )
  180.                 (vlaRelease *dbx*)
  181.         )
  182.         (setq pageSetups (plotConfigNames))
  183.         (cond
  184.                 ((or (not files) (= "" files)) ;No drawings selected
  185.                         (notifyExit "ERROR: No DWG(s) Selected to Export Page Setups Into!") ;No DWG(s) Set to export page setups into
  186.                 )
  187.                 ((and (= (type files) 'STR)(not (vl-file-directory-p (vl-string-translate "/" "\\" files))))
  188.                         (notifyExit "ERROR: DWGs Process Directory Does Not Exist!") ;Incorrect directory for processing DWGs
  189.                 )
  190.                 ((not pageSetups)
  191.                         (notifyExit "ERROR: No Page Setups Selected to Export!") ;No page setups selected
  192.                 )
  193.                 (T ;Everything good, Run the script
  194.                         (if (= 'STR (type files)) ;get the files if files is a directory
  195.                                 (setq files (directoryFiles files "*.dwg" subfiles))
  196.                                 (setq files files)
  197.                         )
  198.                         (setq files (vl-remove (vla-get-fullname *acdoc*) files)) ;Don't need to be deleting the current drawings stuff :'(
  199.                         (if SetDefaultSetup
  200.                                 (progn
  201.                                         (alert "SET CURRENT the Page Setup to apply as default for all drawings.")
  202.                                         (COMMAND "_.PAGESETUP")
  203.                                         (if (= "" (currentPageSetup))
  204.                                                 (notifyExit "ERROR: Current Page Setup set to None!")
  205.                                         )
  206.                                         (setq  
  207.                                                 Layts (vla-get-layouts *acdoc*)
  208.                                                 clyt  (vla-get-activelayout *acdoc*)
  209.                                         )
  210.                                         (foreach itm (vl-remove (vla-get-name clyt) (layoutlist))
  211.                                                 (vla-copyfrom (vla-item Layts itm) clyt)
  212.                                         )
  213.                                 )
  214.                         )
  215.                         (runActiveXFunctionOnDwgs)
  216.                         (fixPageSetupNames files)
  217.                         (print "Page Setups exported successfully!")
  218.                         (princ)
  219.                 )
  220.         )
  221. )

code=cadlisp-7  mod' kdub
« Last Edit: May 23, 2022, 08:49:26 PM by kdub »

BlackBox

  • King Gator
  • Posts: 3770
Re: Set default page setup
« Reply #13 on: May 24, 2022, 10:02:30 AM »
Always when I hear "set a page setup in a layout" it reminds me of BlackBox's work.

Anyway nice job Lee! 8)

I'm a big fan of Lee's work also. :beer:

FWIW, the code Grrr1337 linked to from 2013 still works in 2023 today; it plays nicely with ObjectDBX & Core Console for batch processing.

If you need to iterate layoutlist in Core Console, to supply the layoutName parameter to vla-SetActivePageSetup:

http://www.theswamp.org/index.php?topic=57471.msg609440#msg609440

HTH

"How we think determines what we do, and what we do determines what we get."

MrSmith

  • Newt
  • Posts: 23
Re: Set default page setup
« Reply #14 on: May 24, 2022, 11:48:20 AM »
Hey BB! I came across your work when researching methods to solve the issue. I definitely think it is the "best" way and it is a tragedy that ACAD hasn't implemented the function into their VLA library by default. However, I ended up not pursuing it for three reasons.
  • I didn't know how to compile or even install it.
  • I wasn't sure how I'd push it out to all other CAD users in the company.
  • Each new release of ACAD has to have the XML revised to work for it.

I am sure I could have overcame these issues, but it seems like the current method of copying the active page layout from the current tab to other tabs appears to work without issue. Bugs appear in the exporting page layouts portion which require the document to be opened up and the page setup dictionary modified.