Jump to content
Kate_L

Print only one layout

Recommended Posts

Kate_L

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

Share this post


Link to post
Share on other sites
Lee Mac

Hi Kate,

 

Welcome to CADTutor.

 

Please try the following code:

([color=BLUE]defun[/color] c:pdf ( [color=BLUE]/[/color] *error* cm fd )

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

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

Share this post


Link to post
Share on other sites
Kate_L

Thanks! That worked perfectly and was way easier than what I was trying to do!

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome Kate :)

Share this post


Link to post
Share on other sites
BIGAL

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

Share this post


Link to post
Share on other sites
martinle

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

Share this post


Link to post
Share on other sites
Lee Mac

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:

 

([color=BLUE]defun[/color] c:pdf ( [color=BLUE]/[/color] *error* cm fd )

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

Share this post


Link to post
Share on other sites
BIGAL

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.

Share this post


Link to post
Share on other sites
martinle

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×