Jump to content
nnutting

Printing LISP Help...

Recommended Posts

nnutting

I need help with writing a few routines...

Not sure really where to get started but below is what I need:

 

Instead of going through the typical plot routine (type plot, choose plotter, choose paper size, choose pen settings, choose scale, and finally print)

I would like to be able to just type a couple letters and get the same result...thus...saving time.

 

If I'm in paper space and the title block is placed at 0,0...I would like to be able to type the following and get the results listed:

 

30x42 plot sheet

PDF11: Creates 11x17 PDF with correct pen settings and saves the file into a predetermined folder on your desktop called PDF

 

PDF30: Creates full size PDF with correct pen settings and saves the file into a predetermined folder on your desktop called PDF

 

PDF8: Creates 8 1/2x11 PDF with correct pen settings and saves the file into a predetermined folder on your desktop called PDF

 

24x36 plot sheet

PDF2411: Creates 11x17 PDF with correct pen settings and saves the file into a predetermined folder on your desktop called PDF

 

PDF24: Creates full size PDF with correct pen settings and saves the file into a predetermined folder on your desktop called PDF

 

PDF248: Creates 8 1/2x11 PDF with correct pen settings and saves the file into a predetermined folder on your desktop called PDF

 

 

I know I'm asking a lot...any help would be greatly appreciated.

 

Thanks in advance! :D

Share this post


Link to post
Share on other sites
BIGAL

Here is a code example.

 

 

; plotpdf2 ver 2 with filename and directory as output oct 2011
(PROMPT ".....PRINTING DRAWING TO pdf's....")
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(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"  "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 x (+ x 1))
)
(setvar "cmddia" 1)
(setvar "filedia" 1)
(setq DWGNAME nil
     LEN nil
     NAME nil
     PLOTTABLIST nil) 
(princ)

Share this post


Link to post
Share on other sites
woodman78

Hi Bigal, where does this routine store the pdf's. I can't find them.

Share this post


Link to post
Share on other sites
Tharwat
where does this routine store the pdf's. I can't find them.

 

Check this out .... :)

(getvar "dwgprefix") 

Share this post


Link to post
Share on other sites
woodman78

Tharwat, are you suggesting they are stored in the same folder as the drawing? But I created a new folder saved the drawing there and ran it but no joy. This is the modified lisp I use.

 

; plotpdf2 ver 2 with filename and directory as output oct 2011
; from Bigal
(defun c:A3_dwg_pdf ()  
(if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt")
   (progn
     (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A3-dwg-pdf")
     (while (wcmatch (getvar "cmdnames") "*PSETUPIN*")
       (command "_yes")
     ) ;_ while
     T
   ) ;_ progn
 ) ;_ if
(PROMPT ".....PRINTING DRAWING TO pdf's....")
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(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" "n" "" "A3-dwg-pdf" "" "n" "y" "y")
   )
 )
 (setq x (+ x 1))
)
(setvar "cmddia" 1)
(setvar "filedia" 1)
(setq DWGNAME nil
     LEN nil
     NAME nil
     PLOTTABLIST nil) 
(princ)
)

Share this post


Link to post
Share on other sites
Tharwat
Tharwat, are you suggesting they are stored in the same folder as the drawing ?

 

I am not suggesting , but this what the system variable does . :)

Share this post


Link to post
Share on other sites
woodman78

Tharwat, I had removed the pdfname variable from the plot command.

 

Thanks.

Share this post


Link to post
Share on other sites
woodman78

I have cutepdf printer installed and am using a lisp to print a pdf copy of a drawing. This has been running for a few years now without problems. I took the code that Bigal provided above and modified it to create a batch plot for pdf's. The problem I had was that the paper size in the "dwg to pdf" was not allowing our sheet to fit on the page even though it using the cute pdf. I modified the "dwg to pdf" to included our paper the same as the cute printer and now it prints fine but it is like it repeats the plot about 5 or 6 times for each layout and it goes into a loop and I have to esc out of it.

 

Could someone have a look and see where I am going wrong? Thanks.

 

; plotpdf2 ver 2 with filename and directory as output oct 2011
; from Bigal
(defun c:A3_dwg_pdf ()  
 (if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt")
   (progn
     (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A1")
     (while (wcmatch (getvar "cmdnames") "*PSETUPIN*")
       (command "_yes")
     ) ;_ while
     T
   ) ;_ progn
 ) ;_ if

(PROMPT ".....PRINTING DRAWING TO pdf's....")
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(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" "y" "" "dwg to pdf" "A3" "m" "Landscape" "n" "Layout" "1=2" "0,0" "n" "." "y" "n" "n" "n" pdfname "n" "y")
   )
 )
 (setq x (+ x 1))
)
(setvar "cmddia" 1)
(setvar "filedia" 1)
(setq DWGNAME nil
     LEN nil
     NAME nil
     PLOTTABLIST nil) 
(princ)
)

 

Added the file:

dwg to pdf.zip

Share this post


Link to post
Share on other sites
BIGAL

Im no expert I would look at this bit of code maybe put a dumy line in to test its only place I can see that loops outside of the older code which works ok

 

(setq x 1)
(while (wcmatch (getvar "cmdnames") "*PSETUPIN*")
       (command "_yes")
(princ x)(setq x (+ x 1))
     ) ;_ while

Share this post


Link to post
Share on other sites
pBe

With this (setvar 'Expert 5) you can get rid of this

 

(while (wcmatch (getvar "cmdnames") "*PSETUPIN*")
       (command "_yes")
     )

 

and use instead:

 

(if (setq dwtfile (findfile "T:/Drawing Tools/Templates/CCC2009.dwt"))
   (progn
     (command "_.psetupin" dwtfile "A1")
     .....

Share this post


Link to post
Share on other sites
woodman78

Ok, here is where I am at the moment. I have had to abandon using the "dwg to pdf" and it is for asthetic reasons more than anything. The lisp worked alright but see the image and the poor quality of the pdf using the "dwg to pdf".

rps20120518_094748_902.jpg

To be honest it wouldn't cut it around our place. We have been using "Cutepdf" for many years now with very good results. So I am back to this for batch plotting pdf's.

 

 

;Based on PageSetups from Alan J. Thompson
(defun c:A3_all_pdf ()
(PlotReactorOFF)
 (if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt")
   (progn
     (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A3")
     (while (wcmatch (getvar "cmdnames") "*PSETUPIN*")
       (command "_yes")
(princ x)(setq x (+ x 1))
     ) ;_ while
     T
   ) ;_ progn
 ) ;_ if

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(setq plottablist (acad_strlsort plotabs))
(setq len (length plottablist))
(setq x 0)
(repeat len
 (setq name (nth x plottablist))
 (princ name)
 (if (/= name "Model")
  (progn
   (setvar "ctab" name)
(command "-plot" "n" "" "A3-pdf" "" "n" "y" "y")
   (command "_-purge" "a" "*" "N")
   (setq CCC_Sheet "A3")
   (command "updatefield" "all" "")
   (command "regenall")
   (command "_zoom" "e")
   (initdia)
   (command "._plot")
  ) ;<- IF
 )  ;<- PROGN
 ;(princ)
 (setq x (1+ x))
)
   (PlotReactorON)
)    ;<- DEFUN

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun PlotReactorON nil
 (vl-load-com)
 ;; © Lee Mac 2010

 (  (lambda ( data foo / react )
      (if (setq react
            (vl-some
              (function
                (lambda ( reactor )
                  (if (eq data (vlr-data reactor)) reactor)
                )
              )
              (cdar
                (vlr-reactors :vlr-command-reactor)
              )
            )
          )
        (if (not (vlr-added-p react))
          (vlr-add react)
        )
        (setq react
          (vlr-command-reactor data
            (list
              (cons :vlr-commandwillstart foo)
            )
          )
        )
      )
      (if (vlr-added-p react)
        (princ "\n** Reactor Activated **")
        (princ "\n** Reactor Failed to Activate **")
      )
      react
    )
   "Plot-Reactor"
   'Plot-Callback
 )

 (princ)
)

(defun PlotReactorOFF nil
 (vl-load-com)
 ;; © Lee Mac 2010

 (  (lambda ( data foo / react )
      (if (setq react
            (vl-some
              (function
                (lambda ( reactor )
                  (if (eq data (vlr-data reactor)) reactor)
                )
              )
              (cdar
                (vlr-reactors :vlr-command-reactor)
              )
            )
          )
        (if (vlr-added-p react)
          (vlr-remove react)
        )
      )
      (if (or (not react) (not (vlr-added-p react)))
        (princ "\n** Reactor Deactivated **")
        (princ "\n** Reactor Failed to Deactivate **")
      )
      react
    )
   "Plot-Reactor"
   'Plot-Callback
 )
 
 (princ)
)

(defun Plot-Callback ( reactor arguments )
 (vl-load-com)

 (if (eq (strcase (car arguments)) "PLOT")
   (LM:Popup "Warning" 64 "Gotcha!!!   Please use the NNRDO Plot tools when plotting standard layouts!!")
 )

 (princ)
)

(defun LM:Popup ( title flags msg / WSHShell result )
 ;; © Lee Mac 2010
 (setq WSHShell (vlax-create-object "WScript.Shell"))
 (setq result   (vlax-invoke WSHShell 'Popup msg 0 title flags))
 (vlax-release-object WSHShell)
 
 result
)

 

The problem I am having with this is that it runs fine and launches the curepdf file save as window. And the autocad plot window reloads. I click "save" on the cutepdf window, which is not a big issue. Then I click plot on the autocad window but it plots the same layout. It can run like that for 5 or 6 times and eventually change the layout.

 

This is the cutepdf save window

plot pdf.jpg

I would appreciate it if anyone had any ideas how to get around this. Thanks.

Share this post


Link to post
Share on other sites
woodman78

I tried to incorporate a pause into the plot command but after the first plot it just stopped.

Share this post


Link to post
Share on other sites
pBe

Use (layoutlist) for layout names

instead of repeat use foreach

(foreach name (layoutlist) '

.....

)

and DO NOT forget to localize plotabs variable.

 

This line:

 
(vlax-for lay (vla-get-Layouts doc)
 [color=blue](setq [b]plotabs[/b] ([b]cons[/b] (vla-get-name lay) [b]plotabs[/b]))[/color]
)

 

If you dont localize the variable the list will continue to "grow" the next time you use the command

 

 (defun c:A3_all_pdf ( / PlotReactorOFF doc lay [b][color=blue]plotabs[/color][/b] plottablist ....)

 

That is why i suggested on your previous post to use (layoutlist) as this will give you a list without "Model" and its already sorted and no need to assign to a variable.

 

HTH

 

Cheers

 

BTW: whats the use of CCC_Sheet variable?

Share this post


Link to post
Share on other sites
woodman78

Thanks pBe, I tried to incorporate your comments and this is what I have but what I have doesn't run. I have been looking and can't quite get my head around what I need to remove or keep.

 

;Based on PageSetups from Alan J. Thompson
(defun c:A3_all_pdf ( / PlotReactorOFF doc lay plotabs plottablist name)
(PlotReactorOFF)
 (if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt")
   (progn
     (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A3")
     (while (wcmatch (getvar "cmdnames") "*PSETUPIN*")
       (command "_yes")
(princ x)(setq x (+ x 1))
     ) ;_ while
     T
   ) ;_ progn
 ) ;_ if

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(setq plottablist (acad_strlsort plotabs))
(setq len (length plottablist))
;(setq x 0)
(foreach name (layoutlist))
 ;(setq name (nth x plottablist))
 (princ name)
 (if (/= name "Model")
  (progn
   (setvar "ctab" name)
(command "-plot" "n" "" "A3-pdf" "" "n" "y" "y")
   (command "_-purge" "a" "*" "N")
   (command "updatefield" "all" "")
   (command "regenall")
   (command "_zoom" "e")
   (initdia)
   (command "._plot")
  ) ;<- IF
 )  ;<- PROGN
 ;(princ)
; (setq x (1+ x))
)
   (PlotReactorON)
)    ;<- DEFUN

 

What have I missed?

 

 

CCC_Sheet was an overhang from an earlier version and can be removed.

Share this post


Link to post
Share on other sites
pBe

Still not sure what your code is all about but the obvious reason is this.....

(foreach name (layoutlist)[b][color=blue]);<----- loose this one[/color][/b]

 

Still.. not sure

 

(defun c:A3_all_pdf ( / PlotReactorOFF tmptfile PlotReactorON)
(PlotReactorOFF)
[color=blue](setvar 'Expert 5)[/color]       
 (if (setq tmptfile (findfile "T:/Drawing Tools/Templates/CCC2009.dwt"))
(progn
     (command  "_.psetupin" tmptfile  "A3")
     (foreach  name  (layoutlist)
           (setvar "ctab" name)
           (command "-plot" "n" "" "A3-pdf" "" "n" "y" "y")
           (command "_-purge" "a" "*" "N")
           (command "updatefield" "all" "")
           (command "regenall")
           (command "_zoom" "e")
           (initdia)
           (command "._plot")
           )
      )                          
     )
(PlotReactorON)
      (princ)
      )

  • Like 1

Share this post


Link to post
Share on other sites
woodman78

I get this error when I run your revised code pBe:

; error: no function definition: PLOTREACTOROFF

 

The code is supposed to plot all layouts to pdf using cutepdf printer. The problem was it was plotting the same layout over and over again.

Share this post


Link to post
Share on other sites
pBe

(PlotReactorOFF) and (PlotReactorON) came from your post Woodman78

Share this post


Link to post
Share on other sites
woodman78

They are LeeMac's subroutines. I just removed them from the variable list and it works fine now. Thanks pBe.

Share this post


Link to post
Share on other sites
pBe

Glad it helps Woodman78. keep on coding ;)

 

Cheers

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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