Push PageSetup changes to Layout with LISP

Push PageSetup changes to Layout with LISP

Anonymous
Not applicable
2,951 Views
12 Replies
Message 1 of 13

Push PageSetup changes to Layout with LISP

Anonymous
Not applicable

Hi all,

 

What I need is kind of hard for me to explain. Instead I recorded a short video showing what I mean. Basically I was wondering if there is chance that I could avoid Running PageSetup window everytime, press Modify button and then OK it to update my background to fit the viewport. (Am I write on terminologies here ?!)

 

 

Regards

0 Likes
Accepted solutions (1)
2,952 Views
12 Replies
Replies (12)
Message 2 of 13

hencoop
Advisor
Advisor

I have a lisp routine I use to set page setups.

setstdpage.lsp which requires several subroutines:

Doslib (free from Robert McNeeal & Associates

check_for_doslib (to load the correct version)

ukword (our initget - getkword handler)

ustr (our initget - getstring handler)

 

It hard codes the path to our template files that contain the pagesetups we use.

The template files are swapped out depending upon the user because AutoCAD 2013 page setups used by one user are incompatible with other versions of AutoCAD we use (at least as currently installed here).

 

If you replace our template section of the code setting your template path it should work for you.  Removing our template code may eliminate the need for DOSLIB and thus CHECK_FOR_DOSLIB.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 3 of 13

joselggalan
Advocate
Advocate

Try one of these two functions.
Ideally, it should work with the first one (RefreshAllLayout_1)

 

 

 (defun C:RefreshAllLayout_1 ( / oLayout AcDoc)
  (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vlax-for oLayout (vla-get-layouts AcDoc)
    (cond
     ((= (vla-get-ModelType oLayout) :vlax-true))
     (T
      (vla-RefreshPlotDeviceInfo oLayout)
     )
    );c.cond 
   )
  (princ)
 )
(defun C:RefreshAllLayout_2 ( / oLayout NameLayout AcDoc oActLayout)
  (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
   (setq oActLayout  (vla-get-ActiveLayout AcDoc))
   (vlax-for oLayout (vla-get-layouts AcDoc)
    (cond
     ((= (vla-get-ModelType oLayout) :vlax-true))
     (T
      (vla-put-ActiveLayout AcDoc oLayout)
      (vla-ZoomExtents (vlax-get-acad-object))
      (vla-RefreshPlotDeviceInfo oLayout)
      (vla-Regen AcDoc acActiveViewport)
     )
    );c.cond 
   )
   (vla-put-ActiveLayout AcDoc oActLayout)
  (princ)
 )
0 Likes
Message 4 of 13

Anonymous
Not applicable

Dude, I am using your first code. Although it does the job but I noticed some weird behaviour. 

 

Here is how my layout looks like before running your code:

 

1.jpg2.jpg

 

Immediately after running your code, here is what I get:

 

3.jpg4.jpg

 

 

Any idea why the plot unit is changed to "INCH"?

0 Likes
Message 5 of 13

hencoop
Advisor
Advisor

The Page Setup should have a name.  The program sets the page setup by name.  If after it has been set the name is <None> then there is a problem with the source of the page setup being used or it is coming from a template file that was last saved from a different version of AutoCAD.  

 

The change of units is part of this problem.

 

In our office one user is on Civil 3D 2013. Its page setups will produce similar results in my Civil 3D 2014.  Use a template file that you have created or revised.  Set your desired page setup settings and then use the Add... button to update the definitions to make them work in your sessions.

 

PageSetup.jpg

 

Also, if you are plotting a layout the plot area is best if set to "Layout" which will always correspond to the paper size of your page setup.  Plotting Layout is highly recommended for its easy association with a Sheet Set to access its great plotting and publishing abilities.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 6 of 13

joselggalan
Advocate
Advocate

try this

 

(defun C:RefreshAllLayout_1 (/ oLayout AcDoc)
 (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (vlax-for oLayout (vla-get-layouts AcDoc)
  (cond
   ((= (vla-get-ModelType oLayout) :vlax-true))
   (T
    (vla-RefreshPlotDeviceInfo oLayout)
    (vla-put-PaperUnits oLayout acMillimeters)
    )
   );c.cond 
  );c.vlax-for
 (princ)
);c.defun
0 Likes
Message 7 of 13

Anonymous
Not applicable
That's more or less what I am trying to achieve in 1000+ drawings I have in front of me for a brown field job. I need LISP routines for this mean. But thanks for the reply.
0 Likes
Message 8 of 13

Anonymous
Not applicable

Nothing happens i.e. no refreshing whatsoever. 

0 Likes
Message 9 of 13

joselggalan
Advocate
Advocate

You can put a sample dwg file, to try .. thanks

 

0 Likes
Message 10 of 13

Anonymous
Not applicable

Sample file attached. Tnx for your help.

 

EDIT:

-----------------

 

I think I found out what was wrong. The line (command "regenall") was missing. 

0 Likes
Message 11 of 13

joselggalan
Advocate
Advocate

Anyway, try this...

 

(defun C:RefreshAllLayout_3 (/ acApp AcDoc oActLayout oLayout
			       PlotOrigin PaperUnits PlotType CenterPlot
			    )	  
 (setq acApp (vlax-get-acad-object))
 (setq AcDoc (vla-get-ActiveDocument acApp))
 (setq oActLayout  (vla-get-ActiveLayout AcDoc))
 (vlax-for oLayout (vla-get-layouts AcDoc)
  (cond
   ((= (vla-get-ModelType oLayout) :vlax-true))
   (T
    (vla-put-ActiveLayout AcDoc oLayout)
    (setq PaperUnits (vla-get-PaperUnits oLayout))
    (setq PlotOrigin (vla-get-PlotOrigin oLayout))
    (setq PlotType   (vla-get-PlotType oLayout))
    (setq CenterPlot (vla-get-CenterPlot oLayout))
    
    (vla-RefreshPlotDeviceInfo oLayout)
    (vla-put-PaperUnits oLayout PaperUnits)
    (vla-put-PlotOrigin oLayout PlotOrigin)
    (vla-put-PlotType oLayout acExtents)
    (vla-Regen AcDoc acActiveViewport)
    (vla-ZoomExtents acApp)
    (vla-put-CenterPlot oLayout CenterPlot)
    (vla-put-PlotType oLayout PlotType)
   )
  );c.cond 
 );c.vlax-for
 (vla-put-ActiveLayout AcDoc oActLayout)
 (princ)
);c.defun
0 Likes
Message 12 of 13

joselggalan
Advocate
Advocate
Accepted solution

Apologies, some code was missing so that everything went well.

 

 

(defun C:RefreshAllLayout_3 (/ acApp AcDoc oActLayout oLayout
			       PlotOrigin PaperUnits PlotType CenterPlot
			    )	  
 (setq acApp (vlax-get-acad-object))
 (setq AcDoc (vla-get-ActiveDocument acApp))
 (setq oActLayout  (vla-get-ActiveLayout AcDoc))
 (vlax-for oLayout (vla-get-layouts AcDoc)
  (cond
   ((= (vla-get-ModelType oLayout) :vlax-true))
   (T
    (vla-put-ActiveLayout AcDoc oLayout)
    (if (= (vla-get-MSpace AcDoc) :vlax-true)
     (vla-put-MSpace AcDoc :vlax-false)
    )
    (setq PaperUnits (vla-get-PaperUnits oLayout))
    (setq PlotOrigin (vla-get-PlotOrigin oLayout))
    (setq PlotType   (vla-get-PlotType oLayout))
    (setq CenterPlot (vla-get-CenterPlot oLayout))
    
    (vla-RefreshPlotDeviceInfo oLayout)
    (vla-put-PaperUnits oLayout PaperUnits)
    (vla-put-PlotOrigin oLayout PlotOrigin)
    (vla-put-PlotType oLayout acExtents)
    (vla-Regen AcDoc acActiveViewport)
    (vla-ZoomExtents acApp)
    (vla-put-CenterPlot oLayout CenterPlot)
    (vla-put-PlotType oLayout PlotType)
   )
  );c.cond 
 );c.vlax-for
 (vla-put-ActiveLayout AcDoc oActLayout)
 (princ)
);c.defun
0 Likes
Message 13 of 13

Anonymous
Not applicable
This one works exactly as I wanted to.

Thank you so much for your time.
0 Likes