Greetings!
For fun I wanted to greet the user when they launched AutoCAD. I added this to the acad.lsp so that it ran at each new AutoCAD session.
For fun I wanted to greet the user when they launched AutoCAD. I added this to the acad.lsp so that it ran at each new AutoCAD session.
;;;-----------------------------------------
;Simply some fun to greet the user when AutoCAD is first launched.
;;;-----------------------------------------
(defun ETP:GetFirstName (/ ETP_name ETP_cmd ETP_sh ETP_ex)
(or (getenv "ETP_FIRSTNAME")
(progn
;(setq ETP_cmd "powershell -NoProfile -Command ""(New-Object System.DirectoryServices.DirectorySearcher('(samAccountName=' + $env:USERNAME +)')).FindOne().Properties.givenname" "")
(setq ETP_cmd (strcat "powershell -NoProfile -Command " "\"(New-Object System.DirectoryServices.DirectorySearcher('(samAccountName=' + $env:USERNAME + ')')).FindOne().Properties.givenname\""))
(setq ETP_sh (vlax-create-object "WScript.Shell"))
(setq ETP_ex (vlax-invoke ETP_sh 'Exec ETP_cmd))
(setq ETP_name (vl-string-trim " \r\n\t" (vlax-invoke (vlax-get ETP_ex 'StdOut) 'ReadAll)))
(vlax-release-object ETP_sh)
(setenv "ETP_FIRSTNAME" ETP_name);; cache for future sessions
;name
)
)
(princ)
)
(ETP:GetFirstName)
;;;-----------------------------------------
;;;-----------------------------------------
(defun ETP_greeting (/ ETP_x ETP_hr ETP_tod)
;; Get current hour (00-23)
(setq ETP_hr (atoi (menucmd "M=$(edtime,$(getvar,date),HH)")))
;; Determine time-of-day greeting
(setq ETP_tod
(cond
((< ETP_hr 12) "Good Morning")
((< ETP_hr 18) "Good Afternoon")
(T "Good Evening")
)
)
;; Build and display message
(setq ETP_x
(strcat "\n" ETP_tod " " (getenv "ETP_FIRSTNAME") ". Have a great day!\n")
)
(princ ETP_x)
(princ)
)
(ETP_greeting)
;;;-----------------------------------------