FREE Thai Alphabet Game F for Android

FREE Thai Alphabet Game F for Android
Free app for learning Thai Alphabet on Play Store
Showing posts with label microsoft excel vba. Show all posts
Showing posts with label microsoft excel vba. Show all posts

Motion Simulation in Solid Edge using sketches together with Microsoft Excel VBA Programming Part III


In previous example, I showed how to control variables in Solid Edge sketch using direct link to excel spreadsheet. In this example, I am going to show how to use VBA (Visual Basic for Application) in excel to control the variables in Solid Edge sketch.

1) Create new file in Microsoft Excel

2) Press Alt+F11 to enter Microsoft Visual Basic windows as shown below



3) Right click in Project Explorer at new file name (in this example, new excel file name = Book2) > Insert > Module



4) To make Solid Edge type libraries available to the Visual Basic Object Browser, click References on the Project menu. On the References dialog box, select the Solid Edge libraries you want to access.



All variable automation is accessed through the Variables collection and Variable objects. The Variables collection serves two purposes: it allows you to create and access variable objects, and it allows you to work with dimensions as variables.

Note: When debugging programs that interact with the Variable Table, it helps to have the Variable Table displayed while stepping through the program. The Variable Table shows the results as they are executed.

5) Write the following code into VBA code area as shown below,


You can copy & paste the following code to your excel VBA.

' =================================================================
' Example of using VBA code to control variables in Solid Edge document
' By AkeBlogger
' http://mechanical-design-handbook.blogspot.com/
' =================================================================

Sub Simulate()
On Error Resume Next

'Declare the program variables.
Dim iAngle As Single
Dim objApp As Object
Dim objVariables As Object
Dim objVariable As Object

'------------------------------------------------------------------
' Checking for the active document
Set objApp = GetObject(, "SolidEdge.Application")
If Err Then
MsgBox "You must open 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")
'Access the Variables collection.
Set objVariables = objApp.ActiveDocument.Variables
End If

'SIMULATION STARTS!
For iAngle = 0 To 360 Step 2
' Changing Cam_angle from 0, 2, 4, ..., 360 deg.
Call objVariables.Edit("Cam_angle", iAngle)

Next iAngle

End Sub

6) Open Solid Edge file from previous example and delete formula in Variables Table as shown below, because in this example we will control the variable (dimension) using VBA code directly.



7) We are now ready for simulation. Resize VBA Windows as shown below then click run to see the result.



Watch the following video for the actual result!




Read more info about Mechanical Engineering Design Handbook

Motion Simulation in Solid Edge using sketches together with Microsoft Excel VBA Programming Part I


Solid Edge has a very useful application called "Motion" which allows a user to simulate the movement of mechanical parts. This enables the machine designers to test and make sure that the movement of their mechanism is the same as they expect before manufacturing parts. This helps save a lot of money.

However, instead of using "Motion" application, I would like to show you how to simulate the motion of mechanical parts using a sketch in Solid Edge together with Microsoft Excel.

Why?

Most of the time, I started my mechanical design with the concept and layout using sketches. If we could simulate the motion of mechanical parts in a sketch, it would help me a lot.

I got this idea when I was playing with sketches and constraints in Solid Edge. Solid Edge allows us to change the dimensions easily by just rotating the mouse wheel.

Watch the following video to see how easy to make the motion in sketch.



So what I have to do is just to have Microsoft Excel VBA changes the dimensional values in Solid Edge sketch.

Here is the results of this idea ...



Let's see how to do this in the next post...


Read more info about Mechanical Engineering Design Handbook