FlexPro offers you the option of programming your own functions in FPScript or Python. You can create these as you would regular formulas; however, you need to use the Arguments statement in the first code line to declare arguments for the function. This turns the formula into a function which must be supplied with arguments when called. You can also save these types of functions in template databases, thus expanding the number of FPScript functions.
Python is part of FlexPro in the Professional Edition.
An example
a) FPScript
An FPScript function Sum would look like this, for example:
Arguments a, b
a + b
This function can now be called in a different formula:
Sum(1 V, 2 mV)
or
Sum(DataSet1, DataSet2)
The arguments a and b serve as formal parameters to represent the arguments passed. You can use these just like local variables.
You can omit any items in the argument list when calling the function. These items then have an empty data type:
Sum( , 2) is therefore the equivalent to Sum(Empty, 2) and Sum(1) is equivalent to Sum(1, Empty).
Please note that in the function Sum no Return statement is necessary. The result of the last statement in a formula is automatically used as the result of the formula.
b) Python
The same example in Python looks slightly different. In Python, you must explicitly assign the calculation result to the result value of the function: The arguments are passed as flexpro.Data objects with value and unit:
arguments a, b
this.data = a.value + b.value
If you want to pass the result with a unit, the code looks like this:
arguments a, b
this.data = flexpro.Data(a.value + b.value, a.unit)
An FPScript or Python function is called in a Python formula as follows:
flexrpro.call('Sum', flexpro.Data(1, 'V'), flexpro.Data(2, 'V'))
Please note that Python does not check or adjust the unit. If, for example, a has the unit V and b has the unit mV, the calculated result is incorrect.
Saving FPScript or Python Functions as a Template
If you save an FPScript function in a template database, you can use it in your project databases as you would a built-in function. To save a function, use a wizard in which you can specify a comment for each argument and define the permitted data types and structures. Functions saved in this way
•are displayed in the wizard for inserting a function into a formula in the Customized category,
•are supported by the FPScript Editor's Assistance feature,
•support optional arguments with default values, and
•when called, automatically check arguments passed for permitted data types and data structures.
Sharing FPScript Functions
FlexPro Professional and FlexPro Developer Suite support shared template databases. You can share FPScript functions that you save in this type of template database with your colleagues. Use the shared template databases to create function libraries for your department or company.
See Also
Custom FPScript Functions Tutorial