Using (vlax-get-or-create-object "prog-id")

Using (vlax-get-or-create-object "prog-id")

spykat
Advocate Advocate
234 Views
2 Replies
Message 1 of 3

Using (vlax-get-or-create-object "prog-id")

spykat
Advocate
Advocate

I have an issue where the drafters don't tell me right away if there's a problem, sometimes never. So I wanted to add code to my programs that automatically emails me when there's a problem. I found this but I don't know how to make it work with our Outlook 365. How do I find out what the prog-id is for my Outlook?

 

(defun C:OUTLOOK11 (/ objOLApp)
(setq objOLApp (vlax-Get-Or-Create-Object "Outlook.Application.11") myOlMailItem (vlax-invoke-method objOlApp "CreateItem" 0))
(vlax-put-property myOlMailItem "to" "cadmanager@strandsystems.com")
(vlax-put-property myOlMailItem "subject" "test email")
(vlax-put-property myOlMailItem "body" "sample body")
(vlax-invoke-method myOlMailItem "send")
(prin1)
)

0 Likes
235 Views
2 Replies
Replies (2)
Message 2 of 3

CodeDing
Advisor
Advisor

@spykat ,

 

My recommendation, do not send emails blindly. This will eventually create a trust issue between you and the user(s). Instead, you can easily use the mailto URI scheme. This is just a string that you can execute to populate the default email with content.

Here's an example:

(defun c:TEST ( / emailStr)
  (setq emailStr
    (strcat
      "\"mailto:"
      "user@example.com" ;; add 'to' users, separate with semicolon ';'
      "?subject="
      "My Subject Line %26 Custom Info"   ;; add 'subject' here, %26 is ampersand &
      "&body="
      "This is my 'Body' content..."      ;; add 'body' content here
      "%0a"                               ;; this is a newline character
      "I can include %22Quotes%22 and..." ;; %22 is a quote
      "%0a"
      "Use multiple lines."
      "\"" ;; keep this line, mailto string must be in quotes
    );strcat
  );setq
  ;; now, open users default mail app
  ;(alert (princ (strcat "\nFinal 'mailto' string:\n" emailStr)))
  (startapp "explorer" emailStr)
  (princ)
)

 

Best,

~DD

Message 3 of 3

Sea-Haven
Mentor
Mentor

If you want to get a message about an error you could use an Error trap, that sends the message to you with the users name (getenv "username"), Only problem may be how many your going to get a day. A better approach may be to write to a file using the "A" option, append to file. Then you check say once a day, include the date time etc. 

 

This is an example of trapping an Error has occurred, I use this to draw objects taking advantage of the error message. You would just need one defun to write a file remember to close after writing.

 

; Enter the filet radius as part of a command line entry f100, O234 for offset, c123.45 for circle, P123 for pline width
; original code and methology by Alan H
; assistance and code that worked by Lee-Mac
; OCT 2015
; Edited by Mhupp Sep 2022


((lambda nil
  (vl-load-com)
  (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
    (if (= "fillet-reactor" (vlr-data obj))
      (vlr-remove obj)
    )
  )
  (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
 )
)

(defun Linex ( / )
(command "line" (getpoint "\nPick 1st point "))
(command (mapcar '+ (getvar 'lastpoint) (list num 0.0 0.0)) "")
(princ)
)

(defun plwid (/ oldwidth)
  (setq oldwidth (getvar 'plinewid))
  (setvar 'plinewid num)
  (vla-sendcommand fillet-reactor-acdoc "_.pline ")
  (setvar 'plinewid oldwidth)
)
(defun filletrad ()
  (setvar 'filletrad num)
  (vla-sendcommand fillet-reactor-acdoc "_.fillet ")
)
(defun makecirc ()
  (setvar 'circlerad num)
  (vla-sendcommand fillet-reactor-acdoc "_.Circle ")
)
(defun offdist ()
  (setvar 'offsetdist num)
  (vla-sendcommand fillet-reactor-acdoc "_.Offset ")
)
(defun fillet-reactor-callback (obj com / num)
  (setq com (car com))
  (cond
  ((and
      (eq (strcase (substr com 1 1)) "X")
      (numberp (setq num (distof (substr com 2))))
      (<= 0.0 num)
     )  ; and
      (LineX)
    )
    ((and
      (eq (strcase (substr com 1 1)) "F")
      (numberp (setq num (distof (substr com 2))))
      (<= 0.0 num)
     )  ; and
      (filletrad)
    )

    ((and
      (eq (strcase (substr com 1 1)) "C")
      (numberp (setq num (distof (substr com 2))))
      (<= 0.0 num)
     )  ;and
      (makecirc)
    )

    ((and
      (eq (strcase (substr com 1 1)) "O")
      (numberp (setq num (distof (substr com 2))))
      (<= 0.0 num)
     )  ; and
      (offdist)
    )
    ((and
      (eq (strcase (substr com 1 1)) "P")
      (numberp (setq num (distof (substr com 2))))
      (<= 0.0 num)
     )  ; and
      (plwid)
    )
  )     ; master cond
)       ; defun

(or fillet-reactor-acdoc 
    (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)

eg C123 draws a Circle with radius 123.