Hide Table of Contents

Create Force Feature (VBA)

This example shows how to create a force feature for use with Basic Motion and Motion Analysis studies.


' Preconditions: An assembly is open and Motion Study 3 exists.

'                SolidWorks MotionStudy type library is referenced.


' Postconditions: A Force feature is created.


Option Explicit


Sub main()


    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim swModelDocExt As SldWorks.ModelDocExtension

    Dim swSelMgr As SldWorks.SelectionMgr

    Dim swMotionMgr As SwMotionStudy.MotionStudyManager

    Dim swMotionStudy3 As SwMotionStudy.MotionStudy

    Dim swForceFeat As SldWorks.SimulationForceFeatureData

    Dim boolstatus As Boolean

    Dim swFeat As SldWorks.Feature


    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swModelDocExt = swModel.Extension


    ' Get the MotionManager

    Set swMotionMgr = swModelDocExt.GetMotionStudyManager()

    If (swMotionMgr Is Nothing) Then


    End If


    ' Get Motion Study 3, which must must exist

    Set swMotionStudy3 = swMotionMgr.GetMotionStudy("Motion Study 3")


    If (swMotionStudy3 Is Nothing) Then

        MsgBox "Motion Study 3 is not available."


    End If


    ' ACtivate Motion Study 3



    ' Select a face

    boolstatus = swModelDocExt.SelectByID2("", "FACE", -0.07792618280496, 0.06212618843159, 0.02214691016243, False, 0, Nothing, 0)


   ' Create the definition for the Force feature

    Set swForceFeat = swMotionStudy3.CreateDefinition(swFmAEMLinearForce)

    If swForceFeat Is Nothing Then

       Debug.Print "ERROR: Creation of force feature data object failed."

        Exit Sub

    End If


    ' Define the Force feature

    swForceFeat.ActionType = swSimulationForceAction_ActionOnly

    Set swSelMgr = swModel.SelectionManager

    ' Get the selected face

    swForceFeat.ActionLocation = swSelMgr.GetSelectedObject6(1, -1)


    Dim RelObj As Component2

    ' Get the component to which the just selected face belongs

    Set RelObj = swSelMgr.GetSelectedObjectsComponent3(1, -1)


    ' Select a face on a component and create the force feature relative to this component

    boolstatus = swModelDocExt.SelectByID2("", "FACE", -0.07924982844941, 0.06212618843165, 0.03225592518596, False, 0, Nothing, 0)

    swForceFeat.ReferenceComponent = RelObj


     ' Create a force feature

     Set swFeat = swMotionStudy3.CreateFeature(swForceFeat)


    If swFeat Is Nothing Then

        Debug.Print " ERROR: Creation of the force feature failed."


        Debug.Print "Name of the feature added : " & swFeat.Name

    End If

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:   Create Force Feature (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) 2010 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.