Hide Table of Contents

Create Simulation Gravity Feature Example (VBA)

This example shows how to create a simulation gravity feature in a motion study.

' Preconditions:  
' 1. Verify that the specified model document exists.
' 2. In SOLIDWORKS, verify that View > MotionManager is selected.
' 3. In the IDE, click Tools > References and select
'    SOLIDWORKS version MotionStudy Type library.
' 4. Click OK.
' 5. Open an Immediate window.
' Postconditions:
' 1. Adds Gravity to the MotionManager design tree on the Motion Study 1 tab.
' 2. Inspect the Immediate window.
' NOTE: Because the model is used elsewhere,
' do not save changes when closing it.

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swMotionMgr As SwMotionStudy.MotionStudyManager
Dim swMotionStudy1 As SwMotionStudy.MotionStudy
Dim swGravityFeat As SldWorks.SimulationGravityFeatureData
Dim swFeat As SldWorks.Feature
Dim longstatus As Long, longwarnings As Long
Option Explicit
Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.OpenDoc6("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\beam_boltconnection.sldasm", 2, 0, "", longstatus, longwarnings)
    swApp.ActivateDoc2 "beam_boltconnection", False, longstatus
    Set swModel = swApp.ActiveDoc

    Set swModelDocExt = swModel.Extension

    Set swMotionMgr = swModelDocExt.GetMotionStudyManager()

    Set swMotionStudy1 = swMotionMgr.GetMotionStudy("Motion Study 1")

    If (swMotionStudy1 Is Nothing) Then
        Debug.Print "Motion Study 1 is not available"
    End If

    swMotionStudy1.StudyType = swMotionStudyType_e.swMotionStudyTypePhysicalSimulation

    ' Activate Motion Study 1

    ' Define feature data
    Set swGravityFeat = swMotionStudy1.CreateDefinition(swFmAEMGravity)

    If swGravityFeat Is Nothing Then
        Debug.Print "Creation of feature data object failed"
    End If

    swGravityFeat.ReverseDirection = False
    swGravityFeat.Axis = 0
    swGravityFeat.Strength = 12

     ' Create feature
     Set swFeat = swMotionStudy1.CreateFeature(swGravityFeat)

    If swFeat Is Nothing Then
        Debug.Print "Creation of 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 Simulation Gravity Feature 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) 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.