Jump to content
Steven P

PDF Printable Area LISP

Recommended Posts

Steven P

Hello,

A question about plotting to PDF and paper printable areas that I wonder if anyone can help with.

 

 

I have a LISP routine that plots a PDF to the file where the original drawing is saved. This mostly works great for me.

 

 

Our drawing standards are to use the default standard paper sizes printable area for a paper plot (so an A3 sheet might have 6mm left, 5m right, 18mm top and 17mm bottom margin to the plot), but for a PDF plot to use a modified standard paper size with a 0mm margin all round the printable area (so it plots full size).

 

 

My LISP routine detects the current paper size then uses the modified paper size based on 'IF' commands (If papersize = A4 then use A4_0mm_margin type command). This is good for 3 or 4 paper types - any more and the code gets quite lengthy.

 

 

My question is is there a better way? Is there a routine or command that will temporarily set the paper printable area to have a 0mm margin all round (or any other size I want), then do the plotting, and without changing anything or saving anything?

 

 

Thanks for any help

Share this post


Link to post
Share on other sites
Lee Mac

You could use a cond expression in place of your if statement to reduce the amount of expression nesting.

 

It is difficult to advise without seeing your current code.

Share this post


Link to post
Share on other sites
Steven P

Yup, I get the point of cond, it would make the code a bit shorter.

 

 

If you don't mind and are gentle with me, then I can post the relevant LISP routines (I appreciate I am not the best at this and have taken a lot from forums like this!). Will take me a short while to get rid of the parts that aren't relevant and add some notes what I am hoping each part does

Share this post


Link to post
Share on other sites
Lee Mac
If you don't mind and are gentle with me, then I can post the relevant LISP routines (I appreciate I am not the best at this and have taken a lot from forums like this!).

 

Don't worry, this is not that kind of forum ;)

 

Will take me a short while to get rid of the parts that aren't relevant and add some notes what I am hoping each part does

 

No problem.

Share this post


Link to post
Share on other sites
Steven P

Hi sorry it took me a while, the LSP file I use had other things in it that aren't relevant, it took me a while to remove them and make sure I didn't take anything important out.

Below is the LIPS routines that I use to make a PDF plot:

 

 

Oh, just paranoid that you will all be rolling on the floor laughing at basic mistakes that all

 

 

 

 

**EDITED TO PUT CODE IN CODE TAGS - SEE BELOW **

Edited by Steven P
Put code in Code Tags (I hope!)

Share this post


Link to post
Share on other sites
Steven P

I think the smiling faces should be : p (with no spaces)

Share this post


Link to post
Share on other sites
Steven P

Many apologies - I hadn't read that

Share this post


Link to post
Share on other sites
marko_ribar

Now that you read it, you could edit your post...

Share this post


Link to post
Share on other sites
Steven P

My code so far:

 

 

(defun c:currentpapersize()

;;This part looks at the page setup and returns simple paper size

;;e.g A0P (A0 size, portrait orientation)

;;

;;This seperate because it is also used in other LISP routines elsewhere

;;

(setq plotsize (vla-get-canonicalmedianame

(vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (getvar 'ctab))

))

(setq aplotsize "")

(if (= plotsize "User622")(setq aplotsize "A0P"))

(if (= "A0" plotsize)(setq aplotsize "A0L"))

(if (= plotsize "User622")(setq aplotsize "A0L"))

(if (= plotsize "User271")(setq aplotsize "A1P"))

(if (= "A1" plotsize)(setq aplotsize "A1L"))

(if (= plotsize "User1645")(setq aplotsize "A1L"))

(if (= plotsize "User270")(setq aplotsize "A2P"))

(if (> (vl-string-search "A2_(420" plotsize) 1)(setq aplotsize "A2P"))

(if (= "A2" plotsize)(setq aplotsize "A2L"))

(if (= plotsize "User1644")(setq aplotsize "A2L"))

;;hope you get the idea here - this could be a long list to work out each paper

;;size for eat plotter we use

(if (= plotsize "User269")(setq aplotsize "A3P"))

(if (= plotsize "User1292")(setq aplotsize "A3L"))

(if (= plotsize "User618")(setq aplotsize "A4P"))

(if (= plotsize "User1291")(setq aplotsize "A4L"))

(princ)

)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:modelorpaper()

;;This detects whether the view is Model or Paperspace.

;;If Modelspace it will ask if you want to continue with the plot

;;If you don't want to continue then it sets stopfunc to No

;;to cancel the plot later.

;;

(cond

((= (getvar "TILEMODE") 1)

(cond ((=

(LM:Popup "Model space plotting" "Plot this model space display?" (+ 1 256)) 1)

(setq stopfunc "Yes")

)

(T (setq stopfunc "No") )

)

)

(T (setq stopfunc "Yes") )

)

)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:PDFplot()

;;Function to plot to a PDF

;;

;;This first bit works out if the PDF is Model and Paperspace plot

;;It needs tidying up but it works and not really what I am asking

;;about.

(setq orientation "Landscape") ;;there is more to this function to set orientation to Portrait

(Setq PDFPLOTTER "DWG to PDF.pc3") ;;plotter name

(setq directoryname (getvar "dwgprefix"))

(setq filename (vl-filename-base (getvar 'dwgname)))

(setq fullpath (strcat directoryname filename ""))

;;works out if plotting modelspace or aperspace plot

(c:modelorpaper)

;;Condition statement if modelspace plotting - to be tidied up later, ignore this for now

(cond

((= (getvar "TILEMODE") 1)

(command "-plot" "Yes" "Model" PDFPLOTTER "" "" orientation "No" "Display" "Fit" "Center" "No"

"" "Yes" "As Displayed" fullpath "No" "Yes")

)

((> (getvar "CVPORT") 1)

(command "_.pspace")

(c:pdfplotting)

)

(T

(c:pdfplotting)

)

)

(princ))

 

 

;;The function to do the plotting that I am looking at changing about.

;;This is called from PDFPLOT above.

;;This but plots paperspace drawing

(defun c:pdfplotting()

(command "zoom" "all")

;;Change current paper size to expanded (0mm border) for standard paper sizes

(setq papersize "")

(setq aplotsize "")

;;calls function currentpapersize to get the current paper size as e.g.A0P

;;(For A0 Portrait plot)

;;Uses if statements to set the papersize to the equivalent print area with

;;a 0mm border.

;;This is the but I want to tidy up this week.

;;

(c:currentpapersize)

;;Landscape layouts

(if (= aplotsize "A0L")(setq papersize "ISO expand A0 (841.00 x 1189.00 MM)"))

(if (= aplotsize "A1L")(setq papersize "ISO expand A1 (841.00 x 594.00 MM)"))

(if (= aplotsize "A2L")(setq papersize "ISO expand A2 (594.00 x 420.00 MM)"))

(if (= aplotsize "A3L")(setq papersize "ISO expand A3 (420.00 x 297.00 MM)"))

(if (= aplotsize "A4L")(setq papersize "ISO expand A4 (297.00 x 210.00 MM)"))

;;Portrait layouts

(if (= aplotsize "A0P")(setq papersize "ISO expand A0 (841.00 x 1189.00 MM)"))

(if (= aplotsize "A1P")(setq papersize "ISO expand A1 (594.00 x 841.00 MM)"))

(if (= aplotsize "A2P")(setq papersize "ISO expand A2 (420.00 x 594.00 MM)"))

(if (= aplotsize "A3P")(setq papersize "ISO expand A3 (297.00 x 420.00 MM)"))

(if (= aplotsize "A4P")(setq papersize "ISO expand A4 (210.00 x 297.00 MM)"))

;;how do I remove the need to use currentpapersize function and these if statements

;;in a better way

(if (= papersize "")( (setq papersize (vla-get-canonicalmedianame

(vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (getvar 'ctab))

)) ))

(command "-plot" "Yes" "" PDFPLOTTER papersize "" orientation "No" "" "Fit" "Center" "No" ""

"Yes" "Yes" "No" "No" fullpath "No" "Yes")

(princ))

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

×