(alert (strcat "Messenger.lsp - AutoCAD Messenger" "\nPlease read the Installation Notes and customize" "\nthe Required Global Variables to run the program.")) (exit) ; Comment out the lines above after reading the Installation Notes. ;------------------------------------------------------------------------------- ; Program Name: Messenger.lsp [AutoCAD Messenger R4] ; c:AM for Shortcut ; Created By: Terry Miller (Email: terrycadd@yahoo.com) ; (URL: http://web2.airmail.net/terrycad) ; Date Created: 1-20-04 ; Function: AutoCAD Messenger uses the Windows Messenger Service to send and ; receive messages between AutoCAD users on a network or server. ; Note: Messenger requires a few installation steps, such as customizing ; the global variables *Shared_Folder$, *Login_Exceptions@, and ; *Login_Displayname@. The purpose of the *Shared_Folder$ is to ; create a list of Recipients based upon which AutoCAD users have ; logged in for the day. *Login_Exceptions@ are users to exclude ; from the Recipients list for various reasons. *Login_Displayname@ ; is used to customize the display name for each user login name. ;------------------------------------------------------------------------------- ; Revision History ; Rev By Date Description ;------------------------------------------------------------------------------- ; 1 TM 1-20-04 Initial version ; 2 TM 3-20-06 Included global variables to make it easier to customize. ; 3 TM 1-10-07 Revised to use the standard SHELL command and removed all ; calls to the GetIcon and Dcl_Tiles functions. ; 4 TM 11-30-07 Added runapp function for DOS applications. ;------------------------------------------------------------------------------- ; Installation Notes: ; System Requirements ; AutoCAD users are on a network or server loading the same AcadDoc.lsp file. ; AutoCAD users can configure their Windows Messenger to start automatically. ; Installation Steps per each computer ; 1. Start the Windows Messenger. From the Windows [Start] menu, select [Settings], ; select [Control Panel], select [Administrative Tools], select [Services], then ; select [Messenger]. Pick [Automatic] for the Startup type, then select [Start]. ; 2. Add Windows Messenger to the Windows Firewall Exceptions. From the Windows [Start] ; menu, select [Settings], select [Control Panel], then select [Windows Firewall]. ; From the [Exceptions] tab select [Add Program], scroll down to the bottom and ; select [Windows Messenger], then select [OK], then [OK]. ; * Skip to number 7, after successfully testing on one computer. ; Installation Steps continued... ; 3. Customize the Required Global Variables below to run the program. ; 4. Comment out the top lines in this file from "alert" to "exit". ; 5. Copy this file to the network or server folder where AcadDoc.lsp is located. ; 6. Edit the AcadDoc.lsp file and include the line (load "Messenger"). ; 7. On the AutoCAD command line type AM to run the AutoCAD Messenger. The [To:] ; list of Recipients will show which AutoCAD users have logged in that day. ; Note: This program may not work on all network or server environments and you may need ; to consult with the IT Administrator to adjust some settings. Save your drawings first ; if you encounter any problems sending messages to certain users. Do not send messages ; to users that have logged off for the day. If you do, your computer will attempt to ; send for about 2 minutes. If this happens wait a few minutes for it to time out. ;------------------------------------------------------------------------------- ; Setq these Required Global Variables to run the program. Edit as needed to customize. ;------------------------------------------------------------------------------- ; *Shared_Folder$ - The network folder that all AutoCAD users can share. (setq *Shared_Folder$ "K:\\AutoCAD\\AutoLISP\\");<-- Edit as required. ; *Login_Exceptions@ - List of uppercase login names or computer names to exclude as recipients. (setq *Login_Exceptions@ (list "USER" "WXYLO"));<-- Edit as required. ; *Login_Displayname@ - Association list of uppercase login names and display names ; to change the way their names are displayed. (setq *Login_Displayname@ (list (cons "JDOE" "John Doe");Leave at least one of these in to complete the global list (cons "VFUENTES" "Victor");<-- Edit as required. Use uppercase login names. );list );setq ;------------------------------------------------------------------------------- ; Messenger - AutoCAD Messenger ;------------------------------------------------------------------------------- (defun c:AM ( );Shortcut (if (and (not (member (strcase (getvar "LOGINNAME")) *Login_Exceptions@)) (not (member (strcase (getenv "COMPUTERNAME")) *Login_Exceptions@))) (Messenger) );if (princ) );defun c:AM ;------------------------------------------------------------------------------- (defun Messenger (/ AcadUser$ AcadUsers@ ComputerName$ ComputerNames@ DateLine$ Dcl_Id% DosCommand$ FileName% List001@ List1@ List2@ LoginName$ LoginNames@ Message$ Return# Var001$ Var002$ Verify_Info:) (princ "\nAutoCAD Messenger")(princ) (setvar "CMDECHO" 0) ;----------------------------------------------------------------------------- ; Verify_Info: - Verifies Infomation ;----------------------------------------------------------------------------- (defun Verify_Info: (/ Passed) (setq Passed t) (cond ((and (= Var001$ "Choose Recipient")(= Var002$ "")) (alert "Choose a Recipient and enter a message to send!") (setq Passed nil) );case ((= Var001$ "Choose Recipient") (alert "Choose a Recipient to send message to!") (setq Passed nil) );case ((= Var002$ "") (alert "Enter a message to send to Recipient!") (setq Passed nil) );case );cond (if Passed (done_dialog 1) );if );defun Verify_Info: ;----------------------------------------------------------------------------- ; Set Default Variables and List Values ;----------------------------------------------------------------------------- (setq AcadUsers@ (vl-directory-files *Shared_Folder$ "*.a~m" 1)) (foreach AcadUser$ AcadUsers@ (setq FileName% (open (strcat *Shared_Folder$ AcadUser$) "r")) (setq LoginName$ (Login_Displayname (read-line FileName%))) (setq ComputerName$ (read-line FileName%)) (setq DateLine$ (read-line FileName%)) (close FileName%) (if (= DateLine$ (rtos (getvar "CDATE") 2 0));Include AcadUser$ if logged in today (progn (setq List1@ (append List1@ (list LoginName$))) (setq List2@ (append List2@ (list ComputerName$))) );progn );if );foreach (setq LoginNames@ (Acad_StrlSort List1@)) (foreach LoginName$ LoginNames@ (setq ComputerName$ (FindInlist LoginName$ List1@ List2@)) (setq ComputerNames@ (append ComputerNames@ (list ComputerName$))) );foreach (setq LoginNames@ (cons "Choose Recipient" LoginNames@)) (setq ComputerNames@ (cons "Choose Recipient" ComputerNames@)) (if *Recipient* (if (member *Recipient* LoginNames@) (setq Var001$ *Recipient*) (setq Var001$ "Choose Recipient") );if (setq Var001$ "Choose Recipient") );if (setq LoginName$ (Login_Displayname (getvar "LOGINNAME"))) (setq List001@ LoginNames@) (setq Var002$ "") ;----------------------------------------------------------------------------- ; Load Dialog ;----------------------------------------------------------------------------- (setq Dcl_Id% (load_dialog "Messenger.dcl")) (new_dialog "Messenger" Dcl_Id%) ;--------------------------------------------------------------------------- ; Set Dialog Initial Settings ;--------------------------------------------------------------------------- (set_tile "Title" " AutoCAD Messenger") (set_tile_list "List001" List001@ Var001$) (set_tile "Edit002" Var002$) ;--------------------------------------------------------------------------- ; Dialog Actions ;--------------------------------------------------------------------------- (action_tile "List001" "(set_list_value \"List001@\" \"Var001$\")") (action_tile "Edit002" "(setq Var002$ $value)") (action_tile "Send" "(Verify_Info:)") (setq Return# (start_dialog)) (unload_dialog Dcl_Id%) (setq *Recipient* Var001$) (if (= Return# 0)(exit)) (setq Message$ (strcat Var002$ " [" LoginName$ "]")) (setq ComputerName$ (FindInList *Recipient* LoginNames@ ComputerNames@)) (setq DosCommand$ (strcat "Net Send " ComputerName$ " \"" Message$ "\"")) (runapp DosCommand$ nil) (princ) );defun Messenger ;------------------------------------------------------------------------------- ; Start of Messenger Support Utility Functions ;------------------------------------------------------------------------------- ; FindInList - Finds the associated Item from two lists ; Arguments: 3 ; Item = Item to find ; SearchList@ = List to search in ; InList@ = List used to return the nth where Item was found in SearchList@ ; Returns: The associated Item in InList@ ;------------------------------------------------------------------------------- (defun FindInList (Item SearchList@ InList@) (nth (- (length SearchList@) (length (member Item SearchList@))) InList@) );defun FindInList ;------------------------------------------------------------------------------- ; Login_Displayname - Converts the login name to the displayed name in *Login_Displayname@ ;------------------------------------------------------------------------------- (defun Login_Displayname (Name$) (setq Name$ (strcase Name$)) (if (assoc Name$ *Login_Displayname@) (cdr (assoc Name$ *Login_Displayname@)) Name$ );if );defun Login_Displayname ;------------------------------------------------------------------------------- ; set_list_value - Sets SentVar$ to the item selected in SentList$ ; Arguments: 2 ; SentList$ = String of the list variable name ; SentVar$ = String of the variable name ; Syntax: (set_list_value "ListName" "Variable") ;------------------------------------------------------------------------------- (defun set_list_value (SentList$ SentVar$ / SaveVar$ SubList@) (setq SubList@ (eval (read SentList$))) (setq SaveVar$ (eval (read SentVar$))) (set (read SentVar$) (nth (atoi $value) SubList@)) (if (= (eval (read SentVar$)) "") (progn (set (read SentVar$) SaveVar$) (set_tile_list $key SubList@ SaveVar$) );progn );if (princ) );defun set_list_value ;------------------------------------------------------------------------------- ; set_tile_list - Sets a dialog popup_list or list_box tile to a list ; Arguments: 3 ; KeyName$ = Key name of tile ; ListName@ = The list to set in tile ; Selected = An item in the ListNames@ or a list of items selected ; Syntax: (set_tile_list "TileName" '("A" "B" "C") "B") ; (set_tile_list "TileName" '("A" "B" "C") '("A" "C")) ; Returns: Sets Selected items in dialog popup_list or list_box tiles. ;------------------------------------------------------------------------------- (defun set_tile_list (KeyName$ ListName@ Selected / Item) (start_list KeyName$ 3) (mapcar 'add_list ListName@) (end_list) (foreach Item (if (listp Selected) Selected (list Selected)) (if (member Item ListName@) (set_tile KeyName$ (itoa (- (length ListName@) (length (member Item ListName@))))) );if );foreach );defun set_tile_list ;------------------------------------------------------------------------------- ; runapp - Runs a DOS application with parameters ; Arguments: 2 ; Commands$ = String of DOS application with parameters ; Visible = t for visible else nil ; Syntax example: (runapp "Notepad.exe \"C:\\Temp\\Temp.txt\"" t) ; Returns: Runs a DOS application and waits for it to finish. ;------------------------------------------------------------------------------- (defun runapp (Commands$ Visible / WScript) (if (setq WScript (vlax-get-or-create-object "WScript.Shell")) (if Visible (vl-catch-all-apply 'vlax-invoke-method (list WScript "Run" Commands$ 1 :vlax-true)) (vl-catch-all-apply 'vlax-invoke-method (list WScript "Run" Commands$ 6 :vlax-true)) );if );if (princ) );defun runapp ;------------------------------------------------------------------------------- ; Messenger_Login - Logs in the AutoCAD users that will be using the program ;------------------------------------------------------------------------------- (defun Messenger_Login (/ Filename%) (if (and (not (member (strcase (getvar "LOGINNAME")) *Login_Exceptions@)) (not (member (strcase (getenv "COMPUTERNAME")) *Login_Exceptions@))) (progn (setq Filename% (open (strcat *Shared_Folder$ (getenv "COMPUTERNAME") ".a~m") "w")) (write-line (strcase (getvar "LOGINNAME")) Filename%) (write-line (strcase (getenv "COMPUTERNAME")) Filename%) (write-line (rtos (getvar "CDATE") 2 0) Filename%) (close Filename%) );progn );if );defun Messenger_Login ;------------------------------------------------------------------------------- (Messenger_Login);Run the Messenger_Login function when loading Messenger.lsp ;------------------------------------------------------------------------------- (princ)