Jump to content

Print only one layout


Kate_L

Recommended Posts

Hi all! I'm new to LISP--just started teaching myself yesterday--so I might have missed something obvious, but...

 

I'm trying to write a routine that prints a PDF of a drawing to the same directory as the drawing itself, and that only prints the current layout sheet. The first half of that I have, thanks to the code examples posted by BIGAL and woodman78 here: http://www.cadtutor.net/forum/showthread.php?69132-Printing-LISP-Help...

 

The second half--getting it to only print the current layout--is where I'm having trouble. Plotting every layout from the drawing is useful in some cases, but generally I just want the one I have selected at the time.

 

This is what I'm using:

 

(defun c:pdf ()

 (setvar "cmddia" 0)
 (setvar "filedia" 0)

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (vlax-for lay (vla-get-Layouts doc)
   (setq plottabs (cons (vla-get-name lay) plottabs))
   )
 
 (setq dwgname (getvar "dwgname"))
 (setq len (strlen dwgname))
 (setq dwgname (substr dwgname 1 (- len 4)))

 (setq plottablist (acad_strlsort plotabs))
 (setq len (length plottablist))
 
 (setq x 0)
 (repeat len
   (setq name (nth x plottablist))
   (princ name)
   
   (setq pdfname (strcat (getvar "dwgprefix") dwgname "-" name))
   
   (if (/= name "Model")
     (progn
(setvar "ctab" name)
(command "-plot"
	 "yes"
	 ""
	 "dwg to PDF"
	 "ANSI full bleed B (11.00 x 17.00 Inches)"
	 "inches"
	 "landscape"
	 "no"
	 "extents"
	 "fit"
	 "center"
	 "yes"
	 "monochrome.ctb"
	 "yes"
	 "no"
	 "no"
	 "no"
	 pdfName
	 "n"
	 "y"
	 )
)
     )

   (setq x (+ x 1))
   )

 (setvar "cmddia" 1)
 (setvar "filedia" 1)

 (setq DWGNAME nil
LEN nil
NAME nil
PLOTTABLIST nil)

 (princ)
 )

 

I've narrowed the issue down to the section here:

  (vlax-for lay (vla-get-Layouts doc)
   (setq plottabs (cons (vla-get-name lay) plottabs))
   )

 

What would I use instead of vlax-for to get the name of just the current layout?

 

Thanks :D

Link to comment
Share on other sites

Hi Kate,

 

Welcome to CADTutor.

 

Please try the following code:

(defun c:pdf ( / *error* cm fd )

    (defun *error* ( msg )
        (if (= 'int (type cm))
            (setvar 'cmdecho cm)
        )
        (if (= 'int (type fd))
            (setvar 'filedia fd)
        )
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
    
    (if (= 1 (getvar 'cvport))
        (progn
            (setq fd (getvar 'filedia)
                  cm (getvar 'cmdecho)
            )
            (setvar 'filedia 0)
            (setvar 'cmdecho 0)
            (command
                "_.-plot"
                "_Y" ;; Detailed plot configuration? [Yes/No]:
                ""   ;; Enter a layout name <Current-Layout>:
                "DWG To PDF.pc3" ;; Enter an output device name:
                "ANSI full bleed B (11.00 x 17.00 Inches)" ;; Enter paper size:
                "_I" ;; Enter paper units [Inches/Millimeters]:
                "_L" ;; Enter drawing orientation [Portrait/Landscape]:
                "_N" ;; Plot upside down? [Yes/No]:
                "_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
                "_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
                "_C" ;; Enter plot offset (x,y) or [Center]:
                "_Y" ;; Plot with plot styles? [Yes/No]:
                "monochrome.ctb" ;; Enter plot style table name (enter . for none):
                "_Y" ;; Plot with lineweights? [Yes/No]:
                "no" ;; Scale lineweights with plot scale? [Yes/No]:
                "no" ;; Plot paper space first? [Yes/No]:
                "no" ;; Hide paperspace objects? [Yes/No]:
                (strcat  ;; Enter file name:
                    (getvar 'dwgprefix)
                    (cadr (fnsplitl (getvar 'dwgname))) "-" (getvar 'ctab) ".pdf"
                )
                "_N" ;; Save changes to page setup [Yes/No]:
                "_Y" ;; Proceed with plot [Yes/No]:
            )
            (setvar 'cmdecho cm)
            (setvar 'filedia fd)
        )
        (princ "\nCommand not available in Modelspace.")
    )
    (princ)
)
 

I have included the prompts for the -PLOT command so that it is clear for others to alter if required.

 

I have also included an error handler to reset the System Variables should something go wrong.

(I have written a short tutorial on this topic here).

 

If you have any questions about the code, just ask.

 

Lee

Edited by Lee Mac
Link to comment
Share on other sites

Maybe a thought "you get a tap on the shoulder can I have page 11 please" your in the middle of doing something.

 

Ok save current layout name, read all layouts into a list, pop list into dialouge pick the one you want, jump to that one plot it and then return back ! Keep on working

Link to comment
Share on other sites

Hello Mr. Lee!

 

I have tested this Lisp and found that it works great.

 

It has been shown that the paper size does not change automatically.

 

I have several layouts with different paper sizes that are set in the preferences.

 

Following working methods:

 

ALL entered individually on the command line:

I plotte a layout with A3 paper,

 

-plot, etc. ... - everything works perfectly.

 

so now I switch to a different layout. This time with a paper size A4.

Re-enter everything manually on the command line.

 

-plot; .... etc. .. everything works perfekt.Das paper size is automatically detected and converted to A4.

 

When your Lisp Mr. Lee the paper size is not changed.

When I first plotte a layout with the A3 and then into another layout with a paper Forms A4 and their change my command again ausführe then remains the paper size to A3.

 

What could be the problem here?

 

Greetings

 

Martin

Link to comment
Share on other sites

The default option for the Paper Size prompt is not the paper size that is assigned to the Layout, but is the last used paper size.

 

The following should use the paper size that is assigned to the layout:

 

(defun c:pdf ( / *error* cm fd )

   (defun *error* ( msg )
       (if (= 'int (type cm))
           (setvar 'cmdecho cm)
       )
       (if (= 'int (type fd))
           (setvar 'filedia fd)
       )
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )
   
   (if (= 1 (getvar 'cvport))
       (progn
           (setq fd (getvar 'filedia)
                 cm (getvar 'cmdecho)
           )
           (setvar 'filedia 0)
           (setvar 'cmdecho 0)
           (command
               "_.-plot"
               "_Y" ;; Detailed plot configuration? [Yes/No]:
               ""   ;; Enter a layout name <Current-Layout>:
               "dwg to PDF" ;; Enter an output device name:
               (vla-get-canonicalmedianame (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))) ;; Enter paper size:
               "_I" ;; Enter paper units [inches/Millimeters]:
               "_L" ;; Enter drawing orientation [Portrait/Landscape]:
               "_N" ;; Plot upside down? [Yes/No]:
               "_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
               "_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
               "_C" ;; Enter plot offset (x,y) or [Center]:
               "_Y" ;; Plot with plot styles? [Yes/No]:
               "monochrome.ctb" ;; Enter plot style table name (enter . for none):
               "_Y" ;; Plot with lineweights? [Yes/No]:
               "_N" ;; Scale lineweights with plot scale? [Yes/No]:
               "_N" ;; Plot paper space first? [Yes/No]:
               "_N" ;; Hide paperspace objects? [Yes/No]:
               (strcat  ;; Enter file name:
                   (getvar 'dwgprefix)
                   (cadr (fnsplitl (getvar 'dwgname))) "-" (getvar 'ctab) ".pdf"
               )
               "_N" ;; Save changes to page setup [Yes/No]:
               "_Y" ;; Proceed with plot [Yes/No]:
           )
           (setvar 'cmdecho cm)
           (setvar 'filedia fd)
       )
       (princ "\nCommand not available in Modelspace.")
   )
   (princ)
)
(vl-load-com) (princ)
 
Edited by Lee Mac
Link to comment
Share on other sites

Sorry Lee great code as usual but come to think of it why not just save in your DWT a plot page A4 particular printer. Even save a page setting in the current dwg then its then available every layout.

 

Plot, pick top left pull down, pick "a4 laser" hit ok sheet comes out perfect.

Link to comment
Share on other sites

Hello Mr. Lee!

 

Thank you for your quick help. Unfortunately, I have your command

"(Vla-get-canonicalmedianame (vla-get-active layout (vla-get-active document (vlax-get-acad-object))));; Enter papersize"

only "A4" back.

The program does not accept!?

When I go through the program run separately then he brings in

Paper size or specify : [?]

A4 not found.

 

Here is the sequence in the text window when I run the program normally views:

 

Command: PDF

Unknown command "I". Press F1 for help.

Unknown command "L". Press F1 for help.

Unknown command "N". Press F1 for help.

Unknown command "E". Press F1 for help.

Unknown command "F". Press F1 for help.

Unknown command "C". Press F1 for help.

Unknown command "Y". Press F1 for help.

Unknown command "CTB". Press F1 for help.

Unknown command "Y". Press F1 for help.

Unknown command "N". Press F1 for help.

Unknown command "N". Press F1 for help.

Unknown command "N". Press F1 for help.

Unknown command "PDF". Press F1 for help.

Unknown command "N". Press F1 for help.

Unknown command "Y". Press F1 for help.

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...