Hide Table of Contents

Run Studies in Batch Mode Example (VB.NET)

This example shows how to run studies in batch mode.

' Preconditions:
' 1. Add the SOLIDWORKS Simulation as an add-in (in SOLIDWORKS, click 
'    Tools > Add-ins > SOLIDWORKS Simulation > OK).

' 2. Add the SOLIDWORKS Simulation primary interop assembly as a reference
'    (in the IDE, click Project > Add Reference > .NET > 
'    SolidWorks.Interop.cosworks > OK).
' 3. Ensure that the specified model exists.

' 4. Open the Immediate window.
' Postconditions:
' 1. Opens the model document.
' 2. Sets the run and mesh option for the studies in the batch.
' 3. Analyzes the studies in the batch.
' 4. Gets the result codes of the studies.
' 5. Inspect the Immediate window.

' NOTE: Because the model is used elsewhere, do not save changes.
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.cosworks
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
    Dim Part As ModelDoc2
    Dim fileName As String
    Dim CWAddinCallBack As CWAddinCallBack
    Dim ActDoc As CWModelDoc
    Dim StudyMngr As CWStudyManager
    Dim Study As CWStudy
    Dim RunStudyResults As CWRunStudiesResults
    Dim RunStudyOptions As CWRunSpecStudiesRunMeshOptions
    Dim errCode As Integer
    Dim studyName As String
    Dim result As Integer
    Dim errors As Integer
    Dim warnings As Integer
    Sub main()
        fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\api\tjoint.sldprt"
        Part = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, 1, "", errors, warnings)
        CWAddinCallBack = swApp.GetAddInObject("SldWorks.Simulation")
        ActDoc = COSMOSWORKS.ActiveDoc()
        StudyMngr = ActDoc.StudyManager()
        RunStudyOptions = StudyMngr.RunSpecifiedStudyOptions()
        errCode = RunStudyOptions.AddStudyOption("Partial", swsRunStudiesRunMeshOptions_e.swsRunStudiesRunMeshOptions_MeshAndRun)
        errCode = RunStudyOptions.AddStudyOption("Ready - 8 plies", swsRunStudiesRunMeshOptions_e.swsRunStudiesRunMeshOptions_MeshAndRun)
        RunStudyResults = StudyMngr.RunSpecifiedStudyByName(errCode)
        errCode = RunStudyResults.GetFirstItem(studyName, result)
        Debug.Print("First study in batch: " & studyName)
        Debug.Print("  Result code as defined in swsRunStudiesResultsErrorCode_e: " & result)
        errCode = RunStudyResults.GetNextItem(studyName, result)
        Debug.Print("Next study in batch: " & studyName)
        Debug.Print("  Result code as defined in swsRunStudiesResultsErrorCode_e: " & result)
    End Sub
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
End Class



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Run Studies in Batch Mode Example (VB.NET)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2017 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.