Macro to find all files created in a given version
Macro to find all files created in a given version
I've been searching around for a while to find a macro that can crawl in a folder (and its sub folders) and find all Solidworks files created in a given version (2023).
Do you any know any macro that can do the job?
Thanks.
Do you any know any macro that can do the job?
Thanks.
- Stefan Sterk
- Posts: 37
- Joined: Tue Aug 10, 2021 2:40 am
- x 51
- x 77
Re: Macro to find all files created in a given version
Hi Tera, Have a look at https://www.codestack.net/solidworks-api/document/versions-report/
@artem code used the solidworks application to get the version history. Which limits the speed.
A faster way is to get the file atribute 'Last Saved With SW' itself, see example code below
@artem code used the solidworks application to get the version history. Which limits the speed.
A faster way is to get the file atribute 'Last Saved With SW' itself, see example code below
Code: Select all
Sub main()
Debug.Print GetLastSavedWithSW("E:\Path\To\File\FileName.SLDPRT")
End Sub
Function GetLastSavedWithSW(sFullPathName As String) As String
Dim objShell As Object
Dim objFolder As Object
Dim objFolderItem As Object
Dim sFolderPath As Variant 'Needs to be variant for .NameSpace
Dim sFileName As String
sFolderPath = Left(sFullPathName, InStrRev(sFullPathName, "\") - 1)
sFileName = Right(sFullPathName, Len(sFullPathName) - InStrRev(sFullPathName, "\"))
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(sFolderPath)
If objFolder Is Nothing Then Exit Function
Set objFolderItem = objFolder.ParseName(sFileName)
GetLastSavedWithSW = objFolder.GetDetailsOf(objFolderItem, 336)
Set objFolderItem = Nothing
Set objFolder = Nothing
Set objShell = Nothing
End Function
Re: Macro to find all files created in a given version
I haven't reviewed @artem code yet, but your code returns null values.Stefan Sterk wrote: ↑Thu Jan 11, 2024 4:59 am Hi Tera, Have a look at https://www.codestack.net/solidworks-api/document/versions-report/
@artem code used the solidworks application to get the version history. Which limits the speed.
A faster way is to get the file atribute 'Last Saved With SW' itself, see example code below
What does 336 stands for?
Thanks.
Re: Macro to find all files created in a given version
I believe that is the number on which "SW last saved with" comes in the list. But I do not think it is still exposed to VBA.
You can use @artem code as that would work OK for previous version (when SW last saved with was not exposed) and also for the batch processing of the files.
For active file, you can try the following codes (used the ConvertFileVersionToSwMajorVersion function from @artem code)
Code: Select all
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim vVerStr As Variant
Dim swVersion As Integer
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
vVerStr = swApp.VersionHistory(Part.GetPathName)
swVersion = Left(vVerStr(UBound(vVerStr)), InStr(vVerStr(UBound(vVerStr)), "[") - 1)
MsgBox ConvertFileVersionToSwMajorVersion(swVersion)
End Sub
Function ConvertFileVersionToSwMajorVersion(versNumber As Integer) As String
Dim swVersMajor As String
If versNumber >= 5000 Then
swVersMajor = 2012 + (versNumber - 5000) / 1000
Else
Select Case versNumber
Case 44
swVersMajor = 95
Case 243
swVersMajor = 96
Case 483
swVersMajor = 97
Case 629
swVersMajor = "97Plus"
Case 822
swVersMajor = 98
Case 1008
swVersMajor = "98Plus"
Case 1137
swVersMajor = 99
Case 1500
swVersMajor = 2000
Case 1750
swVersMajor = 2001
Case 1950
swVersMajor = "2001Plus"
Case 2200
swVersMajor = 2003
Case 2500
swVersMajor = 2004
Case 2800
swVersMajor = 2005
Case 3100
swVersMajor = 2006
Case 3400
swVersMajor = 2007
Case 3800
swVersMajor = 2008
Case 4100
swVersMajor = 2009
Case 4400
swVersMajor = 2010
Case 4700
swVersMajor = 2011
End Select
End If
ConvertFileVersionToSwMajorVersion = "Last major version is: SOLIDWORKS " & swVersMajor
End Function
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
- Stefan Sterk
- Posts: 37
- Joined: Tue Aug 10, 2021 2:40 am
- x 51
- x 77
Re: Macro to find all files created in a given version
336 is the index for 'Last Saved With SW' extended file attribute/detail. A value that can be shown in the file explorer. See image below. This is working for me
Re: Macro to find all files created in a given version
I'm trying to check for future version.
I'm on 2022 SP5. Downloaded and used 2023 SP1 for a while . After a while our company decided to end its subscription.
I want to see how many files we have on version 2023.
If the amount of files are high, or sensitive assemblies are saved with 2023, we will extend our subscription for another year. If not, then we will end it now.
We have been on subscription since I think 2009, so some of us downloaded the latest version as ever. But it turned out the management has something else in mind.
thanks.
Re: Macro to find all files created in a given version
@artem macro will create a CSV file and list out details for all the files in the desired folder.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
- Stefan Sterk
- Posts: 37
- Joined: Tue Aug 10, 2021 2:40 am
- x 51
- x 77
Re: Macro to find all files created in a given version
As gupta said, the code of artem will fit your need, straid out of the box.
Got some other info. The index for 'Last Saved With SW' doens't seems to be contant. On my Windows 11 system is is set on 330 instead of 336 (Windows 10). Not sure if it is Windows related or user setting.
Got some other info. The index for 'Last Saved With SW' doens't seems to be contant. On my Windows 11 system is is set on 330 instead of 336 (Windows 10). Not sure if it is Windows related or user setting.
Re: Macro to find all files created in a given version
For me on WIn 10, the 336 number is the width of the column for 'Last Saved With SW' . Change the width of the column and you can see the number changes again.Stefan Sterk wrote: ↑Sat Jan 13, 2024 12:42 pm As gupta said, the code of artem will fit your need, straid out of the box.
Got some other info. The index for 'Last Saved With SW' doesn't seems to be constant. On my Windows 11 system is is set on 330 instead of 336 (Windows 10). Not sure if it is Windows related or user setting.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Macro to find all files created in a given version
iirc the version number is calculated as the sum of major and minor (SP) version of solidworks. codestack macro should have the calculation explained somewhere.