![]() SeGuruCool The Largest Independant Solid Edge Resource Outside UGS |
www.oocities.org/SeGuruCool ![]() |
|
|
In this this tutorial, you learn :
It is assumed that you are familiar with the basics of Solid Edge and VB. | ![]() |
Define the Goal We want to control parameters of a shaft with a keyway as shown in figure. Start with creating the part. Make a circle in the x-z plane and protrude it. | ![]() |
The Constraints For the keyway cutout, sketch a rectangle as shown. Connect ![]() See figure (brown arrows). This ensures symmetry for the keyway slot both horizontally and vertically. Also, the keyway slot stays with the shaft all the time, i.e. even when the diameter of the shaft changes, we need not worry about the position of the keyway from the center of shaft. | ![]() |
The Cutout Complete the cutout and do not make it through. We want to control the length of the keyway as a parameter. Check the part consistency by modifying the width and height of the cutout (keyway) and the diameter of the shaft. Two Connect contraints have done the trick. | ![]() |
Setup the Variables Rename the shaft diameter variable to ShaftDia as shown in figure. Similarly, ShaftLength, KeyWidth, KeyDepth and KeyLength. Save the part and quit Solid Edge. | ![]() |
Coding Time Start a Standard EXE project. | ![]() |
The Form Cook up a form with controls as shown in figure. The Sub for the Update button will handle the meaty part of the code. | ![]() |
Involve Solid Edge Click Project > References and include references to Solid Edge FrameWork and Part type libraries. See figure. | ![]() |
Start Coding Start coding by opting to declare variables explicitly. Option Explicit Dim strFName As String Dim objApp As SolidEdgeFramework.Application Dim objDoc As SolidEdgePart.PartDocument Dim objVars As VariablesThe string strFName holds the filename of the Solid Edge part file containing the Shaft. Also, declare object variables for the Solid Edge application, the part document and the variables collection. Download [ 32 kb ] VB source code files for this tutorial (Also contains the part file). |
More Variables The datatype for the paramters to control is string and not numeric. Dim strFName As String Dim ShaftDia As String Dim ShaftLength As String Dim KeyWidth As String Dim KeyDepth As String Dim KeyLength As StringAlso, code the textboxes to directly assign their text property to these variables, and not the value of the textboxes. This is shown below : Private Sub txtShaftDia_Change() ShaftDia = txtShaftDia.Text End Sub |
Go for It The Click event of the cmdUpdate button calls the UpdatePart Public Function Private Sub cmdUpdate_Click() Call UpdatePart End Sub Public Function UpdatePart() strFName = App.Path & "\Shaft_With_KeyWay.par" On Error Resume Next Set objApp = GetObject(, "SolidEdge.Application") If Err Then Err.Clear Set objApp = CreateObject("SolidEdge.Application") Set objDoc = objApp.Documents.Open(strFName) End If objApp.DisplayAlerts = False objApp.Visible = FalseFirst strFName is assigned the filename. In this case, the part file Shaft_With_KeyWay.par sits in the same folder as this project, hence, App.path. Also note the leading Slash ( \ ) Next we try to connect to a running instance of Solid Edge using GetObject. If SE is not running, fire it up using CreateObject. Open the part file and assign it to ObjDoc and keep SE invisible throughout. If you keep objApp.Visible = True, you can see the things in action. But that would be a innocent way to stare at things. Watch it happening - like a pro Before you click the Update button on the form, right click the taskbar (Win 2000 only) and select Task manager.... In the task manager dialog, take the Processes tab and click on the Image Name column header twice ( do not double-click ) to list the processes alphabetically. Edge.exe should be one of them, but only until the objects are set to Nothing. You can also see the Mem Usage figure flare up at key time intervals, especially when the part document is opened and the program is updating the variables. |
The Meaty Part objVars is assigned the variables collection from the variable table of Solid Edge part file. Set objVars = objDoc.Variables objVars.Edit "ShaftDia", ShaftDia objVars.Edit "ShaftLength", ShaftLength objVars.Edit "KeyDepth", KeyDepth objVars.Edit "KeyWidth", KeyWidth objVars.Edit "KeyLength", KeyLengthChange the value of the variables using the Edit method of the objVars collection object. Here the first "ShaftDia" (in double quotes) is the name of the variable from the variable table of the part file. The second ShaftDia (without double quotes) is the string variable from the txtShaftDia textbox. |
Scavenging The Scavenging stuff in any Solid Edge - VB customization thing should be taken seriously. Call objDoc.Save Call objDoc.Close Call objApp.Quit Set objApp = Nothing Set objDoc = Nothing Set objVars = Nothing MsgBox "Done !", vbExclamation End Function |
Tushar Suradkar ![]() |