Saving a batch of plans in previous version

Hello everyone,
I'm on Solidworks 2024 Sp5 on which I've created an ASM, parts and about fifty plan files.

I manage to make a " pack and go " in previous version (2022 and 2023) however this is only functional for parts and assembly. The drawings checked and exported via the " pack and Go " remain in 2024...

After contact and exchange with the support the answer is: " this is the normal operation of solidworks " (understand: get on with it! it's none of our business!)

I tried the task scheduler, I tried to go through a macro... in short I'm dry!
The only method that works is to open the plans one by one, then save them in an earlier version.
In my logic of fenicant (and quality!) it seems unthinkable to me for 50 shots as well as for future projects.

Has anyone figured out a trick to exploit this WONDERFUL " save as an early version" feature for batches of drawing files?

Thanks in advance!

AI response:

Question Answer
Known bug? :white_check_mark: Yes, widely reported (but not officially recognized as a bug)
Normal behavior? :warning: Officially yes... but highly contested
Fix announced? :x: No
Viable workaround? :white_check_mark: VBA macro or manual backup
Reliable pack and go for retro DRW? :x:

VBA macro solution to convert a plan folder (Not tested output as-is by AI copilot):

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim errors As Long
Dim warnings As Long

Sub main()

    Set swApp = Application.SldWorks

    ' ⚠️ MODIFIER LE CHEMIN DU DOSSIER ICI
    Dim folderPath As String
    folderPath = "C:\TEMP\Plans_2024"

    ' Choisir la version cible :
    ' swSaveAsVersion_e.swSaveAsCurrentVersion
    ' swSaveAsVersion_e.swSaveAs2023
    ' swSaveAsVersion_e.swSaveAs2022
    Dim targetVersion As Long
    targetVersion = swSaveAsVersion_e.swSaveAs2023

    Dim fileName As String
    fileName = Dir(folderPath & "\*.slddrw")

    Do While fileName <> ""

        Dim fullPath As String
        fullPath = folderPath & "\" & fileName

        Set swModel = swApp.OpenDoc6( _
            fullPath, _
            swDocumentTypes_e.swDocDRAWING, _
            swOpenDocOptions_e.swOpenDocOptions_Silent, _
            "", _
            errors, _
            warnings)

        If Not swModel Is Nothing Then

            swModel.ForceRebuild3 False

            Dim savePath As String
            savePath = folderPath & "\OLDVER_" & fileName

            swModel.SaveAs4 _
                savePath, _
                targetVersion, _
                swSaveAsOptions_e.swSaveAsOptions_Silent, _
                errors, _
                warnings

            swApp.CloseDoc swModel.GetTitle

        End If

        fileName = Dir
    Loop

    MsgBox "Conversion terminée !", vbInformation

End Sub

Not possible for me to test the macro because sw2023, but the code seems correct at 1st sight.

2 Likes

Thank you for your search!

But I already spent a few hours trying a macro with copilot, before they told me that it was finally impossible.

I hope I missed something... :confused:

Try and give us feedback, if bug and where (capture of the error).
If the functionality (save in previous version) does not exist in the API, we won't do much.
If there is another bug, we can help you debug.

indeed the functionality is non-existent in VBA...

Not the 1st time that AI invents a feature in the API, unfortunately...

Try this one just in case with SaveAs3 Method (IModelDocExtension) instead of saveas4.
This feature exists after it is well documented with a version option, so to be tested.

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExt As SldWorks.ModelDocExtension
Dim errors As Long
Dim warnings As Long

Sub main()

    Set swApp = Application.SldWorks

    ' ⚠️ CHEMIN À ADAPTER
    Dim folderPath As String
    folderPath = "C:\TEMP\Plans_2024"

    ' Version cible
    Dim targetVersion As Long
    targetVersion = swSaveAsVersion_e.swSaveAs2023
    ' swSaveAs2022 possible aussi

    Dim fileName As String
    fileName = Dir(folderPath & "\*.slddrw")

    Do While fileName <> ""

        Dim fullPath As String
        fullPath = folderPath & "\" & fileName

        Set swModel = swApp.OpenDoc6( _
            fullPath, _
            swDocumentTypes_e.swDocDRAWING, _
            swOpenDocOptions_e.swOpenDocOptions_Silent, _
            "", _
            errors, _
            warnings)

        If Not swModel Is Nothing Then

            Set swExt = swModel.Extension
            swModel.ForceRebuild3 False

            Dim savePath As String
            savePath = folderPath & "\OLDVER_" & fileName

            swExt.SaveAs3 _
                savePath, _
                swSaveAsOptions_e.swSaveAsOptions_Silent, _
                targetVersion, _
                errors, _
                warnings

            swApp.CloseDoc swModel.GetTitle

        End If

        fileName = Dir
    Loop

    MsgBox "Conversion terminée", vbInformation

End Sub

Unfortunately " swSaveAs2023 " does not exist :confused:

Hello
Isn't it possible to tell a macro to open all the clips one by one, and print them? under 2024 extraordinary :grinning:
Do you have PDM? It was a macro that did this to us in another era after selecting MEPs.

It's a mess :upside_down_face:

The limits of AI!
Last attempt, not easy when you can't test.
Apparently you have to use " AdvancedSaveAsOptions.SaveAsPreviousVersion' ":

Option Explicit

Dim swApp   As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExt   As SldWorks.ModelDocExtension
Dim advOpts As SldWorks.AdvancedSaveAsOptions

Dim errs    As Long
Dim warns   As Long

Sub main()

    Set swApp = Application.SldWorks

    ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ' A MODIFIER
    Dim folderPath As String
    folderPath = "C:\TEMP\Plans_2024"

    ' -1 = version précédente
    ' -2 = deux versions précédentes
    Dim previousOffset As Long
    previousOffset = -1   ' 2024 -> 2023
    ' previousOffset = -2 ' 2024 -> 2022
    ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Dim fileName As String
    fileName = Dir(folderPath & "\*.slddrw")

    Do While fileName <> ""

        Dim fullPath As String
        fullPath = folderPath & "\" & fileName

        Set swModel = swApp.OpenDoc6( _
            fullPath, _
            swDocumentTypes_e.swDocDRAWING, _
            swOpenDocOptions_e.swOpenDocOptions_Silent, _
            "", _
            errs, _
            warns)

        If swModel Is Nothing Then
            Debug.Print "❌ Impossible d’ouvrir : " & fileName
            GoTo NextFile
        End If

        Set swExt = swModel.Extension

        Set advOpts = swExt.GetAdvancedSaveAsOptions( _
            swSaveWithReferencesOptions_e.swSaveWithReferencesOptions_None)

        advOpts.SaveAsPreviousVersion = previousOffset
        advOpts.SaveAllAsCopy = True

        Dim savePath As String
        savePath = folderPath & "\OLDVER_" & fileName

        If False = swExt.SaveAs3( _
            savePath, _
            swSaveAsVersion_e.swSaveAsCurrentVersion, _
            swSaveAsOptions_e.swSaveAsOptions_Silent, _
            Nothing, _
            advOpts, _
            errs, _
            warns) Then

            Debug.Print "❌ ERREUR SaveAs : " & fileName & _
                        " | Code = " & errs
        Else
            Debug.Print "✅ OK : " & fileName
        End If

        swApp.CloseDoc swModel.GetTitle

NextFile:
        fileName = Dir
    Loop

    MsgBox "Traitement terminé (voir Ctrl+G pour le log)", vbInformation

End Sub
``

Thanks again for this lead.

But after many iterations, and debugging, here is the conclusion :confused:

image

Sorry for the cold trails.
The most serious lead is this:

Test it on a MEP if it works, it means that it is possible to do it in batches. (Via Integration, or by modifying this macro).
Codestack is a reliable source unlike AI...

1 Like