Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA & Assemblies

Status
Not open for further replies.

TomPeijs

Mechanical
Oct 7, 2008
2
Hi,

I'm trying to drive variables through VBA in a Solid Edge Assembly, which holds two part-files. I want to be able to change the variables of both files. I have the following code to change the variables of 1 partfile, but it doesn't seem to be working: I don't even get errors!

Private Sub CommandButton3_Click()
On Error Resume Next

'Declare the program variables
Dim HipXRotation As Single
Dim ShoulderXRotation As Single
Dim SpineXRotation As Single
Dim objApp As Object
Dim objVariables As Object
Dim objDim As Object
Dim objDim2 As Object
Dim objDim3 As Object
Dim objDim4 As Object
Dim objDim5 As Object
Dim objDim6 As Object

'Connect to a running instance of Solid Edge
Set objApp = GetObject(, "SolidEdgeFramework.Application")

'Access the Variables collection.
Set objVariables = objApp.ActiveDocument.Occurrences.Item(2).PartDocument.Variables

Set objDim = objVariables.Translate("Left_Foot_X_Dist")
Set objDim2 = objVariables.Translate("Left_Foot_Y_Dist")
Set objDim3 = objVariables.Translate("Left_Foot_Z_Dist")
Set objDim4 = objVariables.Translate("Left_Hand_X_Dist")
Set objDim5 = objVariables.Translate("Left_Hand_Y_Dist")
Set objDim6 = objVariables.Translate("Left_Hand_Z_Dist")

'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)
Range("H15").Value = objDim.Value * 1000
Range("I15").Value = objDim2.Value * 1000
Range("J15").Value = objDim3.Value * 1000
Range("K15").Value = objDim4.Value * 1000
Range("L15").Value = objDim5.Value * 1000
Range("M15").Value = objDim6.Value * 1000
Next HipXRotation
For ShoulderXRotation = -110 To -90 Step 10
Call objVariables.Edit("Left_Shoulder_X_Rotation", ShoulderXRotation)
Range("H15").Value = objDim.Value * 1000
Range("I15").Value = objDim2.Value * 1000
Range("J15").Value = objDim3.Value * 1000
Range("K15").Value = objDim4.Value * 1000
Range("L15").Value = objDim5.Value * 1000
Range("M15").Value = objDim6.Value * 1000
Next ShoulderXRotation
For SpineXRotation = -40 To 40 Step 10
Call objVariables.Edit("Spine_X_Rotation", SpineXRotation)
Call objVariables.Edit("Left_Shoulder_X_Rotation", -90)
Range("H15").Value = objDim.Value * 1000
Range("I15").Value = objDim2.Value * 1000
Range("J15").Value = objDim3.Value * 1000
Range("K15").Value = objDim4.Value * 1000
Range("L15").Value = objDim5.Value * 1000
Range("M15").Value = objDim6.Value * 1000
Next SpineXRotation

For ShoulderXRotation = -90 To 98 Step 18.8
Call objVariables.Edit("Left_Shoulder_X_Rotation", ShoulderXRotation)
Range("H15").Value = objDim.Value * 1000
Range("I15").Value = objDim2.Value * 1000
Range("J15").Value = objDim3.Value * 1000
Range("K15").Value = objDim4.Value * 1000
Range("L15").Value = objDim5.Value * 1000
Range("M15").Value = objDim6.Value * 1000
Next ShoulderXRotation
End Sub

Does someone have an idea? Thanks in advance.

Regards,

Tom
 
Replies continue below

Recommended for you

Hi,

I've changed some items and did a short test (without Excel)
and the variables got updated:

================
Private Sub CommandButton3_Click()
'
'On Error Resume Next ' <--- will leave the error handling to you!
' ' therefore you didn't see any errors ;-)
'
' typical coding after a statement that might fail
' if err.number <> 0 then
' [...]
' endif

'Declare the program variables
Dim HipXRotation As Double ' use doubles for SE's values here
Dim ShoulderXRotation As Double
Dim SpineXRotation As Double
Dim objApp As SolidEdgeFramework.Application ' do an early bindng here
Dim objVariables As Object
Dim objDim As Object
Dim objDim2 As Object
Dim objDim3 As Object
Dim objDim4 As Object
Dim objDim5 As Object
Dim objDim6 As Object

'Connect to a running instance of Solid Edge
Set objApp = GetObject(, "SolidEdge.Application") ' not ..Framework !

'Access the Variables collection.
' the Occurrences.Item(2) returns an occurrence and to get to the
' related object use OccurrenceDocument and optional check it's type
Set objVariables = objApp.ActiveDocument.Occurrences.Item(2).OccurrenceDocument.Variables
[...]

==================

HTH

dy
 
Allright, thanks donyoung!

I haven't been able to test it yet, but I sure will! I'm kind of new to this stuff, so that explains the 'errors'.

Thanks again and I'll let you know if it worked!

Regards,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor