Author Topic: Change to Read Only after Opening Files  (Read 5506 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Change to Read Only after Opening Files
« on: March 26, 2018, 05:56:13 PM »
So, we are syncing two servers together, unfortunately, we have learned that syncing with data locks is all but impossible and the couple of solutions that claim to do it are very cost prohibitive. So I am writing a LISP routine that can check the remote server for the .dwl file, that is simple enough since they are connected with a VPN. The question is if there is a way to make the file read only if it is open on the other server? Obviously for the LISP routine to run, the file has to be open already, so it is a matter of changing it to be considered read only.

ChrisCarlson

  • Guest
Re: Change to Read Only after Opening Files
« Reply #1 on: April 06, 2018, 04:18:44 PM »
The .dwl/.dwl2 file simply tells AutoCAD at the .dwg version is in-use. Could you just filter your syncing software to exclude .dwl/.dwl2 extensions?

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Change to Read Only after Opening Files
« Reply #2 on: April 06, 2018, 04:33:14 PM »
No, that's the point, I want to scan the other server and see if the file is in use on the other server. That part is easy, but what I also want is if the file is in use on the other server, then I want it to open read only and the server that is trying to open the file.

Unfortunately the .dwl files do not sync because they are technically open files themselves.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Change to Read Only after Opening Files
« Reply #3 on: April 06, 2018, 05:27:49 PM »
Can't natively change it to read-only or locked-for-open.

You could check for a custom DWL3/etc. file on open; if present and/or indicating someone has it open, open read-only and close the current file with no save.  If not present, then create the file.  On file close, delete the file or modify the contents.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Change to Read Only after Opening Files
« Reply #4 on: April 06, 2018, 05:39:54 PM »
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:

Code: [Select]
(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?")
                        )
                    )
                )
            )
        )
    )
)

Dlanor

  • Bull Frog
  • Posts: 263
Re: Change to Read Only after Opening Files
« Reply #5 on: April 07, 2018, 03:25:35 PM »
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.

Maybe https://www.theswamp.org/index.php?topic=1876.0

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Change to Read Only after Opening Files
« Reply #6 on: April 09, 2018, 11:44:49 AM »
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.

Maybe https://www.theswamp.org/index.php?topic=1876.0
Except that appears to use VBA and we don't install VBA as we have found it to cause stability and performance issues.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Change to Read Only after Opening Files
« Reply #7 on: April 09, 2018, 12:11:55 PM »
I may be missing (haven't read the thread) something but if you wish to open a dwg read-only:

(vla-open (vla-get-documents (vlax-get-acad-object)) drawing_path :vlax-true)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Change to Read Only after Opening Files
« Reply #8 on: April 09, 2018, 12:23:05 PM »
I may be missing (haven't read the thread) something but if you wish to open a dwg read-only:

(vla-open (vla-get-documents (vlax-get-acad-object)) drawing_path :vlax-true)

That is what I am currently using, but it doesn't work form a startup routine.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Change to Read Only after Opening Files
« Reply #9 on: April 09, 2018, 12:40:26 PM »
Oops | sorry for the distraction | odd.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Change to Read Only after Opening Files
« Reply #10 on: April 09, 2018, 01:18:55 PM »
I may be missing (haven't read the thread) something but if you wish to open a dwg read-only:

(vla-open (vla-get-documents (vlax-get-acad-object)) drawing_path :vlax-true)

That is what I am currently using, but it doesn't work form a startup routine.

I'm doing something like that from within the ACADDOC.LSP (albeit a couple of nested function calls down); ours calls a dialog which provides the option to open/close/open-read-only and a few other unrelated options.  The open-read-only opens the file first using the read-only syntax, then closes the active document.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Change to Read Only after Opening Files
« Reply #11 on: April 09, 2018, 03:00:22 PM »
I may be missing (haven't read the thread) something but if you wish to open a dwg read-only:

(vla-open (vla-get-documents (vlax-get-acad-object)) drawing_path :vlax-true)

That is what I am currently using, but it doesn't work form a startup routine.

I'm doing something like that from within the ACADDOC.LSP (albeit a couple of nested function calls down); ours calls a dialog which provides the option to open/close/open-read-only and a few other unrelated options.  The open-read-only opens the file first using the read-only syntax, then closes the active document.

That is actually exactly what I want to do in these circumstances, any chance you could share your code? I am thinking that I am somehow just missing something.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Change to Read Only after Opening Files
« Reply #12 on: April 10, 2018, 11:17:42 AM »
Quote from: cmwade77
So, we are syncing two servers together, unfortunately, we have learned that syncing with data locks is all but impossible and the couple of solutions that claim to do it are very cost prohibitive. So I am writing a LISP routine that can check the remote server for the .dwl file, that is simple enough since they are connected with a VPN. The question is if there is a way to make the file read only if it is open on the other server? Obviously for the LISP routine to run, the file has to be open already, so it is a matter of changing it to be considered read only.

Checking for the existence of .dwl and .dwl2 files is flawed. Those can exist when the file is not open, for example if AutoCAD crashes.

Have you looked at using Peer?  Compare the cost of it to what the costs are if your users are stomping on each others work.


cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Change to Read Only after Opening Files
« Reply #13 on: April 10, 2018, 11:52:50 AM »
Quote from: cmwade77
So, we are syncing two servers together, unfortunately, we have learned that syncing with data locks is all but impossible and the couple of solutions that claim to do it are very cost prohibitive. So I am writing a LISP routine that can check the remote server for the .dwl file, that is simple enough since they are connected with a VPN. The question is if there is a way to make the file read only if it is open on the other server? Obviously for the LISP routine to run, the file has to be open already, so it is a matter of changing it to be considered read only.

Checking for the existence of .dwl and .dwl2 files is flawed. Those can exist when the file is not open, for example if AutoCAD crashes.

Have you looked at using Peer?  Compare the cost of it to what the costs are if your users are stomping on each others work.

I have been looking at tons of options, what is Peer? And I actually have some error handling built-in to account for the existence of .dwl files when the files are indeed not open.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Change to Read Only after Opening Files
« Reply #14 on: April 10, 2018, 11:58:57 AM »
Sorry, I meant to include a link.
Try this: https://www.peersoftware.com/peersync/