Hide Table of Contents

Get Motion Study Example (VBA)

This example shows how to get a Physical Simulation motion study and its properties.

 

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

'

' Preconditions: Model is open that has a Physical Simulation motion study

'                named PhysSim.

'

' Postconditions: None

'

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

Option Explicit

 

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 swResults As SwMotionStudy.MotionStudyResults

Dim swMotionStudyProps As SwMotionStudy.MotionStudyProperties

Dim swPhysicalSimProps As SwMotionStudy.PhysicalSimulationMotionStudyProperties

Dim boolstatus As Boolean

Dim i As Integer

Dim vMotionFeatures As Variant

 

Sub main()

 

    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 motion study named PhysSim.

    Set swMotionStudy1 = swMotionMgr.GetMotionStudy("PhysSim")

    If (swMotionStudy1 Is Nothing) Then

        MsgBox "PhysSim is not available."

        End

    End If

    

    swMotionStudy1.StudyType = swMotionStudyType_e.swMotionStudyTypePhysicalSimulation

    

    'Is the motion study active?  If not, activate it.

    If Not swMotionStudy1.IsActive Then swMotionStudy1.Activate

    Debug.Print "Duration of motion study: " & swMotionStudy1.GetDuration

    Debug.Print "Timebar position on timeline: " & swMotionStudy1.GetTime

    

    Debug.Print "Number of motion features: " & swMotionStudy1.GetMotionFeaturesCount

    

    

    Set swMotionStudyProps = swMotionStudy1.GetProperties(2)

    Set swPhysicalSimProps = swMotionStudyProps

    

    Debug.Print ""

    Debug.Print "Physical simulation properties: "

    Debug.Print "    Frame rate: " & swMotionStudyProps.GetFrameRate

    Debug.Print "    Geometric accuracy: " & swPhysicalSimProps.GeometricAccuracy

    Debug.Print "    Mate accuracy: " & swPhysicalSimProps.MateAccuracy

    

    swPhysicalSimProps.MateAccuracy = 1

    

    vMotionFeatures = swMotionStudy1.GetMotionFeatures

    For i = 0 To UBound(vMotionFeatures)

        Dim swFeat As Feature

        Set swFeat = vMotionFeatures(i)

        

        PhysicalSimFeatureTests swFeat, swModel

        

    Next i

    

    'Calculate

    swMotionStudy1.Calculate

    

    WaitForCaluculation swMotionStudy1

    

    Set swResults = swMotionStudy1.GetResults(2)

    Debug.Print ""

    Debug.Print "Are the motion study results out of date? " & swResults.IsOutOfDate

    

     

End Sub

Private Sub WaitForCaluculation(SwMotionStudy As MotionStudy)

    Do While SwMotionStudy.IsPlaying

        DoEvents

    Loop

End Sub

 

Private Sub PhysicalSimFeatureTests(swFeat As Feature, TopDoc As ModelDoc2)

    Dim SimTypeName As String

    Dim SimulationGravityFeatureData As SldWorks.SimulationGravityFeatureData

 

    SimTypeName = swFeat.GetTypeName

 

    Debug.Print ""

    

        ' Print the name of the type of simulation and its gravity strength.

        Select Case SimTypeName

    

        Case "AEMGravity"

            Debug.Print "    Type of feature: AEMGravity"

            Set SimulationGravityFeatureData = swFeat.GetDefinition

            Debug.Print "    Gravity strength: " & SimulationGravityFeatureData.Strength

      

        Case "AEMLinearMotor"

        

            Debug.Print "    Type of feature: AEMLinearMotor"

            Set SimulationGravityFeatureData = swFeat.GetDefinition

            Debug.Print " Gravity Strength: " & SimulationGravityFeatureData.MotorType

    

        Case "AEMRotationalMotor"

        

            Debug.Print "    Type of feature: AEMRotationalMotor"

            Set SimulationGravityFeatureData = swFeat.GetDefinition

            Debug.Print " Gravity Strength: " & SimulationGravityFeatureData.MotorType

            

        Case "AEMLinearSpring"

     

            Debug.Print "   Type of feature: AEMLinearSpring"

            Set SimulationGravityFeatureData = swFeat.GetDefinition

            Debug.Print " Gravity Strength: " & SimulationGravityFeatureData.SpringConstant

    

        Case Else

            Debug.Print "   Type of feature: " & SimTypeName

            MsgBox SimTypeName

    

    End Select

    

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:   Get Motion Study Example (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) 2015 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.