Hide Table of Contents

Run Studies in Batch Mode Example (VBA)

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 type library as a reference (in the IDE,
'    click Tools > References > SOLIDWORKS Simulation version type library).
' 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.
'---------------------------------------------------------------------------
Option Explicit

Dim swApp           As SldWorks.SldWorks
Dim Part            As SldWorks.ModelDoc2
Dim fileName        As String
Dim COSMOSWORKS     As CosmosWorksLib.COSMOSWORKS
Dim CWAddinCallBack As CosmosWorksLib.CWAddinCallBack
Dim ActDoc          As CosmosWorksLib.CWModelDoc
Dim StudyMngr       As CosmosWorksLib.CWStudyManager
Dim RunStudyResults As CosmosWorksLib.CWRunStudiesResults
Dim RunStudyOptions As CosmosWorksLib.CWRunSpecStudiesRunMeshOptions
Dim errCode         As Long
Dim studyName       As String
Dim result          As Long
Dim errors          As Long
Dim warnings        As Long

Sub main()
 

    Set swApp = Application.SldWorks
   

    fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\api\tjoint.sldprt"
    Set Part = swApp.OpenDoc6(fileName, swDocPART, 1, "", errors, warnings)
   

    Set CWAddinCallBack = swApp.GetAddInObject("SldWorks.Simulation")
    Set COSMOSWORKS = CWAddinCallBack.COSMOSWORKS
    Set ActDoc = COSMOSWORKS.ActiveDoc()
    Set StudyMngr = ActDoc.StudyManager()
   

    Set RunStudyOptions = StudyMngr.RunSpecifiedStudyOptions()
    errCode = RunStudyOptions.AddStudyOption("Partial", swsRunStudiesRunMeshOptions_MeshAndRun)
    errCode = RunStudyOptions.AddStudyOption("Ready - 8 plies", swsRunStudiesRunMeshOptions_MeshAndRun)
   

    Set 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

 

 



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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Run Studies in Batch Mode Example (VBA)
*Comment:  
*   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:




x

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
x

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.