Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Import page setup and make it current for the current layout or layouts

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Sandervp
5437 Views, 10 Replies

Import page setup and make it current for the current layout or layouts

Hello everybody,

 

I want to import one or more page setups into a drawing. It is easy to import them with the "-psetupin" command. But how can I make the imported page setup current?

 

I found some lisp files on the internet but they doesn't work if I combine these..

 

The first part of the lisp shall remove all the excisting page setups in the drawing and, after that, it's shall import the specific page setup I want to make current for the layout. But after importing this page setup, I need to make it current manually. It must change automatically.

 

The lisp file has to do the following steps in this order;

  • Delete all the created page setups in the drawing:
    (vl-load-com) (vlax-for pc (vla-get-plotconfigurations (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-delete pc) )
  • Import the specific page setup for the current layout you'll see on your screen.
  • (command "._-PSETUPIN" "C:/Users/myself/AppData/Roaming/Autodesk/AutoCAD 2015/R20.0/enu/Plotters/PAGE_SETUP_PDF.dwg" "example1")
  • Make the imported page setup current. If you have more layouts, you must switch to the other for make another or the same page setup current. (maybe is it possible to add a function which will let you choose "make this page setup current for "All" or "Current Layout only")
  • ;; Set multiple layouts to a page setup
    (defun c:-MPageSetup (/ PS-Lst PS Tabs TabSel str val)
      ;; Get the Layout Tabs to be changed
      (setq Tabs (Get-Obj-Names (Get-Tab-Col)))
      (princ "\n\nAvailable Layout Tabs: ")
      (foreach str Tabs
        (princ str)
        (princ " | ")
      )
      (setq TabSel nil str nil)
      (while (and (not str) (setq str (vl-string-trim " \t\n" (strcase (getstring t "\nSelect the tabs you wish to apply the setup to [*=All; or Add each in turn; blank to stop]: ")))))
        (cond
          ((= str "") (if (not TabSel) (setq TabSel Tabs)))
          ((= str "*") (setq TabSel Tabs))
          ((setq val (member str Tabs)) (setq TabSel (cons (car val) TabSel) str nil))
          (T (princ (strcat str " is not an available Tab Name\n")) (setq str nil))
        )
        (princ "Selected Tabs: ")
        (if TabSel
          (foreach val TabSel
    	(princ val)
    	(princ " | ")
          )
        )
      )
    
      (setq PS-Lst (Get-Obj-Names (Get-PS-Col)))
      (princ "\n\nAvailable Plot Setups: ")
      (foreach str PS-Lst
        (princ str)
        (princ " | ")
      )
      (setq PS nil str nil)
      (while (and (not str) (setq str (vl-string-trim " \t\n" (strcase (getstring t "\nSelect the Setup you wish to apply: ")))))
        (cond
          ((setq val (member str PS-Lst)) (setq PS (car val)))
          (T (princ (strcat str " is not an available Setup\n")) (setq str nil))
        )
      )
    
      (princ (strcat "\nAbout to assign " PS " to " (vl-prin1-to-string TabSel)))
      (MpageSetup TabSel PS)
      
      (princ)
    )
  • Delete all the imported page setups in the drawing. (code first step)

 

If I create a new command/ lisp (defun C:PSN .........) by following these codes. It doesn't work. But if I load more lisp files, with only 1 code, there are no problems. I only have to select the layout if I use the -mpagestup command. 

 

 

I want to create a toolbar with several buttons for different page setups for the (current) layout(s).

for example:  One for make the "example1" page setup current for the current layout, one for "example3" and "example4" for all the layouts.

 

Who wants to help me?

 

 

10 REPLIES 10
Message 2 of 11
hmsilva
in reply to: Sandervp

Hi Sandervp,

'Import page setup and make it current for the current layout or layouts'

To set a Layout with a Page Setup, try to use the 'copyfrom' method, from the 'PlotConfigurations' collection to the target(s) Layout(s)

i.e.

; name - the Page Setup Name
; all - a flag, T for all nil for current layout
(defun SetNamePageSetupAllLayouts (name all / lst)
   (or adoc (setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (if (vl-position
          name
          (vlax-for pltcfg (vla-get-plotconfigurations adoc)
             (setq lst (cons (vlax-get pltcfg 'Name) lst))
          )
       )
      (progn
         (vlax-for layt (vla-get-Layouts adoc)
            (if (/= (vla-get-name layt) "Model")
               (if all
                  (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) name))
                  (if (= (vla-get-name layt) (getvar 'ctab))
                     (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) name))
                  )
               )
            )
         )
         (vla-Regen adoc acActiveViewport)
      )
   )
)

; for all layouts
(defun c:demo nil
   (SetNamePageSetupAllLayouts "example3" T)
   (princ)
)

; just active layout
(defun c:demo1 nil
   (SetNamePageSetupAllLayouts "example1" nil)
   (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 11
Sandervp
in reply to: hmsilva

Hello HMSilva,

 

I do not understand your lisp/ code.

 

I've changed "name" into the wanted page setup. The commands are working (I don't get an error) but they don't do anything.

How do I have to use this lisp exactly?

 

Message 4 of 11
hmsilva
in reply to: Sandervp


@Sandervp wrote:

Hello HMSilva,

 

I do not understand your lisp/ code.

 

I've changed "name" into the wanted page setup. The commands are working (I don't get an error) but they don't do anything.

How do I have to use this lisp exactly?

 


Hi Sandervp,

the code will set the named page setup current, in active layout or all layouts.

You must import the named page setup and then run the code.

If the 'named page setup' exist in the dwg, the code will set it current...

 

Hope this helps,
Henrique

EESignature

Message 5 of 11
Sandervp
in reply to: hmsilva

Hello again Hmsilva,

 

I've changed every "name" in your code into the page setup name called "A2", also "example3" and "example1" at the end of the code.

 

If I use the lisp commands, after importing the A2 page setup, the following error appears in the command line;

DEMO ActiveX Server returned the error: unknown name: "A2"

 

Did I changed too much?

 

 

Message 6 of 11
hmsilva
in reply to: Sandervp


@Sandervp wrote:

Hello again Hmsilva,

 

I've changed every "name" in your code into the page setup name called "A2", also "example3" and "example1" at the end of the code.

 

If I use the lisp commands, after importing the A2 page setup, the following error appears in the command line;

DEMO ActiveX Server returned the error: unknown name: "A2"

 

Did I changed too much?

 

 


Yes... 😞

 

Main function (don't change it)

; name - the Page Setup Name
; all - a flag, T for all nil for current layout
(defun SetNamePageSetupAllLayouts (name all / lst)
   (or adoc (setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (if (vl-position
          name
          (vlax-for pltcfg (vla-get-plotconfigurations adoc)
             (setq lst (cons (vlax-get pltcfg 'Name) lst))
          )
       )
      (progn
         (vlax-for layt (vla-get-Layouts adoc)
            (if (/= (vla-get-name layt) "Model")
               (if all
                  (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) name))
                  (if (= (vla-get-name layt) (getvar 'ctab))
                     (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) name))
                  )
               )
            )
         )
         (vla-Regen adoc acActiveViewport)
      )
   )
)

 

To call the main function:

 

; to change to A2 all layouts
(defun c:demo nil
   (SetNamePageSetupAllLayouts "A2" T)
   (princ)
)

; to change to A2 just the active layout
(defun c:demo1 nil
   (SetNamePageSetupAllLayouts "A2" nil)
   (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 7 of 11
Sandervp
in reply to: hmsilva

Thank you very much!

Message 8 of 11
hmsilva
in reply to: Sandervp


@Sandervp wrote:

Thank you very much!


You're welcome, Sandervp
Glad I could help! 🙂

Henrique

EESignature

Message 9 of 11
Automohan
in reply to: hmsilva

Not working for me..... 

My pagesetup name = pdf.m-2021

; name - the Page Setup Name
; all - a flag, T for all nil for current layout
(defun SetNamePageSetupAllLayouts (pdf.m-2021 all / lst)
   (or adoc (setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (if (vl-position
          pdf.m-2021
          (vlax-for pltcfg (vla-get-plotconfigurations adoc)
             (setq lst (cons (vlax-get pltcfg 'pdf.m-2021) lst))
          )
       )
      (progn
         (vlax-for layt (vla-get-Layouts adoc)
            (if (/= (vla-get-name layt) "Model")
               (if all
                  (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) pdf.m-2021))
                  (if (= (vla-get-name layt) (getvar 'ctab))
                     (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) pdf.m-2021))
                  )
               )
            )
         )
         (vla-Regen adoc acActiveViewport)
      )
   )
)
; to change to A2 all layouts
(defun c:demo nil
   (SetNamePageSetupAllLayouts "pdf.m-2021" T)
   (princ)
)

; to change to A2 just the active layout
(defun c:demo1 nil
   (SetNamePageSetupAllLayouts "pdf.m-2021" nil)
   (princ)
)
"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
Message 10 of 11
hmsilva
in reply to: Automohan


@Automohan wrote:

Not working for me..... 

My pagesetup name = pdf.m-2021


Did you read what I wrote in post #6

 

;Main function (don't change it)
; name - the Page Setup Name
; all - a flag, T for all nil for current layout
(defun SetNamePageSetupAllLayouts (name all / lst)
   (or adoc (setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (if (vl-position
          name
          (vlax-for pltcfg (vla-get-plotconfigurations adoc)
             (setq lst (cons (vlax-get pltcfg 'Name) lst))
          )
       )
      (progn
         (vlax-for layt (vla-get-Layouts adoc)
            (if (/= (vla-get-name layt) "Model")
               (if all
                  (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) name))
                  (if (= (vla-get-name layt) (getvar 'ctab))
                     (vla-copyfrom layt (vla-item (vla-get-PlotConfigurations adoc) name))
                  )
               )
            )
         )
         (vla-Regen adoc acActiveViewport)
      )
   )
)
;To call the main function:
; to change to pdf.m-2021 all layouts 
;change demo to what better serves
(defun c:demo nil
   (SetNamePageSetupAllLayouts "pdf.m-2021" T)
   (princ)
)
; to change to pdf.m-2021 just the active layout 
; change demo1 to what better serves
(defun c:demo1 nil
   (SetNamePageSetupAllLayouts "pdf.m-2021" nil)
   (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 11 of 11
Automohan
in reply to: hmsilva

😇Sorry ! I was in hurry movement ! Very urgent situation nearly 200 dwgs. pagesetup done manually...

ok, i will use it next onwards.....

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost