1
AutoLISP (Vanilla / Visual) / Re: Lisp to e-mail content to helpdesk.
« Last post by Lonnie on Today at 12:36:38 PM »I never did Publish the lisp.
Code: [Select]
;; Call IT Helpdesk Script
;; Using Outlook, this script will email selected objects in a temporary DWG file.
;; Credits to Ron Perez (ronjonp) for the Outlook example:
;; http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794
;; http://www.theswamp.org/index.php?topic=55486.0
;; Lonnie Shaw 2020-01-06
;; Enter the Email Addresses Here as Strings
(setq *IT-Email* "lshaw@coname.net"
*CC-Email* "bsmead@coname.net"
*BCC-Email* "bseverson@coname.net; dsmith@coname.net; tmcauley@coname.net; jnewton@coname.net; pwyman@coname.net; rstock@coname.net; jarreola@coname.net"
*Fileset1* (strcat "\nI need assistance from a CAD area Lead. Thank you!"
"\nExample file from"
"\n" (getvar "dwgprefix")
"\"" (getvar "dwgname") "\"")
)
(defun c:CRGhelp (/ _catch cc file outlook email sf si ni)
;; Load the Visual LISP extension
(vl-load-com)
;; Define a helper function to catch errors
(defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))
;; Alert the user to select objects and send mail from Outlook
(alert "Please create a scratch file by selecting the elements you are having problems with. \n\nAfter you select objects to mail, remember to send mail from Outlook.")
(if
(and
;; Get selected objects
(or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
;; Create a temporary DWG file
(setq file (vl-filename-mktemp "" nil ".dwg"))
(_catch 'vla-WBlock
(list (cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))))
file
(vla-get-activeselectionset *AcadDoc*)))
;; Create an Outlook application instance
(setq outlook (vlax-get-or-create-object "Outlook.Application"))
(setq sf (vl-catch-all-apply 'vlax-invoke (list (setq ns (vlax-invoke outlook 'GetNameSpace "MAPI")) 'GetDefaultFolder 5)))
(setq si (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count)))
;; Create a new email item
(setq email (vlax-invoke-method outlook 'CreateItem 0))
;; Set email subject
(_catch 'vlax-put (list email 'Subject "Helpdesk Ticket: "))
;; Attach the temporary DWG file
(_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
;; Add recipients
(_catch 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *IT-Email*))
(setq cc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *CC-Email*)))
(setq bcc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *BCC-Email*)))
;; Set recipient types
(_catch 'vlax-put (list cc 'Type 2)) ;; CC
(_catch 'vlax-put (list bcc 'Type 3)) ;; BCC
;; Set the email body
(_catch 'vlax-put (list email 'Body *Fileset1*))
)
;; Display the email in Outlook and handle file cleanup
(progn
(princ "\nOutlook active...")
(vlax-invoke email 'Display :vlax-true)
(if (= (vl-catch-all-apply 'vlax-get (list email 'Sent)) :vlax-true)
(vl-file-delete file)
(progn
(if (= (setq ni (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))) si)
(vl-file-delete file) ;; No email was added to Sent Items - delete the file
)
)
)
)
)
;; Release COM objects
(foreach x (list sf ns email outlook) (and x (vlax-release-object x)))
(princ)
)