- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, All,
I would like to mimic the .dwl and .dwl2 functionality of AutoCAD for the purpose of correcting an issue created by hosting our shared work files on SharePoint/OneDrive. I am not looking for suggestions on other places to save our files. The issue is that .dwl and .dwl2 files are constantly "in-use" from the moment they're created, and so OneDrive does not sync them to the cloud, and therefore other users are allowed to open the same drawing files without being prompted to open them read-only because AutoCAD does not detect that the file is in use. To remedy this, my goal is to create a lisp routine that is loaded for each drawing via acaddoc.lsp that creates a temporary .dwl3 file when a drawing is opened and deletes it when the file is closed. Because it will be a static file, it will get synced, and I can include in my code a check for the existence of this file when opening drawings, and warn users if someone else may have it open.
I still have a lot of improvements to make, but below is my very basic attempt at getting started, which is doing everything it's supposed to do other than deleting the .dwl3 file on close. I am getting a "no function definition: ADD-REACTOR" error, which is likely the culprit, but I'm a bit clueless on how to fix it. Calling the deletedwl3file function directly does in fact delete the text file successfully, so I'm just left trying to figure out how to get CLOSE and QUIT to trigger it. Also need to account for if CLOSE or QUIT is cancelled, but maybe that's a problem for the future.
Any help would be appreciated!
(defun c:writedwl3file (/ user txt des)
(setq user (getvar "loginname"))
(setq txt (strcat (getvar "Dwgprefix") (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".dwl3")) ; Excluded the extension from dwgname
(if (findfile txt)
(alert "Warning: This file may be in use by another user. Please open the .dwl3 file in Notepad for more information.")
)
(if (setq des (open txt "w"))
(progn
(write-line (strcat "This MSA file lock was created by " user ".") des)
(close des)
)
(princ "\nUnable to create text file.")
)
)
(c:writedwl3file) ; This line ensures writedwl3file is executed upon loading dwl3.lsp
;;-----------------------------------------------------------
(defun c:deletedwl3file ()
(setq txt (strcat (getvar "Dwgprefix")(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".dwl3")) ; Excluded the extension from dwgname
(if (findfile txt)
(vl-file-delete txt)
)
(princ)
)
;;-----------------------------------------------------------
(defun reactor_close_drawing (event)
(c:deletedwl3file)
)
(vl-load-com)
(add-reactor 'Dwg_Close reactor_close_drawing)
Solved! Go to Solution.