Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Engineering

PML Functions and Methods

  • Last UpdatedOct 29, 2024
  • 2 minute read

Functions and methods may optionally have arguments that can be used to return values.

Arguments have a data type which is specified in the function or method definition and they are checked when the function or method is called. An argument may be one of the built-in types REAL, STRING or BOOLEAN; an ARRAY; a built-in object or a User-defined object or specified as ANY.

Functions and methods can optionally return values as their results. Functions that do not return values are known as PML Procedures (see PML Procedures).

Here is a definition of a PML function that has two REAL arguments. It also has a REAL return value, as shown by the final 'is REAL':

define function !!Area( !Length is REAL, !Width is REAL )is REAL

Inside a function, the arguments are referenced just as if they were local PML variables. The RETURN keyword is used to specify the variable that stores the return value:

define function !!Area( !Length is REAL, !Width is REAL ) is REAL

 !Area = !Length * !Width

 return !Area

endfunction

When a PML function is called, all the PML variables passed as arguments must already exist.

In addition, arguments used for input must have a value, which could be a constant, when the function is called:

define function !!LengthOfName(!Name is STRING) is REAL

 !TidyName = !Name.trim()

 return !TidyName.Length()

endfunction

The function is called to set the value of a variable '!Length' as follows:

!Length = !!LengthOfName( '   FRED   ')

Here ' FRED ' is a STRING constant passed as an argument. You could rewrite this function so that it returns its results by changing its arguments. The output argument '!Length' will be set to the value required when the function is called:

define function !!LengthAndTrim(!Name is STRING, !Length is REAL)

 !Name = !Name.Trim()

 !Length = !Name.Length()

endfunction

Arguments used for output must exist prior to the call and one that is also used as an input argument must also have a value:

!Name = ' FRED '

!Length = REAL()

The function is called to set the value of a variable '!Length' as follows:

!!LengthAndTrim(' FRED ', !Length)

When an argument value is changed within a PML function its value outside the function is also changed.

The following call is incorrect, as the function cannot modify a constant:

!!LengthAndTrim('  FRED  ' ,4 )

$* WRONG

A PML function returning a value may be used wherever an expression or PML variable can be used, for example, this call to the !Area function defined above:

!PartLength = 7

!PartWidth = 6

!SurfaceArea = !!Area(!PartLength, !PartWidth)

Note:
You cannot switch to a different AVEVA E3D module if a PML function is running. Use EXIT to exit from the function if it has failed to complete.

TitleResults for “How to create a CRG?”Also Available in