+ Reply to Thread
Results 1 to 2 of 2

Thread: Script Plotting

  1. #1
    Forum Newbie
    Using
    AutoCAD 2017
    Join Date
    Jun 2017
    Posts
    1

    Default Script Plotting

    Registered forum members do not see this ad.

    I am looking for a way to automate my drawing plotting.

    Every drawing I make has the same 4 layouts, with the following names: CP1, CU1, 3L1, 3L2. I always need to plot three documents with the following conventions.

    [Drawing Name]-CP.pdf This contains just the page CP1.
    [Drawing Name]-CU.pdf This contains just the page CU1.
    [Drawing Name]-3L.pdf This contains page 3L1 and 3L2.

    The plots for these drawings should always be saved one level higher in my file path. I.e. the path for the AutoCad file is /.../Engineering Drawings/AutoCAD/ and the pdfs should be saved to /.../Engineering Drawings/.

    Can anyone suggest the right path to head down to automate this process?

    Cheers,
    Dan

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

    Default

    Registered forum members do not see this ad.

    Here is a start this is the latest version will do what you want it plots a range so you can do layout 1 or 2-3 etc. You need to download Ghostscript seperately as it combines the pdf's into 1.

    Code:
    ;Plots layouts by range
    ; By Alan H Feb 2014
    (defun AH:pltlays ( / val1 val2 plotnames dwgname lendwg pdfname lay numlay numend dwgpre)
    (SETVAR "PDMODE" 0)
    (setvar "plottransparencyoverride" 2)
    (setvar "fillmode" 1)
    (setvar "textfill" 1)
    (setq plotnames '())
    ; check that pdf directory exists
    (setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
    (if (= (vl-file-directory-p dwgpre) nil)
    (vl-mkdir dwgpre)
    )
    (SETQ LAYOUTS (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
    (SETQ COUNT (- (VLA-GET-COUNT LAYOUTS) 1))
    (if (not AH:getval2) (load "getvals3"))
    (ah:getval2 "Enter start tab number" 6 4 "1" "Enter end tab number" 6 4 (RTOS COUNT 2 0))
    (setq numlay (ATOI val1))
    (setq numend (ATOI val2))
    (setq len (+ (- numend numlay) 1))
    (setq dwgname (GETVAR "dwgname"))
    (setq lendwg (strlen dwgname))
    (setq dwgname (substr dwgname 1 (- lendwg 4)))
    (repeat len
    (vlax-for lay LAYOUTS
    (if (= numlay (vla-get-taborder lay))
      (setvar "ctab" (vla-get-name lay))
    ) ; if
    (setq pdfname (strcat dwgpre "\\" dwgname "-" (getvar "ctab") ".pdf" ))
    ) ; for
    (setvar "textfill" 1)
    (setvar "fillmode" 1)
    (setvar "PLOTTRANSPARENCYOVERRIDE" 2)
        (COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
            "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
            "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y"
        )
     
    (setq numlay (+ numlay 1))
    (setq plotnames (cons pdfname plotnames))
    ) ; end repeat
    (setq trgfile (strcat (getvar "dwgprefix") "pdf\\" dwgname "-D" val1 "-D" val2 ".pdf")) 
    (setq plotnames (reverse plotnames))
    (IF (= (length plotnames) 1)
    (princ)
    (progn
    (if (not combinepdf)(load "mergepdfs"))
    (combinepdf gsExe plotnames trgFile )
    )
    )
    ) ; defun
    (AH:pltlays)
     
    (princ)
    Code:
    ;MergePdfs
    ;Merges multiple pdf (or eps) files into one
    ;Requires the installatoion of Ghostscript 
    ; make a batch file ?
    ;gs -sDEVICE=pdfwrite \
    ;    -dNOPAUSE -dBATCH -dSAFER \
    ;    -sOutputFile=combined.pdf \
    ;    first.pdf \
    ;    second.pdf \
    ;    third.pdf [...]
    ;Ghostscript (http://www.ghostscript.com/) can be used to combine PDFs.
    ; Something like this should work: by Roy_043
    (defun KGA_String_Join (strLst delim)
    (if strLst
    (apply
    'strcat
    (cons
    (car strLst)
    (mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
    )
    )
    ""
    )
    )
    ; (CombinePdf 
      (setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe")
    ; (setq srcFilelst  '("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf"))
    ; (setq trgfile "C:\\Acadtemp\\Total.pdf")
    ; )
    ; Note: Existing trgFile will be overwritten.
    (defun CombinePdf (gsExe srcFileLst trgFile)
    (startapp 
    (strcat
    gsExe " "
    "-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET  "
    "-sOutputFile=\"" trgFile "\" "
    "\"" (KGA_String_Join srcFileLst "\" \"") "\""
    )
    )
    )
    and this
    Code:
    ; Input  Dialog box with variable title
    ; multiple lines of dcl input supported
    ; add extra lines if required by copying code defun
    ; By Alan H 2015
    (vl-load-com)
    ; 1 line dcl
    ; sample code (ah:getval1 "Line 1" 5 4)
    (defun AH:getval1 (title width limit def1 / fo fname)
    ; you can hard code a directory if you like for dcl file
    (setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
    (write-line "ddgetval : dialog {" fo)
    (write-line " : row {" fo)
    (write-line ": edit_box {" fo)
    (write-line (strcat "    key = "  (chr 34) "key1" (chr 34) ";") fo)
    (write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
    ; these can be replaced with shorter value etc
    (write-line (strcat "     edit_width = " (rtos width 2 0) ";" ) fo)
    (write-line (strcat "     edit_limit = " (rtos limit 2 0) ";" ) fo)
    (write-line "   is_enabled = true;" fo)
    (write-line "    }" fo)
    (write-line "  }" fo)
    (write-line "ok_only;}" fo)
    (close fo)
    (setq dcl_id (load_dialog  fname))
    ; pt is a list 2 numbs -1 -1 centre ('(20 20))
    ;(not (new_dialog "test" dch "" *screenpoint*)) 
    (if (not (new_dialog "ddgetval" dcl_id))
    (exit))
    (set_tile "key1" (setq val1 def1))
    (action_tile "key1" "(setq val1 $value)")
    (mode_tile "key1" 3)
    (start_dialog)
    (done_dialog)
    (unload_dialog dcl_id)
    ; returns the value of val1 as a string
    (vl-file-delete fname)
    ) ; defungetval1
    ; 2 line dcl
    ; sample code (ah:getval2 "Line 1" 5 4 "Line2" 8 7)
    (defun AH:getval2 (title1 width1 limit1 def1 title2 width2 limit2 def2 / fo fname)
    (setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
    (write-line "ddgetval2 : dialog {" fo)
    (write-line " : column {" fo)
    (write-line ": edit_box {" fo)
    (write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
    (write-line  (strcat " label = "  (chr 34) title1 (chr 34) ";" ) fo)
    (write-line (strcat "     edit_width = " (rtos width1 2 0) ";" ) fo)
    (write-line (strcat "     edit_limit = " (rtos limit1 2 0) ";" ) fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (write-line "spacer_1 ;" fo)
    (write-line ": edit_box {" fo)
    (write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
    (write-line (strcat " label = "  (chr 34) title2 (chr 34) ";"  ) fo)
    (write-line (strcat "     edit_width = " (rtos width2 2 0) ";" ) fo)
    (write-line (strcat "     edit_limit = " (rtos limit2 2 0) ";" ) fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (write-line "    }" fo)
    (write-line "spacer_1 ;" fo)
    (write-line "ok_only;}" fo)
    (close fo)
    ; code part
    (setq dcl_id (load_dialog  fname))
    (if (not (new_dialog "ddgetval2" dcl_id))
    (exit))
    (mode_tile "key1" 3)
    (set_tile "key1" (setq val1 def1))
    (action_tile "key1" "(setq val1 $value)")
    (mode_tile "key2" 3)
    (set_tile "key2" (setq val2 def2))
    (action_tile "key2" "(setq val2 $value)")
    (start_dialog)
    (done_dialog)
    (unload_dialog dcl_id)
    ; returns the value of val1 and val2 as strings
    (vl-file-delete fname)
    ) ; defungetval2
    ; 3 line dcl
    ; sample code (ah:getval3 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123")
    (defun AH:getval3 (title1 width1 limit1 def1 title2 width2 limit2 def2 title3 width3 limit3 def3 / fo fname)
    (setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
    (write-line "ddgetval3 : dialog {" fo)
    (write-line " : column {" fo)
    (write-line ": edit_box {" fo)
    (write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
    (write-line  (strcat " label = "  (chr 34) title1 (chr 34) ";" ) fo)
    (write-line (strcat "     edit_width = " (rtos width1 2 0) ";" ) fo)
    (write-line (strcat "     edit_limit = " (rtos limit1 2 0) ";" ) fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (write-line "spacer_1 ;" fo)
    (write-line ": edit_box {" fo)
    (write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
    (write-line (strcat " label = "  (chr 34) title2 (chr 34) ";"  ) fo)
    (write-line (strcat "     edit_width = " (rtos width2 2 0) ";" ) fo)
    (write-line (strcat "     edit_limit = " (rtos limit2 2 0) ";" ) fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (write-line "spacer_1 ;" fo)
    (write-line ": edit_box {" fo)
    (write-line (strcat "    key = " (chr 34) "key3" (chr 34) ";") fo)
    (write-line (strcat " label = "  (chr 34) title3 (chr 34) ";"  ) fo)
    (write-line (strcat "     edit_width = " (rtos width3 2 0) ";" ) fo)
    (write-line (strcat "     edit_limit = " (rtos limit3 2 0) ";" ) fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (write-line "    }" fo)
    (write-line "spacer_1 ;" fo)
    (write-line "ok_only;}" fo)
    (close fo)
    ; code part
    (setq dcl_id (load_dialog  fname))
    (if (not (new_dialog "ddgetval3" dcl_id))
    (exit))
    (mode_tile "key1" 3)
    (set_tile "key1" (setq val1 def1))
    (action_tile "key1" "(setq val1 $value)")
    (mode_tile "key2" 3)
    (set_tile "key2" (setq val2 def2))
    (action_tile "key2" "(setq val2 $value)")
    (mode_tile "key3" 3)
    (set_tile "key3" (setq val3 def3))
    (action_tile "key3" "(setq val3 $value)")
    (start_dialog)
    (done_dialog)
    (unload_dialog dcl_id)
    ; returns the value of val1 val2 and val3 as strings
    (vl-file-delete fname)
    ) ; defungetval3
    Last edited by BIGAL; 9th Jun 2017 at 05:22 am.
    A man who never made mistakes never made anything

Similar Threads

  1. Autocad PDF plotting script
    By Stevery in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 5
    Last Post: 7th Mar 2016, 12:41 am
  2. Plotting to a file using Script
    By daveyboyd in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 15th Jan 2010, 02:21 pm
  3. Plotting Script Help
    By r_osu in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 26th Feb 2008, 07:01 am
  4. Sub script and Super script Text
    By edwin in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 1st Aug 2007, 08:07 pm
  5. Plotting script no longer works
    By Skeeps in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 9th Feb 2005, 01:17 pm

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