Looking for a LISP to attach current drawing/open drawing to email

Looking for a LISP to attach current drawing/open drawing to email

Jason.Rugg
Collaborator Collaborator
1,173 Views
11 Replies
Message 1 of 12

Looking for a LISP to attach current drawing/open drawing to email

Jason.Rugg
Collaborator
Collaborator

I am looking for a simple LISP that will start an new outlook email message and attach the current/active drawing file that is open.

0 Likes
Accepted solutions (2)
1,174 Views
11 Replies
Replies (11)
Message 2 of 12

doaiena
Collaborator
Collaborator
Message 3 of 12

Jason.Rugg
Collaborator
Collaborator

@doaienaThat does not work, it errors out with "too many arguments".

Message 4 of 12

doaiena
Collaborator
Collaborator

It worked for me like this:
(rjp-OutlookMessage "mail@mailserver.com" "Test Email" '("C:\\Drawing1.dwg") "Nothing to read here :)" T)

Your are probably feeding too many arguments to the function.

Message 5 of 12

CodeDing
Advisor
Advisor

It worked for me also.

0 Likes
Message 6 of 12

Jason.Rugg
Collaborator
Collaborator

@doaiena @CodeDing I've tried it on multiple computers now, it fails on every one of them. Can either of you do a screencast showing the code and how you are using it?

Message 7 of 12

CodeDing
Advisor
Advisor

@Jason.Rugg ,

 

I can't screencast, but when I paste this code into a dwg (with appropriate input changes) then run "TEST" it pops up the email (have also tested w/ sending it).

Do you have Outlook? Mac/PC?

(defun c:TEST ( / )
  (defun rjp-OutlookMessage
         (To Subject AttachmentList Body Send / objMail objOL)
    (if (and (setq objOL (vlax-get-or-create-object "Outlook.Application"))
	     (setq objMail (vlax-invoke-method objOL 'CreateItem 0))
        )
      (progn
        (vlax-put objMail 'To To)
        (vlax-put objMail 'Subject Subject)
        (vlax-put objMail 'Body Body)
        (foreach file AttachmentList
  	  (vl-catch-all-apply
	    'vlax-invoke
	    (list (vlax-get objMail 'Attachments)
		  'Add
		  file
	    )
  	  )
        )
        (if send
 	  (vlax-invoke objMail 'Send)
	  (vlax-invoke objMail 'Display :vlax-true)
        )
        (vlax-release-object objOL)
        (vlax-release-object objMail)
      )
    )
    (princ)
  )
(rjp-OutlookMessage
  ;;email address (multiple separated by semicolon)
  "myemail@myemail.com"
  ;;Subject
  "Test Email"
  ;;Attachments as a list of strings
  '("C:\\users\\myusername\\desktop\\test.dwg")
  ;;Text in body of email
  "Nothing to read here :)"
  ;;nil will open email to edit...T will send email in the background
  nil ;<- I have tried this w/ nil and t successfully
)
);defun

Best,

~DD

0 Likes
Message 8 of 12

ronjonp
Advisor
Advisor

I don't use Outlook anymore but try calling like this:

(rjp-outlookmessage
  "mail@mailserver.com"
  "Test Email"
  (list (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
  (strcat "Hello Client, Please see attached drawing: " (getvar 'dwgname))
  nil
)
Message 9 of 12

Jason.Rugg
Collaborator
Collaborator

@CodeDingOk this is actually halfway working, it will at least open a pre-filled/blank email but it does not attach the active drawing file that the command was called out in. I'm not the most versed in LISP and coding.

Message 10 of 12

CodeDing
Advisor
Advisor
Accepted solution

@Jason.Rugg ,

 

For that, you will use @ronjonp 's elegant method.

Here it is incorporated with a check to be sure your dwg has already been saved.

(defun c:TEST ( / txt)
  (defun rjp-OutlookMessage
         (To Subject AttachmentList Body Send / objMail objOL)
    (if (and (setq objOL (vlax-get-or-create-object "Outlook.Application"))
	     (setq objMail (vlax-invoke-method objOL 'CreateItem 0)))
      (progn
        (vlax-put objMail 'To To)
        (vlax-put objMail 'Subject Subject)
        (vlax-put objMail 'Body Body)
        (foreach file AttachmentList
  	  (vl-catch-all-apply 'vlax-invoke
			      (list (vlax-get objMail 'Attachments) 'Add file))
        );foreach
        (if send
 	  (vlax-invoke objMail 'Send)
	  (vlax-invoke objMail 'Display :vlax-true)
        );if
        (vlax-release-object objOL)
        (vlax-release-object objMail)
      );progn
    );if
  );defun
(if (= 1 (getvar 'DWGTITLED))
  (progn 
    (rjp-outlookmessage
      "mail@mailserver.com"
      "Test Email"
      (list (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
      (strcat "Hello Client, Please see attached drawing: " (getvar 'dwgname))
      nil
    )
    (prompt "\nEmail Created.")
  );progn
;else
  (progn
    (setq txt "Drawing has not been saved. Please save and try again.")
    (prompt (strcat "\n" txt)) (alert txt)
  );progn
);if
(princ)
);defun

Best,

~DD

0 Likes
Message 11 of 12

Jason.Rugg
Collaborator
Collaborator
Accepted solution

@CodeDingWith some modifications I was able to get this to work well enough for my needs. Thank you.

Message 12 of 12

CodeDing
Advisor
Advisor

@Jason.Rugg ,

 

I fell you should credit @doaiena  and @ronjonp  for their relevant and direct contributions to the solution.