Hide Table of Contents

Apply Table-driven Load to Multiple Beam (VB.NET)

This example shows how to apply a table-driven elliptical load to multiple beams on a part.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Add the SolidWorks Simulation as an add-in
'    (in SolidWorks, click Tools > Add-ins > SolidWorks Simulation).
' 2. Add a reference to the SolidWorks Simulation interop
'    (in the IDE, click Project > Add Reference > Browse button,
'    navigate to
'    C:\Program Files\SolidWorks Corp\SolidWorks\SolidWorks\api\redist\CLR2,
'    and select SolidWorks.Interop.cosworks.dll).
' 3. Open the Immediate window.
'
' Postconditions:
'  1. A table-driven, elliptical load is applied to the part,
'     and its type is shown in the Immediate window.
'  2. To verify, examine the External Loads folder
'     in Study 3 in the Simulation tree.
'
' NOTE: Because this part document is used elsewhere,
' do not save any changes when closing it.
'-------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics
Imports SolidWorks.Interop.cosworks

Partial Class SolidWorksMacro

    
Public Sub Main()

        
Dim swModel As ModelDoc2
        
Dim swModelDocExt As ModelDocExtension
        
Dim swSelMgr As SelectionMgr
        
Dim COSMOSWORKS As Object
        Dim COSMOSObject As CwAddincallback
        
Dim swsActDoc As CWModelDoc
        
Dim swsStudyMngr As CWStudyManager
        
Dim swsStudy As CWStudy
        
Dim swsLBCMgr As CWLoadsAndRestraintsManager
        
Dim swsCWForce As CWForce
        
Dim selBeam1 As Object
        Dim selBeam2 As Object
        Dim selBeam3 As Object
        Dim selBeam4 As Object
        Dim selTrimExtend1 As Object
        Dim selTrimExtend2 As Object
        Dim selTrimExtend3 As Object
        Dim selFace As Object
        Dim data(5) As Double
        Dim rowNum As Integer
        Dim distValue(2) As Double
        Dim forceValue(2) As Double
        Dim errors As Integer
        Dim warnings As Integer
        Dim errCode As Integer
        Dim forceType As String

        Const fileName As String = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\Loop.sldprt"

        ' Open document
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExt = swModel.Extension

        
' Get the SolidWorks Simulation object
        COSMOSObject = swApp.GetAddInObject("SldWorks.Simulation")
        
If COSMOSObject Is Nothing Then ErrorMsg(swApp, "COSMOSObject object not found.", True)
        COSMOSWORKS = COSMOSObject.COSMOSWORKS
        
If COSMOSWORKS Is Nothing Then ErrorMsg(swApp, "COSMOSWORKS object not found.", True)

        
' Open and get active document
        swsActDoc = COSMOSWORKS.ActiveDoc()
        
If swsActDoc Is Nothing Then ErrorMsg(swApp, "No active document.", True)

        
' Create new static study
        swsStudyMngr = swsActDoc.StudyManager()
        
If swsStudyMngr Is Nothing Then ErrorMsg(swApp, "StudyMngr object not there.", True)
        swsStudy = swsStudyMngr.GetStudy(2)
        
If swsStudy Is Nothing Then ErrorMsg(swApp, "Study not created.", True)

        swsLBCMgr = swsStudy.LoadsAndRestraintsManager

        swSelMgr = swModel.SelectionManager

        
' Select entities
        Call swModel.Extension.SelectByID2("Structural Member1[3]", "SOLIDBODY", 0.2669983091512, -0.4441139265177, -0.05999999999995, True, 0, Nothing, 0)
        selBeam1 = swSelMgr.GetSelectedObject6(1, -1)

        
Call swModel.Extension.SelectByID2("Structural Member1[1]", "SOLIDBODY", 0.5462661602309, 0.4984264234139, -0.02447052600974, True, 0, Nothing, 0)
        selBeam2 = swSelMgr.GetSelectedObject6(2, -1)

        
Call swModel.Extension.SelectByID2("Structural Member1[4]", "SOLIDBODY", -0.364288009376, 0.3216654991368, -0.0596008827161, True, 0, Nothing, 0)
        selBeam3 = swSelMgr.GetSelectedObject6(3, -1)

        
Call swModel.Extension.SelectByID2("Structural Member1[2]", "SOLIDBODY", 1.410399123355, -0.191782066378, -0.05999999999989, True, 0, Nothing, 0)
        selBeam4 = swSelMgr.GetSelectedObject6(4, -1)

        
Call swModel.Extension.SelectByID2("Trim/Extend3[1]", "SOLIDBODY", 0.3090890041738, -0.1687816014703, -0.01999999999992, True, 0, Nothing, 0)
        selTrimExtend1 = swSelMgr.GetSelectedObject6(5, -1)

        
Call swModel.Extension.SelectByID2("Trim/Extend3[2]", "SOLIDBODY", 0.7058778550122, -0.1651708212717, -0.01943888995868, True, 0, Nothing, 0)
        selTrimExtend2 = swSelMgr.GetSelectedObject6(6, -1)

        
Call swModel.Extension.SelectByID2("Trim/Extend2[2]", "SOLIDBODY", 0.6681230178383, 0.1527188626094, -0.01999999999998, True, 0, Nothing, 0)
        selTrimExtend3 = swSelMgr.GetSelectedObject6(7, -1)

        
Call swModel.Extension.SelectByID2("", "FACE", -0.4332349164914, -0.1431037474702, -0.05999999999989, True, 0, Nothing, 0)
        selFace = swSelMgr.GetSelectedObject6(8, -1)

        
Dim beamArray As Object() = {selBeam1, selBeam2, selBeam3, selBeam4, selTrimExtend1, selTrimExtend2, selTrimExtend3}

        
' Create the force
        data(0) = 100.0#
        data(1) = 100.0#
        data(2) = 100.0#
        data(3) = 100.0#
        data(4) = 100.0#
        data(5) = 100.0#
        
Dim forceArray As Object() = {data(0), data(1), data(2), data(3), data(4), data(5)}

        rowNum = 3

        distValue(0) = 10.0#
        distValue(1) = 50.0#
        distValue(2) = 100.0#

        forceValue(0) = 100.0#
        forceValue(1) = 0.0#
        forceValue(2) = 50.0#

        
' Table-driven Load: Elliptical
        swsCWForce = swsLBCMgr.AddForce3(swsForceType_e.swsForceTypeForceOrMoment, swsSelectionType_e.swsSelectionBeams, 2, swsTableDrivenInterpolationType_e.swsLinear, swsTableDrivenDistOption_e.swsPercentage, rowNum, distValue, forceValue, True, True, swsBeamNonUniformLoadDef_e.swsTableDrivenLoad, swsBeamNonUniformLoadType_e.swsEllipticalLoad, 4, 100, (forceArray), False, False, (beamArray), selFace, True, errCode)
        forceType =
"Table-drive Load: Multiple Beams"
        LoadError(swApp, forceType, errCode)


    
End Sub

    Sub LoadError(ByVal swApp As Object, ByVal force As String, ByVal errorCode As Long)

        
Select Case errorCode
            
Case 18
                ErrorMsg(swApp,
"You cannot apply triangular and centered load distribution on multiple beams.", True)
            
Case 19
                ErrorMsg(swApp,
"You cannot apply a zero intensity load.", True)
            
Case 20
                ErrorMsg(swApp,
"Invalid selection.", True)
            
Case 21
                ErrorMsg(swApp,
"The table-driven data is invalid.", True)
            
Case 22
                ErrorMsg(swApp,
"In the table-driven distance data, the distance value from the previous row cannot be greater than the distance value in the next row.", True)
            
Case Is <> 0
                ErrorMsg(swApp,
"No forces applied.", True)
            
Case 0
                Debug.Print(force)
        
End Select
    End Sub

    Sub ErrorMsg(ByVal swApp As Object, ByVal Message As String, ByVal EndTest As Boolean)
        swApp.SendMsgToUser2(Message, 0, 0)
        swApp.RecordLine(
"'*** WARNING - General")
        swApp.RecordLine(
"'*** " & Message)
        swApp.RecordLine(
"")
        
If EndTest Then
        End If
    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:   Apply Table-driven Load to Multiple Beam (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) 2013 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.