![]() 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. | ![]() |
Take the Cut 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. | ![]() |
Set up 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. | ![]() |
Define Relations We want the KeyDepth to be ( KeyWidth * 0.75 ) and KeyLength to be ( ShaftLength - 10 ) This can be easily done in the variable table itself. The current target is to illustrate how it can be achieved by writing BASIC or Visual Basic functions and use them in place of the formulae. This involves writing the function using notepad (save with .bas extension) or use Visual Basic. And further linking the function and its variables with the variable table variables. |
Start Coding In Visual Basic, start a Standard EXE project. Remove the form Form1 Right click the node Form1 in the Project Explorer and select Remove Form1 from the menu. Right click on Project1 in the Project Explorer and select Add > Module. Click Open in the dialog that appears. Save the module as Shaft.bas | ![]() |
The Meaty Part Type or copy-paste the following two functions in the nascent module. Save the module as Shaft.bas and quit VB. Function KeyLength(ByVal ShaftLength As Double) As Double KeyLength = ShaftLength - 10 End Function Function KeyDepth(ByVal KeyWidth As Double) As Double KeyDepth = KeyWidth * 0.75 End FunctionDownload shaft.bas file (32 kb) - also contains the part file. Note that similar fvariable names are used in both the variable table and the VB function. It does not mean however, that we are using the same variable. This is evident from the word ByVal. When ByVal is used before the argument variable name, VB copies the value of the variable by the same name from the variable table. Another method is to use ByRef which directly manipulates the variables. Here ByVal and ByRef are keywords of the BASIC language. Note : Do not confuse the shaft's keyway with the keywords - this is a completely different animal. |
Tell Solid Edge In Solid Edge, click in the formula area for KeyLength and then click the fx button. See figure. | ![]() |
The Function Wizard In the Function Wizard - Step 1 of 2 dialog that appears, click Visual Basic from the Function Category list and then click Next. Select the Shaft.bas file in the next dialog and click Open. | ![]() |
Step 1 of 2 In the Function Wizard - Step 1 of 2 dialog that appears again, select Shaft.KeyLength from the Function Name list and click next. Here, Shaft is the the name of the bas file Shaft.bas and KeyLength is the name of the function you types or copy-pasted earlier. | ![]() |
Step 2 of 2 In the Function Wizard - Step 2 of 2 dialog that appears type ShaftLength and click Finish. The word ShaftLength that we type here is the one from the variable table that goes as an argument to the VB function. Repeat the stuff for KeyDepth. Try changing the values for ShaftLength (this changes KeyLength) and KeyWidth (changes KeyDepth). | ![]() |
Epilogue In the variable table, the formula for KeyLength now looks like this : d:\Shaft.KeyLength( ShaftLength ) And for KeyDepth, like this : d:\Shaft.KeyDepth( KeyWidth ) |
Tushar Suradkar ![]() |