User avatar
By w i l l
#257823
Would it be possible to reimplement the 'save as' for maxwell scenes back into Solidworks? - its a lot quicker to use when saving out lots of different mxs files.
By JDHill
#257833
Sure thing, shouldn't be a problem. In the meantime, here's a VBA macro that will do the job from a toolbar-button:
Code: Select all
Dim swApp As Object
Dim prevName As String

Sub Maxwell_SaveAs()

    On Error GoTo Cancel:
    
    Dim maxwell As Maxwell_Script.ScriptObject
    Set maxwell = New Maxwell_Script.ScriptObject
    
    If maxwell Is Nothing Then
        MsgBox "Unable to create Maxwell ScriptObject.  Please make sure that the Maxwell Script library has been installed."
        Exit Sub
    End If
    
    If Not maxwell.IsConnected Then
        MsgBox "Unable to connect to the current Maxwell Scene.  It may help to re-start SolidWorks."
        Exit Sub
    End If
    
    If prevName = vbNullString Then    
        Set swApp = Application.SldWorks
        
        If swApp Is Nothing Then
            MsgBox "Unable to connect to SolidWorks."
            Exit Sub
        End If
        
        Dim swModel As ModelDoc2
        Set swModel = swApp.ActiveDoc
        
        If swModel Is Nothing Then
            MsgBox "There is no active document."
            Exit Sub
        End If
    
        prevName = swModel.GetPathName
        prevName = Replace(prevName, "sldprt", "mxs")
        prevName = Replace(prevName, "SLDPRT", "mxs")
        prevName = Replace(prevName, "sldasm", "mxs")
        prevName = Replace(prevName, "SLDASM", "mxs")        
    End If
    
    Dim dlg As Object
    Set dlg = CreateObject("MSComDlg.CommonDialog")
    
    If dlg Is Nothing Then
       MsgBox "The script was not able to create the save-file dialog."
       WScript.Quit
       GoTo Cancel
    End If
    
    dlg.MaxFileSize = 260
    dlg.FileName = prevName
    dlg.DialogTitle = "Save MXS As"
    dlg.Filter = "MXS Files (*.mxs)|*.mxs"
    dlg.CancelError = True
    
    dlg.ShowSave
    
    Dim fName As String
    fName = dlg.FileName
    
    If fName <> vbNullString Then
        maxwell.Output.ScenePath = fName 
        maxwell.Rendering.RenderToMxs
        MsgBox "MXS saved as: " & fName 
        prevName = fName 
    End If
    
Cancel:
    
    Set dlg = Nothing

End Sub

Hello everybody, We have just released a new vers[…]

Help with swimming pool water

Nothing beats observing the real world or, if that[…]

Sketchup 2026 Released

Considering how long a version for Sketchup 2025 t[…]

Greetings, One of my users with Sketchup 2025 (25[…]