Yeah, that was the approach that I have come to as well, but now the trick seems to be in opening the file read only.
Unfortunately what I have so far works if I manually load it after opening the file, but if I try to have AutoCAD automatically run it by putting it in our startup routine, it fails open the file read only, here is what I have so far:
(defun OpenDwgFile (arg1 / )
(vl-load-com)
(vla-open (vla-get-documents (vlax-get-acad-object)) arg1 :vlax-true)
); defun
;----------------------------------------------------------------------------------------------------------
; MyYesNo - Question dialog with one question line
; Arguments: 2
; Title$ = Dialog Title
; Question$ = Question line
; Syntax: (MyYesNo " My Yes No" "Do you like creating programs in AutoLISP?")
;----------------------------------------------------------------------------------------------------------
(defun MyYesNo (Title$ Question$ / Answer$ Dcl_Id% Return#)
(princ "\nMyYesNo")(princ)
; Load Dialog
(setq Dcl_Id% (load_dialog "MyYesNo.dcl"))
(new_dialog "MyYesNo" Dcl_Id%)
; Set Dialog Initial Settings
(set_tile "Title" Title$)
(set_tile "Text1" Question$)
; Dialog Actions
(action_tile "Yes" "(done_dialog 1)")
(action_tile "No" "(done_dialog 0)")
(setq Return# (start_dialog))
; Unload Dialog
(unload_dialog Dcl_Id%)
(if (= Return# 1)
(setq Answer$ "Yes")
(setq Answer$ "No")
);if
;(princ "\n")(princ Answer$)(princ);Optional
;Answer$
(if (= Answer$ "No")
(command "._close")
(progn
(if (= dwgPath nil)
(setq dwgPath (strcat (getvar "dwgprefix") (getvar "dwgname")))
(if (= dwgPath "")
(setq dwgPath (strcat (getvar "dwgprefix") (getvar "dwgname")))
)
)
(openDWGFile dwgPath)
(alert "Please do not save this file, if you need to save changes, please use Save As")
(setvar "filedia" 0)
(command "._close" "n")
(setvar "filedia" 1)
)
)
);defun MyYesNo
(setq dwgPath (strcat (getvar "dwgprefix") (getvar "dwgname"))
dwgChk1 (vl-string-subst ".dwl" ".dwg" dwgpath)
dwgChk2 (vl-string-subst "Z:" "H:" dwgChk1)
fndFile (findfile dwgChk2)
)
(if (/= fndFile nil)
(progn
(if (/= (vl-file-delete fndFile) T)
(progn
(if (= (strcase (substr fndFile 1 3)) (strcase "z:\\"))
(progn
(setq f (open dwgChk2 "r"))
(if (/= f nil)
(progn
(setq txt (read-line f)
sv (read-line f)
)
)
(close f)
)
(if (/= txt nil)
(progn
(if (/= sv nil)
(MyYesNo " My Yes No" (strcat "File is open by " txt " on computer " sv ", do you wish to open this file read only?"))
(MyYesNo " My Yes No" (strcat "File is open by " txt ", do you wish to open this file read only?"))
)
)
(MyYesNo " My Yes No" "File is open, do you wish to open this file read only?")
)
)
)
)
)
)
)