+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Forum Newbie
    Using
    AutoCAD 2013
    Join Date
    Jan 2013
    Location
    Austin, TX
    Posts
    2

    Default Print only one layout

    Registered forum members do not see this ad.

    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/showth...g-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:

    Code:
    (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:
    Code:
      (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

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Hi Kate,

    Welcome to CADTutor.

    Please try the following code:
    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" ;; 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]:
                    "_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)
    )
    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
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Forum Newbie
    Using
    AutoCAD 2013
    Join Date
    Jan 2013
    Location
    Austin, TX
    Posts
    2

    Default

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

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    You're welcome Kate
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,747

    Default

    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
    A man who never made mistakes never made anything

  6. #6
    Senior Member martinle's Avatar
    Computer Details
    martinle's Computer Details
    Operating System:
    windows 10
    Using
    AutoCAD 2018
    Join Date
    Mar 2010
    Location
    Austria
    Posts
    157

    Default

    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
    My friend has the Google Translator

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    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:

    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" ;; 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)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,747

    Default

    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.
    A man who never made mistakes never made anything

  9. #9
    Senior Member martinle's Avatar
    Computer Details
    martinle's Computer Details
    Operating System:
    windows 10
    Using
    AutoCAD 2018
    Join Date
    Mar 2010
    Location
    Austria
    Posts
    157

    Default

    Registered forum members do not see this ad.

    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 <ISO full bleed A4 (210.00 x 297.00 mm)>: [?]
    A4 <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.
    My friend has the Google Translator

Similar Threads

  1. How to Set drawing To a Layout and Print it
    By atulkumarengineer in forum AutoCAD Drawing Management & Output
    Replies: 8
    Last Post: 30th Dec 2014, 02:35 pm
  2. AC2012 layout print & Designjet T2300. D size incorrect print rotation.
    By CalypsoArt in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 14th Jun 2012, 03:34 am
  3. Layout Shifting on me when I print?
    By tennis4you in forum AutoCAD General
    Replies: 5
    Last Post: 16th Jun 2011, 04:15 pm
  4. Print to PDF without the layout name?
    By cadman6735 in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 30th Dec 2010, 04:19 pm
  5. How to print from layout autocad LT
    By Sang in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 28th Jun 2010, 10:48 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts