Help with Lisp for plotting in PDF

Help with Lisp for plotting in PDF

elias.kanellakis
Participant Participant
1,047 Views
8 Replies
Message 1 of 9

Help with Lisp for plotting in PDF

elias.kanellakis
Participant
Participant

Hi everyone!

 

I try to write a lisp that does the following:

 

  • asks the user to select the opposite corners of a window in the layout space
  • uses these coordinates to calculate the size of the paper needed to plot (x and y)
  • depending on the size it chooses between some already existing paper sizes (eg 1000x1000 in this case)
  • plots (preview) the selected window in the paper

Unfortunately it doesn't work for some reason.. Can anyone help me in this? Is it a syntax error? Is it about the type (float) of the variables? Something else?

 

 

(DEFUN C:PDF (/ x1 x2 y1 y2 x y p1 p2)

 

;get the coordinates of the 2 opposite corners of the window
(setq p1 (getpoint "\nPick first corner of window: \n"))
(setq p2 (getcorner p1 "\nPick opposite corner of window: \n"))

 

;isolate x and y coordinates

(setq x1 (float(car p1)))
(setq y1 (float(cadr p1)))
(setq x2 (float(car p2)))
(setq y2 (float(cadr p2)))

 

;calculate paper size needed

(setq x (- x2 x1))
(setq y (- y2 y1))

 

;if lets say x=1000mm plot preview in paper size 1000x1000 (etc)

(IF (= x 1000.0)

 

(COMMAND "-PAGESETUP" "AutoCAD PDF (High Quality Print).pc3" "User 1 (1000.00 x 1000.00 MM)" "M" "P" "N" "W" p1 p2 "1=1" "C" "Y" "acad.ctb" "Y" "N" "N" "N")


(COMMAND "PREVIEW")


); end IF


);end DEFUN

0 Likes
1,048 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

For me it fails since I don't have this custom paper size:

User 1 (1000.00 x 1000.00 MM)

 

Also I assume after creating the pagesetup you want to run plot preview then you need to change this from:

(IF (= x 1000.0)
(COMMAND "-PAGESETUP" "AutoCAD PDF (High Quality Print).pc3" "User 1 (1000.00 x 1000.00 MM)" "M" "P" "N" "W" p1 p2 "1=1" "C" "Y" "acad.ctb" "Y" "N" "N" "N")
(COMMAND "PREVIEW")
); end IF

 To this:

(if (= x 1000.0)
 (progn ; if condition is true then
  (COMMAND "_.-PAGESETUP" "AutoCAD PDF (High Quality Print).pc3" "User 1 (1000.00 x 1000.00 MM)" "_M" "_P" "_N" "_W" p1 p2 "1=1" "_C" "_Y" "acad.ctb" "_Y" "_N" "_N" "_N")
  (COMMAND "_.PREVIEW")
 ) ; progn
 (alert "X is not equal to 1000") ; if condition is false else
); end if

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 9

Sea-Haven
Mentor
Mentor

Why are you not using true paper sizes and matching Title blocks, A 1000x1000 is not a normal size, A0 is close 1189x841. Your plotting to pdf but I don't think there is a general Plotter with a 1000+ wide roll could be wrong. 

 

There is plenty of lisp examples about match title block and plot to pdf at true 1:1 scale. I have one that looks at each title block in a layout and they can be different sizes and or orientation, portrait or landscape. For me just click on a menu button and watch the sheets being produced.

0 Likes
Message 4 of 9

paullimapa
Mentor
Mentor

Since there's no lisp method I know of that makes it possible for the user to create a custom paper size in the pc3 on the fly and the pagesetup command requires an already created paper size to successfully complete a pagesetup, what @elias.kanellakis wants to do in selecting a window to create a pagesetup on the fly fails. 

But a workaround could be to look for the closes standard portrait A size paper (since the pagesetup in the code is for portrait) that will accommodate.

Then if found complete the pagesetup else alert the user:

; PDF prompts user to select window to calculate paper size for page setup
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-with-lisp-for-plotting-in-pdf/m-p/13020195/highlight/false#M471647
(DEFUN C:PDF (/ x1 x2 y1 y2 x y p1 p2 pprsiz)
;get the coordinates of the 2 opposite corners of the window
(setq p1 (getpoint "\nPick first corner of window: \n"))
(setq p2 (getcorner p1 "\nPick opposite corner of window: \n"))
;isolate x and y coordinates
(setq x1 (float(car p1)))
(setq y1 (float(cadr p1)))
(setq x2 (float(car p2)))
(setq y2 (float(cadr p2)))
;calculate paper size needed
(setq x (- x2 x1))
(setq y (- y2 y1))
(if (<= x y) (setq x y)(setq y x)) ; find larger size
(cond ; find portrait standard full bleed A size sheets that fit
 ((<= x 210)(setq pprsiz "ISO full bleed A4 (210.00 x 297.00 MM)"))
 ((<= x 297)(setq pprsiz "ISO full bleed A3 (297.00 x 420.00 MM)"))
 ((<= x 420)(setq pprsiz "ISO full bleed A2 (420.00 x 594.00 MM)"))
 ((<= x 594)(setq pprsiz "ISO full bleed A1 (594.00 x 841.00 MM)"))
 ((<= x 841)(setq pprsiz "ISO full bleed A0 (841.00 x 1189.00 MM)"))
 (t (setq x nil))
)
(if x ; if matches found for standard A portrait paper size 
 (progn ; then condition is true 
  (COMMAND "_.-PAGESETUP" "AutoCAD PDF (High Quality Print).pc3" pprsiz "_M" "_P" "_N" "_W" p1 p2 "1=1" "_C" "_Y" "acad.ctb" "_Y" "_N" "_N" "_N")
  (COMMAND "_.PREVIEW")
 ) ; progn
 (alert (strcat "Not Supported for Larger than standard A Paper Size of: " (rtos y 2 2))) ; else condition is false
); end if
(princ)
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 9

Sea-Haven
Mentor
Mentor

I think we need we need to wait for elias to comment about why not using true sheet sizes and Mview to scale objects in say "Model" the intention of using layouts. Otherwise why not just use plot extents to one known sheet size.

0 Likes
Message 6 of 9

elias.kanellakis
Participant
Participant

Hi, thanx for the replies

 

So, 1000x1000 paper is just for example, I don't want to actually plot this size.. But I want to be able to plot in different custom paper sizes each time (not just the standard A0, A1, etc.) without entering the pagesetup window..

 

I will have ALREADY CREATED let's say 20-30 custom paper sizes (e.g. 300x400, 350x400, 400x450, ... , 1000x1000 ec).. I want the lisp to compare the size of the rectangular window I select to these paper sizes and decides which one is the most suitable (with an if-else function) ... Let's say it calculates x=360mm and y=460mm, so it plots in the 400x500 paper that already exists in my computer..

 

 

0 Likes
Message 7 of 9

elias.kanellakis
Participant
Participant

Hi,

yes something like this, I will just have the custom papers already created (let's say 20 - 30 different sizes) and let the lisp find the wright one..

 

This should work, i 'll thest it later..

 

Thanx :))

0 Likes
Message 8 of 9

paullimapa
Mentor
Mentor

Glad to have helped….cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 9

hak_vz
Advisor
Advisor

I would instead use page setups. With page setup one can define any printing property he likes. If there is no defined paper size, use print server properties to define non standard dimension. Assign name to print setup with the name of output pdf file and that's it.

 

(defun c:batch_plot_pdf_modelspace ( / )
	(vlax-for item (vla-get-plotconfigurations (vla-get-ActiveDocument (vlax-get-acad-object)))
		(if (not(wcmatch (vla-get-name item) "*Model*"))
			(vl-cmdf
				"_.-plot" 
				"No"
				"Model"
				(vla-get-Name item)
				(vla-get-ConfigName item)
				(strcat (getvar 'dwgprefix) (vla-get-Name item) ".pdf")
				"No"
				"Yes"
			)
		)
	)
	(princ)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes