Jump to content

PDF plott lisp


V4Mp

Recommended Posts

2 hours ago, martinle said:

Hello Steven, Thanks for your help, unfortunately I am only a beginner in Lisp and can therefore not implement it.
martin

 

This is what i use to get the paper sizes, save this into you LISP file for PDF plotting and in the plot command where it asks for paper size  use  (C:getpapersize) instead. Note that there is a list at the top of there with 'A' size papers, you can change them to whatever you want to suit yourself.

 

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun papersizes ( / PSIZE)
  (setq psize (list
    '(148.00 210.00 297.00 420.00 594.00 841.00 1189.00) ;; Papers dimensions. Add 1 size smaller at the start of list
    '("A0" "1189.00 x 841.00" "Landscape") ;; Size Name, Width x Height, Orientation. List largest to smallest
    '("A0" "841.00 x 1189.00" "Portrait")
    '("A1" "841.00 x 594.00" "Landscape")
    '("A1" "594.00 x 841.00" "Portrait")
    '("A2" "594.00 x 420.00" "Landscape")
    '("A2" "420.00 x 594.00" "Portrait")
    '("A3" "420.00 x 297.00" "Landscape")
    '("A3" "297.00 x 420.00" "Portrait")
    '("A4" "297.00 x 210.00" "Landscape")
    '("A4" "210.00 x 297.00" "Portrait")
    '("A5" "210.00 x 148.00" "Landscape")
    '("A5" "148.00 x 210.00" "Portrait")
    ) ;end list
  )
  PSIZE
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:getpapersize ( / CustomPapers acadObj doc PaperWidth PaperHeight paperdimensions papersize n acount pwn phn aplotsize orientation)
  (setq CustomPapers (papersizes))
;;get current paper dimensions and orientation
  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acadObj))
  (vla-GetPaperSize (vla-get-ActiveLayout doc) 'PaperWidth 'PaperHeight)

;;Get nearest standard paper sizes
  (setq paperdimensions (nth 0 CustomPapers))
  (setq n 0)
  (while (< n (length (nth 0 CustomPapers)) )
  ;;height
    (if (< (nth n (nth 0 CustomPapers)) PaperHeight (nth (+ n 1) (nth 0 CustomPapers)) )
      (setq phn n)
    ) ;;end if
    (if (= (nth n (nth 0 CustomPapers)) PaperHeight)
      (setq phn n)
    ) ;;end if
  ;;width
    (if (< (nth n (nth 0 CustomPapers)) PaperWidth (nth (+ n 1) (nth 0 CustomPapers)) )
      (setq pwn n)
    ) ;;end if
    (if (= (nth n (nth 0 CustomPapers)) PaperWidth)
      (setq pwn n)
    ) ;;end if
    (setq n (+ n 1))
  ) ; end while

;;fix if pwn = pwh. Default to landscape
  (if (= pwn phn)
    (progn
      (setq pwn (+ pwn 1))
    )
  )

  ;;match paper size with standard paper sizes (according to papersizes function)
  ;;paper orientation
  (if (= pwn (+ phn 1))(setq orientation "Landscape"))
  (if (> pwn (+ phn 1))(setq orientation "Oversize Landscape"))
  (if (= pwn (- phn 1))(setq orientation "Portrait"))
  (if (< pwn (- phn 1))(setq orientation "Oversize Portrait"))

;;Page Dimensions
  (if (= orientation "Landscape")
      (setq papersize (strcat (rtos (nth pwn (nth 0 CustomPapers)) 2 0) ".00 x " (rtos (nth (- pwn 1) (nth 0 CustomPapers)) 2 0) ".00" ))
  ) ; end if
  (if (= orientation "Portrait")
      (setq papersize (strcat (rtos (nth pwn (nth 0 CustomPapers)) 2 0) ".00 x " (rtos (nth (+ pwn 1) (nth 0 CustomPapers)) 2 0) ".00" ))
  ) ; end if

  (setq acount 1)
  (while (< acount (length CustomPapers))
    (if (= papersize (nth 1 (nth acount CustomPapers))) (setq aplotsize (nth 0 (nth acount CustomPapers))) )
    (setq acount (+ acount 1))
  ) ;end while

  (setq papersize (vl-string-subst papersize "[width x height]" (papername)))
  (setq papersize (vl-string-subst aplotsize "[An]" papersize))

;;fix for largest paper size
;;  (if (or (= pwn (- (length paperdimensions) 1)) (= pwh (- (length paperdimensions) 1)) )
  (if (or (= pwn (length paperdimensions)) (= pwh (length paperdimensions)) )
     (setq papersize (strcat "ISO expand " (nth 0 (nth 1 CustomPapers)) " (" (nth 1 (nth 1 CustomPapers)) " MM)" ))
  )

;;fix for A0 Expand
(if (= papersize "ISO expand A0 (1189.00 x 841.00 MM)")(setq papersize "ISO expand A0 (841.00 x 1189.00 MM)"))

(princ papersize)

;;return paper size
  papersize
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

 

And this is what I use to get the page orientation, same as before, add (PDFGetPageOrientation) in where the plot command ask for orientation

 

(defun PDFGetPageOrientation ( / pageorientation acadObj doc PaperWidth PaperHeight)
  (setq pageorientation "L") ;; default
  (setq drgextents (mapcar (function getvar) '("EXTMIN" "EXTMAX")) ) ;; by page extents method. Appears to give best results
  (setq lenx (- (nth 0 (nth 1 drgextents)) (nth 0 (nth 0 drgextents))) )
  (setq leny (- (nth 1 (nth 1 drgextents)) (nth 1 (nth 0 drgextents))) )
  (if (< lenx leny)(setq pageorientation "P"))
  (if (> lenx leny)(setq pageorientation "L"))
  pageorientation
)

 

 

Also to note - more to those who are quite good at LISPS, I made these up over time, and probably there are better ways of doing things,.

 

Link to comment
Share on other sites

For Martinle as I suggested if you have a title block then can use a couple of things to work out which pdf size to use, 

 

1st is titleblock name

2nd is the rotation angle 

 

The other thing is the title block should be at true scale 1:1 eg A3 size is 420x297 your title block will be a bit smaller to allow for print clip limits.

 

In simple terms go to layout use ssget insert blocknames this will get the title block and like steven p use a cond to set correct plot variables.

 

If you could provide a dwg with say rectang blocks representing your tite block can do something. 

 

 

 

Link to comment
Share on other sites

Just need a sample dwg with title blocks in layouts or at least a rectang  block representing the title block same size and name. Then can be done and some example code produced.

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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