"Read-only" macro

Hi all

I would need a macro that automatically makes SW files read-only.

I'm already using the @.PL macro from SolidWorks below

http://www.lynkoa.com/forum/solidworks/macro-mettre-fichier-lecture-seule

but I would need a simpler macro that doesn't ask me to confirm (I want to be able to integrate it with the INTEGRATION utility).

Thank you in advance.

 

1 Like

Hello

To remove the validation request, comment (apostrophe at the beginning of the line) the following lines (in bold underline):

Edit: Edit the lines in bold as said before:

If GetAttr(PathName) And vbReadOnly Then
If the file is read-only
        ret = MsgBox("This file is read-only, do you want to write to it?" & vbNewLine_
        & vbNewLine & "Remember to save your changes later", vbYesNo, title)

        'message to ask if we want to access it in read and write
        If ret = vbNo Then Exit Sub
        'If not, we leave the programme
        SetAttr PathName, vbNormal
        'If so, we remove the read-only in Windows
        Part.FileReload
        ret = Part.ReloadOrReplace(False, Part.GetPathName, True)
        Part.FileReload
        'We reload the document in SolidWorks
Else
'Otherwise (= file read, write)
        ret = MsgBox("This file is read-write, do you want to make it read-only?", vbYesNo, title)
        'Message to ask if you want to access it in read-only mode
        If ret = vbNo Then Exit Sub
        'If not, we leave the programme
        SetAttr PathName, vbReadOnly
        'If so, we put read-only in Windows
        Part.FileReload
        ret = Part.ReloadOrReplace(False, Part.GetPathName, True)
        Part.FileReload
        'We reload the document in SolidWorks
End If
End Sub

3 Likes

Edit: message to be deleted, I was on something else

Re: Modified as before, the macro writes read-only files and read-only writes to write files.

To have only the write, modify the end of your macro with this one:

If GetAttr(PathName) And vbReadOnly Then
If the file is read-only
        'ret = MsgBox("This file is read-only, do you want to write to it?" & vbNewLine_
        & vbNewLine & "Remember to save your changes later", vbYesNo, title)

        'message to ask if we want to access it in read and write
        'If ret = vbNo Then Exit Sub
        'If not, we leave the programme
        SetAttr PathName, vbNormal
        'If so, we remove the read-only in Windows
        Part.FileReload
        ret = Part.ReloadOrReplace(False, Part.GetPathName, True)
        Part.FileReload
        'We reload the document in SolidWorks
Else
End If
End Sub

1 Like