[VBA] Is the file backed up? If not, is it read-only?

Hello

I would like to know if in VBA in Solidworks I have a way to know if the file is backed up? (Before closing it, and if it is not saved, simply leave it open).

Also I would like to know if we have a way to get if the file is read-only or not? (We use EPDM, so if it's read-only it's because we can't save it anyway so we can close it).

I tried this:

            Dim instance As IDocumentSpecification
            Dim value As Boolean
            Set instance = swApp.GetOpenDocSpec(swModel.GetPathName)
            Dim Stringi As String
            Stringi = instance. ReadOnly

 

But the Debug always tells me false, even if the file is read-only.

Hello

For read-only, see my macro that I posted here:

http://www.lynkoa.com/tutos/3d/macro-solidworks-retirer-lecture-seule-pour-fichiers-de-bibliotheque

Or here:

http://www.lynkoa.com/sites/default/files/questions/answer/09/09/2014/bibliotheque_lecture_seule.swp

 

Edit: to find out if the document has been saved, I use the GetPathName method , if the variable is empty, it means that it has not been saved yet.

Example:

Set swApp = Application.SldWorks
Set CurrentDOC = swApp.ActiveDoc
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
    docPath = CurrentDOC.GetPathName
If docPath = "" Then
    MsgBox ("this document has not yet been saved")
End if

1 Like

Thank you for your answer!

 

Regarding read-only, your code is perfect.

For the backup I thought about it (I need to do it before the read-only check so I don't have any problems on the way), but this doesn't tell me if the document is "saved", well that there is no longer the little star at the top next to the name on SW:p

After thinking about it, I think that knowing if the file is read-only is enough for me.

 

But if anyone has the solution, don't hesitate! It could well be useful for another time or for someone else:)

1 Like

For the second question, you can ask another question like this one is closed and for more readability, I might have a solution ;-)

Very well, on the other hand I will take care of it on Friday (I am absent tomorrow and the day after tomorrow) and now I will leave.

1 Like