Reply

Assembly References?

[ Edited ]

 

Hi,

I would like to use VBA to control variables like a motion simulation in a SolidEdge-partdocument, that has been placed in an assembly. How should I do that? I guess something with occurrences, but my knowledge of VBA is quite limited. I've pasted a part of the code I have down below.

Private Sub CommandButton1_Click()

On Error Resume Next

'Declare the program variables

Dim HipXRotation As Single

Dim ShoulderXRotation As Single

Dim objApp As Object

Dim objVariables As Object

Dim objVariable As Object

Dim objDoc As Object

Dim objVars As Object

' Checking for the active document

Set objApp = GetObject(, "SolidEdge.Application")

If Err Then

MsgBox "Open wireframe_opzet_HALF.par in Solid Edge before executing this module", vbOKOnly + vbExclamation, "Error"

Exit Sub

Else

'Connect to a running instance of Solid Edge

Set objApp = GetObject(, "SolidEdge.Application")

Set objDoc = objApp.ActiveDocument

Set objVars = objDoc.Variables

'Access the Variables collection.

Set objVariables = objApp.ActiveDocument.Variables

End If

'Start Simulation

For HipXRotation = -45 To 40 Step 17

    Call objVariables.Edit("Left_Hip_X_Rotation", HipXRotation)

    Call objVariables.Edit("Left_Ankle_Y_Rotation", -51.5)

Next HipXRotation

 

For ShoulderXRotation = -110 To 98 Step 37

    Call objVariables.Edit("Left_Shoulder_X_Rotation", ShoulderXRotation)

Next ShoulderXRotation

Call objVariables.Edit("Left_Hip_X_Rotation", 0)

Call objVariables.Edit("Left_Hip_Y_Rotation", 0)

Call objVariables.Edit("Left_Ankle_Y_Rotation", 0)

End Sub

This code works fine in the Part Environment, but like I said, I want it to work in Assembly Environment. Thanks in advance.

Tom Peijs

 

Posted by: Tom Peijs
Post date: 9/30/2008 3:12:30 AM

2 REPLIES

RE: Assembly References?

[ Edited ]

 

Hello Tom,

if you don't use the SolidEdge Spy application, that would be a great help to you. It should be somewhere on this website;

First thing you have to do is get hold of the Parts inside an assembly. To do that, make sure your active document is the assembly and then do what you already did:

Set objDoc = objApp.ActiveDocument

Its better instead that you define

SolidEdgeAssembly asmDoc = objApp.ActiveDocument  (not sure you need a cast in VB, but you do in C#).

Now you need to use Spy to familiarize yourself as to where all the Parts and Subassembly are stored within asmDoc;

They would be in a few places; you need to use the right ones; in this case you need to get hold of the "instances" as opposed to the class references;  This is tricky;

I'll explain:

for the Top Assembly, the instances are under directly in "asmDoc.Occurrences"

However, if you have any assembly Occurrence within that

"Occurrence level2Asm = asmDoc.Occurrences.Item(1);"

then you need to look for instances under level2Asm.SubOccurrences.

Btw level2Asm would be an Assembly if asmDoc.Occurrences.Item(1).SubAssembly = true

I hope this helps you get started; you have to start understanding the way the information is organized (use Spy again to do that)

Chahe

 

 

 

Posted by: Chahe Adourian
Post date: 10/3/2008 3:05:25 PM

RE: Assembly References?

[ Edited ]

Thanks Chahe for your reply! I'll look into it.

 

Tom

 

Posted by: Tom Peijs
Post date: 10/5/2008 10:01:30 PM