## Sunday, 8 March 2015

### Making of SE Equation Curve Part3

...continued from part 2

Initialize the Expression Parser using the New keyword and add a variable x as below: This necessitates that only the letter x be used when specifying the equation.

Following this, create a new list of doubles to store the x and y values of the points to be generated for the curve: The For loop by default uses 1 as increment value but it is possible to use a different one using the Step keyword as seen above. The Step value was earlier calculated using the range difference divided by the no. of points on curve.

For each value of x, the corresponding value of y is calculated as per the equation. Both the x and y values are added to the flat list called CurvePoints since this suits the array that is passed as an argument to the spline creation API of Solid Edge.

If there are at least 3 points generated, then the DrawEquationCurve function is called: Inside the DrawEquationCurve function, the Active Sketch is stored is the active document is Part and the sheet if the current document is a Draft. The BSplines collection belong to these respective holders in the respective documents: Solid Edge always stores measurement values in internal units irrespective of the display or document units used. The unit-less values needs to be converted into something that Solid Edge can make sense of. These internal units are caleld the database units.

oUoM is the Units of Measure object. It's ParseUnit method uses any valid unit
string to return the corresponding database units as per the document.

The oUoM i.e. units if measure will be different for a Draft and a Part documents hence they are assigned values inside the respective If statement.

The GetValueInDocumentUnits function does this conversion: The subsequent code is common irrespective of the document type. An array of Doubles is created from the List of Doubles which is a valid argument for the AddByPoints method used for creating the BSpline i.e. the equation curve.

The first argument to the AddByPoints method is the order of the curve which is 1 greater than the degree of the curve. The second argument is the count of points which should be told before hand, hence the list size or count is divided by 2 to specify the number of points.The third argument is the points array itself which is a flat list of x and y coordinates of the points on the BSpline i.e. the Equation Curve.

The curve is created at the origin if the starting point of x is 0 and the corresponding y value also evaluates to zero.

The On Error Resume Next statement leaves no scope for an error trapping especially when the equation could not be evaluated by the Parser library. For example square root of a negative number will throw an exception but it is not caught anywhere and the curve is simply not drawn.

This concludes the coding part. For details on how to integrate this macro into Solid Edge ribbon and the source code and program downloads, continue to Part 4...

Index of all Solid Edge Tips, Tutorials and Videos...