Lisp to create pdf and send mail

Lisp to create pdf and send mail

larsr2866
Enthusiast Enthusiast
2,901 Views
30 Replies
Message 1 of 31

Lisp to create pdf and send mail

larsr2866
Enthusiast
Enthusiast

Good day everyone,

 

I was wondering if it's even possible to create a lisp for printing a specific layout (user imput to specify the layout) to pdf (user imput to name the pdf) + create a mail with the pdf as attachement?

 

Thanks for your reactions.

Lars

0 Likes
2,902 Views
30 Replies
Replies (30)
Message 21 of 31

cadffm
Consultant
Consultant

Also gerne darfst du auch etwas mehr Zeit in die Lösung deiner eigenen (Einzel-)Probleme stecken,

ich kann es nur recht schlecht testen (eigentlich überhaupt nicht ohne eingerichtetes Outlook).

 

Von daher ein Versuch der Hilfe zur Selbsthilfe, ohne einen Blick in den Code..

 

Wo hakt es denn beim erneuten Aufruf genau?

Mit welcher Rückmeldung, Meldung, FEhler, Symptom.. Irgendwas muß ja passieren - oder etwas erwartetes passiert nicht*.

 

*und damit meiner ich nicht den wunderbaren fehlerfreien Ablauf samt gewünschtem Resultat, sondern ganz spezifisch: Welche Stelle im Programm..

 

Setz dich an die VLide und gehe den code Schritt für Schritt durch.

 

Wenn ich wenige zutun habe, der Arbeitsplatz kühler ist oder die Arbeit zu sehr nervt, investiere ich evtl. auch noch mal mehr Zeit und werfe einen Blick darauf.

 

Sebastian

Sebastian

0 Likes
Message 22 of 31

larsr2866
Enthusiast
Enthusiast

Thanks for your quick reaction. My german isn't very good, but google translate helped me a bit 🙂

 

It loads my lisp without any problem, but it says unknown command..

Very weird, because it worked the first time.

0 Likes
Message 23 of 31

cadffm
Consultant
Consultant

>"My german is"

Sorry, lol Man LOL

 

 

>"It loads my lisp without any problem, but it says unknown command.. Very weird, because it worked the first time."

 

>"It loads my lisp"

Who is "IT" and why load "IT"     "the Lisp"?

Code? Commands? Dialogs? What is your fully workflow?

 

>" it says unknown command."

You didn't post any code what would define a "AutoCAD Command", so i can not help you because i don't know your code.

 

(defun C:MYNEWACADCOMMAND nil
(rjp-OutlookMessage
 "fehler@sags-per.mail.de" ;; email address (multiple separated by semicolon)
 "Test Email via Lisp" ;; Subject
 '("C:\\mypath\\myfile.txt") ;; Attachments as a list of strings
 "Happy, it works" ;; Text in body of email
 nil
)

)

 

MYNEWACADCOMMAND is an AutoCAD command, defined cia Lisp function defun c:

 

>"Very weird, because it worked the first time."

Please, post all steps and code and we can help.

 

Sebastian

0 Likes
Message 24 of 31

larsr2866
Enthusiast
Enthusiast

Hi Everyone,

It took me a while to get back on this topic. But i've searched a bit to change my lisp.
My intension was to make one function to create a new pdf (revision 'a' for example) from my acad file and create a mail with this last created pdf in
it as attachement.


It works, except for the last created pdf attachement. It would be great, if anyone could help me further with this? 🙂

 


(defun c:sendmail (/ Mail)

(command "_.-PLOT" ; plot sequence of a layout

"_yes" ; detailed version
"plan_A_1"; layoutname
"Dwg To PDF.pc3" ; plotter
"ISO full bleed A1 (841.00 x 594.00 mm)" ; papersize
"_millimeters" ; and so on..
"_landscape"
"_no"
"_layout"
"1:1"
"0.00,0.00"
"_yes"
"plan_563.ctb"
"_yes"
"_no"
"_no"
"_no"
"~";name user input
"_no"
"_yes"
)


(cond
(
(setq mail (strcat "mailto:"
"?Subject=name of the last pdf."
"&body= In attachement you'll find the new revision"
;;;Error
;;; "&body=" In attachement you'll find the new revision
;;;
)
)
(setq IShell (vlax-create-object "Shell.Application.1"))
;;; of
;;; (setq IShell (vlax-create-object "Shell.Application"))
(setq imail (vlax-invoke-method IShell "ShellExecute" mail))
(vlax-release-object IShell)
)
)
(princ)
)

0 Likes
Message 25 of 31

cadffm
Consultant
Consultant

I can not see that you checking if the PDF is ready created before you start your mail..!?

Or is your problem not to know the path and name of the PDF file??

Sebastian

0 Likes
Message 26 of 31

larsr2866
Enthusiast
Enthusiast

The thing is i need to save my pdf always in the folder of the dwg and name my pdf manually (with user imput), wich already works with my lisp. 

 

This is a example from my folder map:

SETKFS102Drawing for VR5621.dwg

VR5621.pdf

VR5621-revision a.pdf

VR5621-revision b.pdf

VR5621-revision c.pdf

 

So the idea in this case is to make a revision d, and save it in this folder and create a mail with the pdf VR5621-revision d.pdf

0 Likes
Message 27 of 31

cadffm
Consultant
Consultant

Okay, and what is the problem, what's the question?

Sebastian

0 Likes
Message 28 of 31

larsr2866
Enthusiast
Enthusiast

The problem is i can't figure out how to get this last created pdf as attachement in my mail.

I understand i should find it out myself, but i don't now how to get futher with this, and i can't find anything similar on the internet. I can find a lot on forums about autocad functions but not much about mailing withing acad.

 

I was thinking in these following steps, so i put this order also in my lisp except for step 3. However, you made me doubt that the mail should be created before i create my pdf?

1. create pdf

2. create mail

3. put the pdf as attachement in mail

0 Likes
Message 29 of 31

cadffm
Consultant
Consultant

To make clear:

In the past you wrote my code works...

Now i am asking again: 

Is it working with an already existing file as attachment, yes or no?

 

If yes:

Please read my second last answer again.

As simple test, add a simple (command "_delay" 2000) between PDF-Plot and Mail-send.

2000 or 5000 or 10000, whatever. Make sure

The the file is ready created before you try to attachs the file.

Sebastian

0 Likes
Message 30 of 31

larsr2866
Enthusiast
Enthusiast

Unfortunately, the attachement doesn't work with an existing file either.

Maybe i should try to get this working with a pop up a window to select my file (user imput), but i don't know this is even possible within acad?

0 Likes
Message 31 of 31

cadffm
Consultant
Consultant

@larsr2866  schrieb:

Unfortunately, the attachement doesn't work with an existing file either.

So it is absolutely uninteresting that you "new" pdf won't work,

the problem is more generally: The code dosn't work with attachments (for you).

Right? ok

 

Maybe i should try to get this working with a pop up a window to select my file (user imput),

Please, if you are not able to add an absolute/fix path with already existing files, how or why should it works with an user dialog to select a file?

 

but i don't know this is even possible within acad?

Sure&Easy, but you don't need that and you problem is another one.


Your way to think is...sub-optimal 🙂

 

Now, I have the schnauze voll (LOO, It's DENGLISCH, Deutsch/Englisch and means "it is enough" 😉 )

I created a new mail account

I installed outlook

I setup my new outlook with my new mail account

and tested.

'It works at the first try!

 

	(defun ONL:SENDMAIL (an Betreff Inhalt Anhang / MAIL OLOBJ)
          (vl-load-com)
	   (setq OLOBJ (vlax-Get-Or-Create-Object "Outlook.Application")
	          MAIL  (vlax-invoke-method OLOBJ "CreateItem" 0)
	   )
	   (vlax-invoke-method (vlax-get-property MAIL 'recipients) 'add an)
           (if (and Anhang (findfile Anhang))
	     (vlax-invoke-method (vlax-get-property MAIL 'attachments)'add (findfile Anhang))
	   )
	   (vlax-put-property MAIL 'subject betreff)
	   (vlax-put-property MAIL 'body Inhalt)
	   (vlax-invoke-method MAIL 'send)
	   (vlax-release-object OLOBJ)
	  (princ)
	)

;; TEST - (ONL:SENDMAIL "cadffm@nurfuerspam.de" "Testmail with attachment" "Body" "D:\\PDFEXT1.pdf")

MY hint: Search in www for :
AutoCAD Outlook.Application CreateItem 
to find more sample codes.

Sample with a fix path/file

(ONL:SENDMAIL "cadffm@nurfuerspam.de" "Topic" "Body" "D:\\PDFEXT1.pdf")

Sebastian

0 Likes