LISP for printing from a button

LISP for printing from a button

tims79
Enthusiast Enthusiast
5,537 Views
15 Replies
Message 1 of 16

LISP for printing from a button

tims79
Enthusiast
Enthusiast

I'm having a problem with a LISP routine for printing to a pdf file.  I have the LISP working as desired - but only if I type the command into the command prompt.  What I would like to do is run the command from a button on the ribbon.  But when I do that, the LISP gets hung up on the step where it saves the file to a folder.  Can anyone tell me what am I doing wrong?  I don't understand why the same command works differently when entered command line vs. button.  Attached is my lisp file.

0 Likes
5,538 Views
15 Replies
Replies (15)
Message 2 of 16

Jonathan3891
Advisor
Advisor

See if this works.

(defun c:PDFLIMITS1=1MM (/ dwg)
	(command "tilemode" "1")
	(command "cmdecho" "1")
	(command "-plot" 
	"y"; detailed configuation
	"MODEL"; layout name
	"Autocad PDF (Smallest File).pc3"; device name
	"ANSI full bleed A (11.00 x 8.50 Inches)"; paper size
	"M"; paper units
	"L"; orientation
	"N"; plot upside down?
	"L"; plot area - Limits
	"1=1"; scale
	"CENTER"; Offset
	"N"; plot with styles?
	"."; style table name
	"Y"; plot with lineweights?
	"A"; shade plot setting
	(strcat "C:\\temp\\"(getvar 'dwgprefix) (substr (setq dwg  (getvar 'dwgname)) 1 (- (strlen dwg) 4)) ".pdf")
	"y"
	"Y"
	)
  	(princ)
)

Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 16

tims79
Enthusiast
Enthusiast

Not quite.  I think that is adding the current drawing prefix, when I was already specifying C:\Temp\.  If I remove the  (getvar 'dwgprefix)  I am right back where I started.  It works from the command line but not from a button.

0 Likes
Message 4 of 16

Jonathan3891
Advisor
Advisor

OK, that was untested.

 

I've tested this and it works with a button.

 

(defun c:ttt (/ )
	(command "tilemode" "1")
	(command "cmdecho" "1")
	(command "-plot" 
	"y"; detailed configuation
	"MODEL"; layout name
	"Autocad PDF (Smallest File).pc3"; device name
	"ANSI full bleed A (11.00 x 8.50 Inches)"; paper size
	"M"; paper units
	"L"; orientation
	"N"; plot upside down?
	"L"; plot area - Limits
	"1=1"; scale
	"CENTER"; Offset
	"N"; plot with styles?
	"."; style table name
	"Y"; plot with lineweights?
	"A"; shade plot setting
	(strcat "C:\\temp\\" (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) ".pdf")
	"y"
	"Y"
	)
  	(princ)
)

Jonathan Norton
Blog | Linkedin
0 Likes
Message 5 of 16

SeeMSixty7
Advisor
Advisor

I think your problem is the name of your command. take the equals (=) sign out of your defun statement.

 

Hope that helps

0 Likes
Message 6 of 16

tims79
Enthusiast
Enthusiast

When you assigned a button to run it, for the button did you just enter ttt for the macro?  That isn't working for me, but it does work to enter ttt in the command line.

0 Likes
Message 7 of 16

Jonathan3891
Advisor
Advisor

The button command is 

^C^Cttt

Jonathan Norton
Blog | Linkedin
0 Likes
Message 8 of 16

tims79
Enthusiast
Enthusiast

This is what has been driving me crazy.  I get the same hanging result with ^C^Cttt.  Attached is a screencap of my Autocad text window when running it from a button.  It looks like something goes wrong when saving the pdf.

 

Which version of Autocad are you using?  I have 2019

 

0 Likes
Message 9 of 16

Scottu2
Advocate
Advocate

I loaded your Lisp and added a macro to my toolbar.

It works for me, even with the =. (Autocad 2019)

 

The filename does not match,  the command string is off by one line.

Perhaps the plot string keystrokes where created while in paper space?

 

If the menu macro is using lisp commands to load the lisp first then check that code again.

 

0 Likes
Message 10 of 16

Sea-Haven
Mentor
Mentor
0 Likes
Message 11 of 16

tims79
Enthusiast
Enthusiast

The arrow you made pointing to the filename not matching - that is the problem. Something is going wrong at that point - but ONLY when I run the command from a button macro. If I type the command in it works perfectly.

 

The macro is simply the same command as I am typing manually, not loading a lisp first. The lisp is already loaded, verified by the fact that it works manually.

 

Is there some setting related to macros and the writing of files/directories? Security or permission setting? I am at a loss.

 

 

 

 

0 Likes
Message 12 of 16

tims79
Enthusiast
Enthusiast

The arrow you made pointing to the filename not matching - that is the problem. Something is going wrong at that point - but ONLY when I run the command from a button macro. If I type the command in it works perfectly.

 

The macro is simply the same command as I am typing manually, not loading a lisp first. The lisp is already loaded, verified by the fact that it works manually.

 

Is there some setting related to macros and the writing of files/directories? Security or permission setting? I am totally at a loss.

 

0 Likes
Message 13 of 16

Scottu2
Advocate
Advocate

Hi Tim79,

 

When it did my test is was using the tool bar, it see that the ribbon is used here.

Compare the plot command results. See attached screen shot.

 

0 Likes
Message 14 of 16

tims79
Enthusiast
Enthusiast

Scott

Obviously, I noticed the different results.  That is what I don't understand and my whole reason for posting here.

 

You seem to be onto something with the toolbar vs ribbon, though.  It works correctly when launched from a toolbar button.  So it looks like the problem is with the ribbon interface.  That is good enough for me, I will just make a toolbar with the buttons I need.  Screw the ribbon!

 

Thanks

0 Likes
Message 15 of 16

Scottu2
Advocate
Advocate

Hello tims79,

Good you got it working.  As for the ribbon, the symptom is similar to plotting from LAYOUT vs MODEL space.  The layout adds questions regarding to paper space.

Perhaps you can still use the ribbon, by setting a variable to 1 to indicate the routine is to use a different plot command string and the routine sets that variable back to zero.

 

0 Likes
Message 16 of 16

Scottu2
Advocate
Advocate

Hi Tims79,

 

I  made the ribbon button and ran the routine and it works, on my machine.

I was not able to reproduce the error, so the original code is good.

Attached is the ribbon button AP i created.

 

 

0 Likes