Hide Table of Contents

Create Simulation Gravity Feature (VBA)

This example shows how to define a simulation gravity feature data object and then create the feature using that data object.

 

'--------------------------------------------------------

'

' Preconditions:  (1) An assembly document is open in which

'                     "Motion Study 1" exists.

'                 (2) MotionManager tab is visible. If it is not visible,

'                     click View, MotionManager.

'                 (3) SolidWorks 2009 MotionStudy Type Library is

'                     selected on Tools, References in SolidWorks VBA.

'

'

' Postconditions: The Gravity feature is added to "Motion Study 1".

'

'-------------------------------------------------------

Option Explicit

 

Sub main()

    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 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

    End If

    ' Get and activate "Motion Study 1"

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

   

    If (swMotionStudy1 Is Nothing) Then

        MsgBox "Motion Study 1  is not available."

        End

    End If

    

    ' Activate "Motion Study 1"

    swMotionStudy1.Activate

    

    ' Define Gravity feature

    Set swGravityFeat = swMotionStudy1.CreateDefinition(swFmAEMGravity)

    

    If swGravityFeat Is Nothing Then

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

        Exit Sub

    End If

    

    swGravityFeat.ReverseDirection = False

    swGravityFeat.Axis = 0

    swGravityFeat.Strength = 12

     

     ' Create Gravity feature

     Set swFeat = swMotionStudy1.CreateFeature(swGravityFeat)

    

    If swFeat Is Nothing Then

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

    Else

        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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Simulation Gravity Feature (VBA)
*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) 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.