VBA code to write Dynamic Simulation output

VBA code to write Dynamic Simulation output

Anonymous
Not applicable
598 Views
1 Reply
Message 1 of 2

VBA code to write Dynamic Simulation output

Anonymous
Not applicable

Good morning.


I'm trying to write a VBA code to run several dynamic simulations with Inventor (v2014).
Thanks to this forum, I wrote the following code that saves in the 'values' array the results of time and position of the part2 for each step time (prismatic joint). To run the code you should extract the zipped folder DynSim in C:\.

 

Sub test()

Dim n As Integer
n = 1
Dim doc(1 To 1) As AssemblyDocument

For i = 1 To n
Set doc(i) = ThisApplication.Documents.Open("C:\DynSim\DynSim_" & i & ".iam")
Next i

Dim UIManager As UserInterfaceManager
Dim environmentMgr As EnvironmentManager
Dim dsEnv As Environment
Dim simManager As SimulationManager
Dim sim As DynamicSimulation

For i = 1 To n
doc(i).Activate
Set UIManager = ThisApplication.UserInterfaceManager
If UIManager.ActiveEnvironment.InternalName <> "DynamicSimulationEnvironmentInternalName" Then
Set environmentMgr = doc(i).EnvironmentManager
Set dsEnv = UIManager.Environments.Item("DynamicSimulationEnvironmentInternalName")
Call environmentMgr.SetCurrentEnvironment(dsEnv)
End If
Set simManager = doc(i).ComponentDefinition.SimulationManager
Set sim = simManager.DynamicSimulations.Item(1)

'start simulation:
If sim.LastComputedTimeStep < sim.NumberOfTimeSteps Then
sim.ComputeSimulation
End If

'output results:
Dim steps As Integer
steps = sim.NumberOfTimeSteps
Dim values() As Double
ReDim values(steps * 2 + 1)

' Prismatic Joint:
Dim oJoints As Inventor.DSJoints
Set oJoints = sim.DSJoints

Dim oJoint As Inventor.DSJoint
Set oJoint = oJoints.Item(1)

Dim oJointDef As Inventor.DSJointDefinition
Set oJointDef = oJoint.Definition

Dim oDegs As Inventor.DSDegreesOfFreedom
Set oDegs = oJointDef.DegreesOfFreedom

Dim oDeg As Inventor.DSDegreeOfFreedom
Set oDeg = oDegs(1)

Dim oResults As Inventor.DSResults
Set oResults = oDeg.Results

Dim oResult As Inventor.DSResult
Set oResult = oResults.Item(4)

Call oResult.GetResultValues(values())


Next i

End Sub

If I write  'Set oResult = oResults.Item(2)', I obtain a 'values' array which represents the time and speed of part2. If I write 'Set oResult = oResults.Item(3)', I obtain time and acceleration of part2.

Well, how can I obtain the results of 3D contact joint? If I write 'Set oResult = oResults.Item(4)' I obtain an error: 'Method GetResultValues of the object DSResult failed'. Why?

 

My goal is to have a 'values' array which represents time and force_max of 3D contact joint (Type of DS Joint = kDSJointTypeImpact3D 92982 Constact 3D - DS Joint. from DSJointTypeEnum Enumerator help page of Inventor).

 

Thank you for any reply.

Matteo

 

0 Likes
599 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

??? nobody knows about dynamic simulation programming ???

0 Likes