Autolisp - Hide "Open As Read Only" Dialog Box

113 Views Asked by At

I'm trying to open up several drawings at the same time, run code on these drawings (skip if read only), and then close the files. The problem I'm running into is that if I open a file that is write protected, the following dialog box appears and stops the code. Is there a function or command to open files without having this dialog box appearing? An enable/disable capability?

Read Only Dialog Box

The cad application I'm using is DraftSight.

2

There are 2 best solutions below

0
CAD Developer On BEST ANSWER

There is a tricky method. ( thanks @LeeMac)

(setq ans(vl-catch-all-apply 'vl-file-rename (list path path )))

If returns nil it means file is locked.

0
Lee Mac On

An alternative to the suggestion of renaming the file to itself might be to attempt to locate the hidden .dwl file associated with the drawing - indeed, this is the method I use on lines 1098-1124 of my Batch Attribute Editor application:

(if
    (and
        (setq dwl (findfile (strcat (substr file 1 (- (strlen file) 3)) "dwl")))
        (null (vl-file-delete dwl))
    )
    (setq removed
        (cons
            (strcat
                (vl-filename-base file) ".dwg\t"
                (
                    (lambda ( / tmp usr )
                        (if (setq tmp (open dwl "r"))
                            (progn
                                (setq usr (read-line tmp)
                                      tmp (close tmp)
                                )
                                usr
                            )
                            "<Unknown>"
                        )
                    )
                )
            )
            removed
        )
    )
)

Here's a related resource: https://www.theswamp.org/index.php?topic=40868.msg461086#msg461086