SolidWorks API: Disable message: Do you want to replace it

Hello

 

I made a macro allowing me to generate the DXF of the drawings contained in a directory.

However, when the DXF already exists, I have a dialog box that opens with the message:

"The "MyFile" file already exists, do you want to replace it?

Is there a method to replace the file without having to click yes every time the file already exists?

 

Thank you in advance,

Gautier

Hello

Depending on the method used, it seems to me that the "silent" option can solve the problem

 

To try

Cdlt

Hello

You should be able to use the "SaveAs3" function, here is an example of a macro:

Sub main()

    Dim swApp As SldWorks.SldWorks
    Dim swmodel As SldWorks.ModelDoc2
    Dim stPath As String
    Dim lgFichier As Long
    Dim blretval As Boolean
    Dim Errors As Long
    Dim Warnings As Long
    
    
    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc
    Dim myModelView As Object
    Set myModelView = Part.ActiveView
    myModelView.FrameState = swWindowState_e.swWindowMaximized
    
    Set swApp = Application.SldWorks
    
    'on récupére le document actif
    Set swmodel = swApp.ActiveDoc
    
    If Not swmodel Is Nothing Then
       'on vérifie que le fichier est enregisté
        If swmodel.GetPathName = "" Then
            MsgBox "Veuillez enregistrer votre document avant de lancer la macro", vbInformation
            End
        Else
            'on récupére l'emplacement du fichier
            stPath = swmodel.GetPathName

            'on récupére le nombre de caractére jusqu'au . de l'extension
            lgFichier = InStrRev(stPath, ".", -1, vbTextCompare) - 1
            'on récupére le chemin sans l'extention
            If lgFichier > 0 Then
                  stPath = Left(stPath, lgFichier)
            End If
        End If

        'si le document est une mise en plan
        If swmodel.GetType = swDocDRAWING Then
            'on créer le DXF
            Dim nameDXF As String
            nameDXF = stPath & "_drw.DXF"
            blretval = swmodel.SaveAs3(nameDXF, 0, 0)
            
            MsgBox "Traitement terminé"

        End If

    End If

End Sub

 

Kind regards

Hello

 

Thank you for your answers. d.roger I already use the SaveAs3 function:

"longstatus = swModel.SaveAs3(nom_Fichier & " EXT. DXF", 0, 0)"

Be.adl, I looked for the function to record with the Silent option and this code works:

longstatus = swModel.Extension.SaveAs(nom_Fichier & " EXT. DXF", swSaveAsOptions_Silent, 0, swExportPDFData, nErrors, nWarnings)

 

The "swSaveAsOptions_Silent" option allows you to disable the message.

 

Thank you for your answers.

 

Gautier.