Hide Table of Contents

Create Body From Deformed Shape Example (VB.NET)

This example shows how to save the deformed shape resulting from running a static study.

'---------------------------------------------------------------------------
' Preconditions:
' 1. Add the SOLIDWORKS Simulation as an add-in
'    (in SOLIDWORKS, select Tools > Add-ins > SOLIDWORKS Simulation
'     and click OK).
' 2. Add the SOLIDWORKS Simulation primary interop assembly as a reference 
'    (in the IDE's Project Explorer, right-click
'     the project name, click Add Reference, click the Browse tab,
'     navigate to install_dir\api\redist\CLR2
'     click SolidWorks.Interop.cosworks.dll, and click OK).
' 3. Ensure that the specified model exists.

' 4. Open an Immediate window.
'
' Postconditions:
' 1. Opens the model document.
' 2. Gets the static study.
' 3. Meshes the model.
' 4. Sets the solver type.
' 5. Analyzes the study.
' 6. Saves the deformed shape as
'    install_dir\samples\tutorial\api\deformedBody.sldprt.
' 7. 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
 
    Sub main()
 
        Dim Part As ModelDoc2
        Dim fileName As String
        Dim errors As Integer
        Dim warnings As Integer
        Dim errCode As Integer
        Dim COSMOSWORKS As COSMOSWORKS
        Dim CWAddinCallBack As CWAddinCallBack
        Dim ActDoc As CWModelDoc
        Dim StudyMngr As CWStudyManager
        Dim Study As CWStudy
        Dim StaticOptions As CWStaticStudyOptions
        Dim CWFeatObj As CWMesh
        Dim res As CWResults
 
        Const MeshEleSize As Double = 1.4769
        Const MeshTol As Double = 0.073847
 
        If SwApp Is Nothing Then Exit Sub
 
        fileName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\tjoint.sldprt"
        Part = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, 1, "", errors, warnings)
 
        CWAddinCallBack = SwApp.GetAddInObject("SldWorks.Simulation")
        COSMOSWORKS = CWAddinCallBack.COSMOSWORKS
 
        ActDoc = COSMOSWORKS.ActiveDoc()
 
        StudyMngr = ActDoc.StudyManager()
        Study = StudyMngr.GetStudy(0)
        Study.ActivateConfiguration()
        StudyMngr.ActiveStudy = 0
 
        'Mesh
        CWFeatObj = Study.Mesh
        CWFeatObj.MesherType = 0
        CWFeatObj.Quality = 0
        errCode = Study.CreateMesh(0, MeshEleSize, MeshTol)
        CWFeatObj = Nothing
 
        'Set solver type to FFEPlus
        StaticOptions = Study.StaticStudyOptions
        StaticOptions.SolverType = 2
 
        'Run analysis
        errCode = Study.RunAnalysis
 
        res = Study.Results
        res.CreateDeformedBody(swsCreateDeformedBodyOption_e.swsCreateDeformedBodyAsPart, "deformedBody", errCode)
        Debug.Print("Create deformed body result code as defined in swsCreateDeformedBodyError_e: " & errCode)
 
    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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Body From Deformed Shape Example (VB.NET)
*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) 2016 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.