Jump to content

How to Add a Pagesetup in a lisp?


ILoveMadoka

Recommended Posts

Once you get all your plot settings configured the way you want in a lisp,

How can you ADD a Page Setup (Name)?

 

image.png.c3fc316ee219df3a583ce1930a930a0c.png

 

I would like to do it as part of the routine to eliminate user interaction if possible.

 

I was hoping the -plot command would give me the option to assign a name but it does not..

 

Quote

Save changes to page setup [Yes/No]? <N> y
Proceed with plot [Yes/No] <Y>: n

 

Quote

Command: -PAGESETUP
Enter an output device name or [?] <Adobe PDF>:
Enter paper size or [?] <Tabloid>:
Enter paper units [Inches/Millimeters] <Inches>:
Enter drawing orientation [Portrait/Landscape] <Landscape>:
Plot upside down? [Yes/No] <No>:
Enter plot area [Display/Extents/Layout/View/Window] <Extents>:
Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <Fit>:
Enter plot offset (x,y) or [Center] <Center>:
Plot with plot styles? [Yes/No] <Yes>:
Enter plot style table name or [?] (enter . for none) <CG_Lineweight.ctb>:
Plot with lineweights? [Yes/No] <Yes>:
Scale lineweights with plot scale? [Yes/No] <No>:
Plot paper space first? [Yes/No] <No>:
Hide paperspace objects? [Yes/No] <No>:

 

Edited by ILoveMadoka
Link to comment
Share on other sites

I use a template with all my setups, then command "PSETUPIN" to import.

 

If you want to use lisp to add one it's as simple as this:

(vla-add (vla-get-PlotConfigurations (vla-get-ActiveDocument (vlax-get-acad-object)))"TEST")

But then you also have to set the appropriate properties ... IMO it's much easier to use a template.

Edited by ronjonp
  • Like 1
  • Agree 1
Link to comment
Share on other sites

4 hours ago, ILoveMadoka said:

Once you get all your plot settings configured the way you want

 

 

I do this by then save as template .dwt already has title block inserted with multiple tabs. then you just have to use -layout  & import from template.

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

I output to about 5 page sizes and have Page Setups for both hard copies and PDF's for each of them. 

I'd recommend importing your Page Setups as you need them instead of recreating them.

You could do it with a -PSETUPIN (Command) macro easily enough.

 

As I create my drawings in Model Space to start it's easiest for me to import the layouts and Page Setups I need using Lee Mac's Lisp Steal from Drawing.

This macro example copies an "11×17" Layout from my default qnew template along with two Page Setups "11×17" & "11×17 PDF" one for sending to a printer and the other for creating a PDF.

^C^C^P(Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "11×17" "11×17 PDF"))(list "Layouts" (list "11×17"))))

 My first two items in my Plot drop-down in the Ribbon are "Quick Plot current layout" & Quick Plot to PDF into drawing folder. Having all drawing output automated saves a lot of time.

  • Like 1
Link to comment
Share on other sites

Do mine a bit different.

Have a list of all the tab names of my template drawing [1-25] Ask how many pages they want inserted add +1 to count the cover page.

pick to insert 6 pages it will delete the 7th position in the list until the list length is less then 7

convert that list to a string named layout.  (Cover Page1 Page2 ....) "Cover,Page1,Page2, ..."

Feed that string into layout command with path to template file.

You will have a cover page and 1-6 tabs with title blocks, default view ports, default notes, anything default you want really.

 

(vl-cmdf "_.Layout" "T" (strcat (getenv "userprofile") "\\Dropbox\\LANSCAPE_TITLE_BLOCK_REV-1.dwt") layout)

 

 

Link to comment
Share on other sites

5 hours ago, mhupp said:

Do mine a bit different.

Whatever works!

Besides speeding the workflow automation reduces the chance for human error. What title block attributes cannot be set automatically can either be picked from a list like the name and registration # of the engineer signing the plans or prompted for like the Field Book #. Repetitive tasks done with every drawing shouldn't take up more than a few minutes. All the drawing details we use are saved in one Typicals drawing available with a click to pick and choose for a detail sheet. Drawing something more that once is a waste of time.

  • Agree 1
Link to comment
Share on other sites

ronjonp - Thank you..

 

I am posting this because I found quite a few people looking to do this very thing when I was searching.

 

(defun c:ppdf ()
;;Creates a Page Setup
(command "-PLOT" "y" " " "Adobe PDF" "Tabloid" "Inches" "Landscape" "No" "Extents" "Fit" "Center" "Yes" "YOURNAMEHERE.ctb" "No" "No" "Yes" "No" "N" "Yes" "N")
(vla-add (vla-get-PlotConfigurations (vla-get-ActiveDocument (vlax-get-acad-object)))
"PDF") 
(princ))

 

The routine creates the page setup and it is available in the drop down

My next question is how do I make it "active?" so that is is selected/displayed?

 

image.png.0bd2bc4ded127c1f80e6abb74d925efd.png

 

ps: I do have (and use) templates with the Page Setup fully configured.

I was looking for an easy fix for legacy drawings

 

Edited by ILoveMadoka
Link to comment
Share on other sites

The macro's for first two items in my Plot drop-down in the Ribbon are "Quick Plot current layout" & Quick Plot to PDF into drawing folder use this lisp to use the correct Plot Style and Printer/Plotter for the current Layout size. It's setup for our sizes and Plot Styles and also uses Lee Mac's Lisp Steal from Drawing which I load with acaddoc.lsp since I use it a lot. Just a basic concept since the Page Setups, Sizes and file locations would be different for anyone else.

;| Create PageSetups for current Layout
^C^C(pdfPlot)
(load "getCurrentPagesetup")(pdfPlot)
^C^C(QuickPlot)
(load "getCurrentPagesetup")(QuickPlot)
^C^C(getCurrentPagesetup (getvar "ctab"));-Plot;No;;;;No;No;Yes
(load "getCurrentPagesetup")(getCurrentPagesetup (getvar "ctab"))
|;
(defun getCurrentPagesetup (layout / lst PSname PSdim data)
  (setq lst (dictsearch (namedobjdict) "acad_layout")
  		lst (dictsearch (cdar lst) layout)
  )
  (setq
		PSname (cdr(assoc 1 lst))
		lst (member '(100 . "AcDbPlotSettings") lst)
		data (cadr lst)
		PSdim (PaperSize)
  )
  (princ "\nPSdim = ")(princ PSdim)
  (princ "\n")
  (cond
	((= PSdim "8½×11")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "8½×11" "8½×11 PDF")))); .regen
	)
	((= PSdim "11×8½")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "11×8½" "11×8½ PDF")))); .regen
	)
	((= PSdim "8½×14")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "8½×14" "8½×14 PDF")))); .regen
	)
	((= PSdim "14×8½")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "14×8½" "14×8½ PDF")))); .regen
	)
	((= PSdim "11×17")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "11×17" "11×17 PDF")))); .regen
	)
	((= PSdim "18×24")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "18×24" "18×24 PDF")))); .regen
	)
	((= PSdim "24×36")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "24×36" "24×36 PDF")))); .regen
	)
	((= PSdim "22×34")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "22×34" "22×34 PDF")))); .regen
	)
	((= PSdim "34×22")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "34×22" "34×22 PDF")))); .regen
	)
	((= PSdim "36×48")
	  (Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "Templates.dwt") (list (list "Page Setups" (list "36×48" "36×48 PDF")))); .regen
	)
	(T (princ "\nDrawing not saved!"))
  )
  (SetCurrentPageSetup (vla-get-activedocument (vlax-get-acad-object)) PSdim)
  (PaperSize)
)

(defun QuickPlot ( / CPgSetup pathPDF)
  (setq CPgSetup(getCurrentPagesetup (getvar "ctab"))
        pathPDF (strcat (getvar "DWGPREFIX")(vl-filename-base (getvar "dwgname"))" - "(getvar "ctab"))
  )
  (if CPgSetup
	(progn
	  (vl-file-delete (strcat CPgSetup))		;http://forums.augi.com/showthread.php?173337-Check-if-PDF-is-open-Delete-if-not&p=1341076&viewfull=1#post1341076
	  (command "_.-PLOT" "No" ""  ""  "" "" "" "Yes")
	  (if (> (getvar "cmdactive") 0)
		(progn
		  (command "No")
		  (princ (alert (strcat pathPDF " cannot be plotted because it's Open in Adobe Acrobat!")))
		)
		(princ (strcat pathPDF " saved."))
	  )
	)
  )
  (princ)
)

(defun pdfPlot ( / CPgSetup pathPDF)
  (setq CPgSetup(getCurrentPagesetup (getvar "ctab"))
        pathPDF (strcat (getvar "DWGPREFIX")(vl-filename-base (getvar "dwgname"))" - "(getvar "ctab"))
  )
  (if CPgSetup
	(progn
	  (vl-file-delete (strcat CPgSetup " PDF"))		;http://forums.augi.com/showthread.php?173337-Check-if-PDF-is-open-Delete-if-not&p=1341076&viewfull=1#post1341076
	  (or(vl-string-search " PDF" CPgSetup)(setq CPgSetup(strcat CPgSetup " PDF")))
	  (command "_.-PLOT" "No" "" CPgSetup "" pathPDF "No" "Yes")
	  (if (> (getvar "cmdactive") 0)
		(progn
		  (command "No")
		  (princ (alert (strcat pathPDF " cannot be plotted because it's Open in Adobe Acrobat!")))
		)
		(princ (strcat pathPDF " saved."))
	  )
	)
  )
  (princ)
)

(defun PaperSize (/ psn scale LayW LayH dx)

  (defun Trl0s (String); remove trailing zero(s) beyond the decimal
  ; Thanks Kent1Cooper http://www.arch-pub.com/Help-modifying-this-Lisp_10737978.html
      (if (= (rem (atof String) 10.0) 0); it's a whole multiple of 10 keep any zero(s) before the decimal
		(itoa (atoi String)); then convert to interger, then back to a string
		(vl-string-right-trim ".0" String); else remove trailing zero(s) beyond the decimal
      ); if
  )

  (setq
    psn	(member	'(100 . "AcDbPlotSettings")
		(dictsearch
		  (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
		  (getvar "ctab")
		)
	)
  )
;  (princ "\npsn = ")(princ psn)
  (if (= (caadr psn) 1) ; Page Setup Name exist
    (progn
	  (setq scale (if (= 0 (cdr (assoc 72 psn))) 25.4 1.0)
		LayW (Trl0s (rtos (/ (cdr (assoc 44 psn)) scale) 2 2))
		LayH (Trl0s (rtos (/ (cdr (assoc 45 psn)) scale) 2 2))
		LayW (vl-string-subst "½" ".5" LayW)
		dx (- (car (getvar 'limmax))(car (getvar 'limmin)))
	  )
;	  (princ "\n(/ (cdr (assoc 44 psn)) scale) = ")(princ (/ (cdr (assoc 44 psn)) scale))
;	  (princ "\ndx = ")(princ dx)(princ "\n")
	  (if (= dx (/ (cdr (assoc 44 psn)) scale)); if height of limits = width of layout
		(strcat LayH "×" LayW)
		(strcat LayW "×" LayH)
	  )
    )
  )
)

;;; By Jimmy Bergmark http://jtbworld.com/autocad-pagesetup-lsp
;;; Set a named page setup as current on current layout by avoiding command usage
;;; (SetCurrentPageSetup <AcadDocument> <PageSetupName>)
;;; (SetCurrentPageSetup (vla-get-activedocument (vlax-get-acad-object)) "Setup2")
(defun SetCurrentPageSetup (doc pcname / layout PlotConfig)
  (setq	doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq layout (vla-get-activelayout doc))
  (setq PlotConfig (vl-catch-all-apply
		     'vla-item
		     (list
		       (vla-get-PlotConfigurations
			 doc
		       )
		       pcname
		     )
		   )
  )
  (if (not (vl-catch-all-error-p PlotConfig))
    (vla-copyfrom layout PlotConfig)
  )
)

Saves a lot of time especially with outside drawings.

Link to comment
Share on other sites

How do you (is it possible to) make a Page Setup "Active/Current" once it is created with lisp?

 

The little code snippet I posted works great but requires me to re-enter the PLOT command then select the new Page Setup from the drop down list to make it active.

 

I work with some people that I wouldn't trust with a piece of string so I cannot have them running interactive routines.

I can manage just fine, I'm trying to help some other cad users all get on the same page.

 

ps:I love Lee's Steal routine and have used it many times

Link to comment
Share on other sites

2 hours ago, ILoveMadoka said:

I work with some people that I wouldn't trust with a piece of string so I cannot have them running interactive routines.

I can manage just fine, I'm trying to help some other cad users all get on the same page.

 

Just wondering what the end result you want to achieve, for example consistent plotting style or something like that, and my second question is how many people do you work with? I know my team is quite small but instead of having to trust them to load and run a LISP, how long would it take to go around each user,  load and run the LISP yourself, create page setup , rename it and save it as required manually.. that way you know all the team you can't trust have done what is needed.. and is a one off task

Link to comment
Share on other sites

My $0.05 dont use page setups rather plot from a lisp with all settings correct, choose from a menu what device and size. Works every time. Like Steven P had 8 in my area plus around 6 others.

 

image.png.e6eacc409c842d7d51d6e4500c27716a.png

Link to comment
Share on other sites

8 hours ago, ILoveMadoka said:

I work with some people that I wouldn't trust with a piece of string so I cannot have them running interactive routines.

I can manage just fine, I'm trying to help some other cad users all get on the same page.

I know how you feel, none of my users has ever needed to know how to load a lisp. They know "Quick Plot current layout" & "Quick Plot to PDF into drawing folder" do what they expect them to do when they click on them. They know if they want to Publish a group of selected tabs the Page Setups are already set for each of them. You cannot Publish without Page Setups, but there's no need for my users to know how to create or assign them, more job security for me! 

Link to comment
Share on other sites

Quote

Just wondering what the end result you want to achieve, for example consistent plotting style or something like that,

 

Our "newer" drawings all have a PDF drawing setup which does more than simply printing to PDF.

All my users have gotten used to using that and they know to select if from the list when they plot if it not set already.

If a legacy drawing does not have that setup they get that "deer in the headlights" thing and we get inconsistent output.

 

Restating: Using ronjonp's code I have a workable solution.

 

The next step I want to add to that code is copying that page setup to all the layouts.

(It saves a step during Publish if all the tabs have a pre-assigned page setup.)

I have the code to copy the page setup across layouts but it needs the correct page setup to be selected/set/assigned.

( Still don't know how to do that via lisp.)

 

I suppose I can just cycle through all the tabs but that is a bit convoluted.

BigAl may be onto something if I can't do the thing I am attempting to do.

 

I also like learning what is possible via lisp too..

 

Bottom line, I do not know how to set that newly created page setup active other than manually selecting it in the Plot setup dialog.

image.png.5bd8ff624b61a703ba1e87c3262f16bd.png

If I can do that I'm done with what I am trying to do.

I appreciate all the alternative options to consider, they are worth considering...and I may have no choice but to go one of those routes..

I just wanted to follow through on my original intent if possible.

Link to comment
Share on other sites

I am almost there...

The following works except for one thing.

On the current tab when the routine runs, It does not leave Extents or Fit selected even though they are set earlier in the code.

All the other tabs are correct (as far as what I'm after.)

 

Is there something negating these two "settings" on the current tab?

 


;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/import-page-setup-and-make-it-current-for-the-current-layout-or/m-p/6450956#M343122
;;;hmsilva 07-20-2016

; 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 all layouts 

(defun c:test1 nil
(command "-PLOT" "y" " " "Adobe PDF" "Tabloid" "Inches" "Landscape" "No" "Extents" "Fit" "Center" "Yes" "CG_Lineweight.ctb" "No" "No" "Yes" "No" "N" "Yes" "N")
(vla-add (vla-get-PlotConfigurations (vla-get-ActiveDocument (vlax-get-acad-object)))"PDF") (princ)
   (SetNamePageSetupAllLayouts "PDF" T)
   (princ)
)

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

 

 

Thank you all so very much!

 

Thanks Tombu,

that code did not work for me as it stood but it allowed me to get to this place...

 

Edited by ILoveMadoka
Link to comment
Share on other sites

Adding this before the closing paren fixed my issue but it is novice duct tape fix..

 

(command "-PAGESETUP" "Adobe PDF" "Tabloid" "Inches" "Landscape" "No" "Extents" "Fit" "Center" "Yes" "Lineweight.ctb" "Yes" "No" "No" "No")

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...