Accurate way to get a SolidWorks Version Check on Files

Hi,

I'm wondering if anyone knows an accurate method of getting the version of a solidworks file that it was created with. Not sure if that makes sense. lol. Basically i'm in a possition where ihave a number of backups created over a long period of time. Just created incrementley ignoring versions of files (some are not modified with newer versions of SW while others may have been). BUt basically i'd like to be able to tell what the majority of files are last saved with so that i can save them as a version specific backup.

I hope this makes sense. And i hope it can be done (but i fear not : ().

Cheers, DWH

Reply to
Anonymous
Loading thread data ...

it would be fairly simple to build a macro for this, based on API SldWorks::VersionHistory

Reply to
Philippe Guglielmetti

This example shows how to get the version history of a SolidWorks document.

'------------------------------------------------

'

' Preconditions: A SolidWorks document is open.

'

' Postconditions: None

'

'------------------------------------------------

Option Explicit

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim vVerStr As Variant

Dim i As Long

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Debug.Print "File = " & swModel.GetPathName

If IsEmpty(vVerStr) Then

vVerStr = swApp.VersionHistory(swModel.GetPathName)

End If

If Not IsEmpty(vVerStr) Then

For i = 0 To UBound(vVerStr)

Debug.Print " " & vVerStr(i)

Next i

Else

Debug.Print " No version information."

End If

End Sub

'------------------------------------------------

Easy to add some lines to read for example the whole folder...

regards Markku

Reply to
Markku Lehtola

Reply to
basu

Markku,

Just thought I'd ask,,,,

If the preconditions are that the file be open, don't you already know the answer ???

Mark

Reply to
MM

basu,

No thats luckily not the case for me. :) Its simply for an incrementle backup type situation. I'd like to go back now, through all the backups i've created and actually make a specific version backup each time i've upgraded SolidWorks.

Regards, HoffY

Reply to
Anonymous

Philippe,

Thanks for your response. i'm not really up to speed with API (50hr days anyone? :)). Be thankful if anyone could lend some of their valuable time if its not to difficult.

Regards, HoffY

Reply to
Anonymous

Markku,

Thank you for that! I must admit i'm no good at comlex API/Macro stuff. I'd really love to be able to pass a directory (and its sub dirs) and possibly get a read out of what version a file is currently at into an excel style layout. or even a text document would be fine.

If anyone could share their skills and time to create something like this and possibly tweak it. Would be muchly appreciated. I'm sure i'm not the only one that would like ot be able to find out file versions of prts/asms/dwgs with the running of a macro or utility. Expanded features like Created With Version, Last Saved Version could be a couple i'd find really handy just off the top of my head.

Kind Regards, HoffY

Reply to
Anonymous

No, you don't know. The previous code will list all versions of SW that ever modified the document. LIkewise, if you look at the feature properties there will be record of all users that ever modified the file.

In fact, SW contains within itself the ability to create the model according to the older versions used in it until that older geometry is edited and replaced.

Reply to
TOP

Here's one way to handle all parts in one folder:

Sub main()

Dim swApp As SldWorks.SldWorks Dim swPart As ModelDoc2

Dim sPath As String Dim sFileSW As String Dim sFileTitle As String Dim sMsg As String Dim retval As Boolean Dim config As Variant Dim i As Variant

Const swDocPart = 1 Const swCustomInfoText = 30 Const swSaveAsOptions_Silent = &H1 Const swGenericSaveError = &H1 Const swFileSaveWarning_RebuildError = &H1

sMsg = "Working folder with \ at the end" sPath = InputBox(sMsg, "Folder", "C:\Temp\") If sPath = "" Then Exit Sub

Set swApp = CreateObject("SldWorks.Application")

sFileSW = Dir(sPath & "*.sldprt")

Do While sFileSW "" 'open model Set swPart = swApp.OpenDoc(sPath & sFileSW, swDocPart)

'Do something for the models '-----------------------

'read all configurations from the model config = swPart.GetConfigurationNames For i = 0 To UBound(config)

'replace the attribute value 'first remove the old one retval = swPart.DeleteCustomInfo2(config(i), "test")

'then add a new one 'retval = swPart.AddCustomInfo3(config(i), "test", swCustomInfoText, "Attr_value")

'handle next configuration Next i

'------------------------

'save

retval = swPart.Save3(swSaveAsOptions_Silent, swGenericSaveError, swFileSaveWarning_RebuildError)

'close saved part sFileTitle = swPart.GetTitle swApp.CloseDoc sFileTitle

'next file sFileSW = Dir Loop

'finished swApp.SendMsgToUser "Done..."

End Sub

It should be quite easy to combine this with the example code from the API help...

Reply to
Markku Lehtola

Markku

Gosh all that code just goes right over my head. Unfort. i can understand sections but to put it all together to make it actaully do something is beyond me at this point.

How would i run that code? I tried a .swp file but it just returns "cant open file". :(

-HoffY

Reply to
Anonymous

You start a new macro in SW and paste it in. Before you run it you go to the tools menu and make sure the SW type library and constants library are checked.

Reply to
TOP

sections but to put it all

I can try to build something more usefull during the weekend...

Reply to
Markku Lehtola

sections but to put it all

open file". :(

Tried to make it as simple as possible..:

formatting link
Markku

Reply to
Markku Lehtola

Markku,

That is awesome. Thank you very much. I downloaded it and gave it a whurl. Just to see if i could get it working and to test its accuracy. NOticed that it seemed to not report things 100% accurately. I had some parts last saved by 2007 (3400) but it doesnt seem to return that value for those. I did a directory full of the same parts created with the same version and modified mostly with the same versions over the years but only about half last saved/modified in 2007. But they all get the same versions returned.

I hate to have to ask more from your generous efforts thus far. :) I def owe you a carton of you favourite beverage. :)

Cheers, HoffY

Reply to
Anonymous

Hmm, maybe it's the references to 2005 that I put there, you can change them like this:

open xls, go to VB Editor (Tools-Macro-Visual Basic Editor) select Tools-References deselect "SolidWorks 2005 constant type library" and "SolidWorks 2005 type library" and select same ones but for version 2007 instead.

If that doesn't make any difference, then I don't have any ideas...just hope that there's no bug in API.

Markku

Reply to
Markku Lehtola

Markku,

I'll give that a look at. It seems to only happen with multiple files in the folder. IF a single file is there it seems to give a more thorough reading of the versions instead of, say, just 3 of the exact same versions for all files listed.

Thanks.

Reply to
Anonymous

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.