Hide Table of Contents

Set Composite Shell Options Example (VBA)

This example shows how to set composite shell options.

' 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. Verify that the specified material library exists.
' 4. Verify that the specified model document exists.
' Postconditions:
' 1. Opens the model.
' 2. Activates Ready - 8 plies.
' 3. Sets composite shell options.
' 4. Meshes the model.
' 5. Analyzes the study.
' NOTE: Because the model is used elsewhere, do not save changes.
Dim SwApp As SldWorks.SldWorks
Dim COSMOSObject As CosmosWorksLib.CWAddinCallBack
Dim ActDoc As CosmosWorksLib.CWModelDoc
Dim StudyMngr As CosmosWorksLib.CWStudyManager
Dim Study As CosmosWorksLib.CWStudy
Dim Shell As CosmosWorksLib.CWShell
Dim Mesh As CosmosWorksLib.CwMesh
Dim StaticOptions As CosmosWorksLib.CWStaticStudyOptions
Dim Part As SldWorks.ModelDoc2
Dim ShellMgr As CosmosWorksLib.CWShellManager
Dim CWShellOptions As CosmosWorksLib.CWCompositeShellOptions
Dim m As Integer
Dim errCode As Long
Dim longstatus As Long, longwarnings As Long
Dim bApp As Boolean
Dim j As Integer

Const MeshEleSize   As Double = 1.4769
Const MeshTol       As Double = 0.073847

Option Explicit
Sub main()

    Set SwApp = Application.SldWorks

    Set COSMOSObject = SwApp.GetAddInObject("CosmosWorks.CosmosWorks")
    If COSMOSObject Is Nothing Then ErrorMsg SwApp, "Simulation add-in not loaded"
    If COSMOSWORKS Is Nothing Then ErrorMsg SwApp, "No COSMOSWORKS object"

    Set Part = SwApp.OpenDoc6("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\Simulation Examples\Composites\tjoint.SLDPRT", swDocPART, 2, "", longstatus, longwarnings)
    If Part Is Nothing Then ErrorMsg SwApp, "Failed to open tjoint.SLDPRT"

    Set ActDoc = COSMOSWORKS.ActiveDoc()
    If ActDoc Is Nothing Then ErrorMsg SwApp, "No active document"

    Set StudyMngr = ActDoc.StudyManager()
    If StudyMngr Is Nothing Then ErrorMsg SwApp, "No study manager"
    StudyMngr.ActiveStudy = 1
    Set Study = StudyMngr.GetStudy(1)

    Set ShellMgr = Study.ShellManager
    If ShellMgr Is Nothing Then ErrorMsg SwApp, "No shell manager"

    Set Shell = ShellMgr.GetShellAt(0, errCode)
    If errCode <> 0 Then ErrorMsg SwApp, "No shell"

    bApp = Shell.SetLibraryMaterial("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\sldmaterials\solidworks materials.sldmat", "Alloy Steel")
    Shell.Formulation = 2

    Set CWShellOptions = Shell.CompositeOptions
    If CWShellOptions Is Nothing Then ErrorMsg SwApp, "No composite shell options"

    CWShellOptions.Symmetric = 0
    CWShellOptions.RotateZeroDegreeReference = 0
    CWShellOptions.MappingType = 0
    CWShellOptions.Symmetric = 0
    CWShellOptions.Sandwich = 0
    CWShellOptions.PlyRelativeAngle = 0
    CWShellOptions.LengthUnit = 4
    CWShellOptions.AllPliesSameMaterial = 1

    m = CWShellOptions.GetTotalPlies()
    For j = 0 To m - 1
        errCode = CWShellOptions.SetPlyParameters2(j + 1, 0.1 * (j + 1), 0.05 * j, "solidworks materials", "Cast Stainless Steel")
    Next j


    Set Mesh = Study.Mesh
    Mesh.MesherType = 0
    Mesh.Quality = 0
    errCode = Study.CreateMesh(0, MeshEleSize, MeshTol)

    Set StaticOptions = Study.StaticStudyOptions
    StaticOptions.SolverType = 2

    'Run analysis
    errCode = Study.RunAnalysis

End Sub

Sub ErrorMsg(SwApp As SldWorks.SldWorks, Message As String)
    SwApp.SendMsgToUser2 Message, 0, 0
    SwApp.RecordLine "'*** WARNING - General"
    SwApp.RecordLine "'*** " & Message
    SwApp.RecordLine ""
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

Subject:   Feedback on Help Topics
Page:   Set Composite Shell Options Example (VBA)
*   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.