×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA & Assemblies

VBA & Assemblies

VBA & Assemblies

(OP)
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

RE: VBA & Assemblies

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 winky smile
'
' 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

RE: VBA & Assemblies

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources