top of page

Using functions in PcDmis

  • Writer: Metis
    Metis
  • Oct 31, 2023
  • 2 min read

If you need to carry out a complex calculation or operation multiple times in your program, it might be beneficial to create a function at the top of the program that can be used over and over again.


What is a Function?

A function takes any number of inputs (parameters), performs an operation on them, and returns the result.


What are the benefits of using functions?

  • Functions make your program tidier and easy to read.

  • Less typing, less chance of a typo when doing calculations.

  • The feeling of accomplishment and satisfaction when it works :)

How do I create functions in PcDmis?

In PcDmis, functions are assigned to variables using the FUNCTION function in an assignment command. Below is a very basic function that takes a feature (e.g. Auto vector point), as in input, and outputs the features deviations from nominal (which is calculated from subtracting the theoretical valued from the actual values).

ASSIGN/GETDEV=FUNCTION((V),V.XYZ-V.TXYZ)
Function Name

The name of the function in the example above is GETDEV, the name will be used when you want to use the function further down in your program.

Function Inputs

Inside the parenthesis are inputs, and you can have any number of inputs, e.g. V1,V2. In the above example the function has just one input which I've named V. The inputs will be used in the functions expression.

Function Express

After the inputs is the expression specifying what to do with the inputs. In this case the expression calculates the deviation using the actual and theoretical values of the input feature, V.XYZ-V.TXYZ. Note that the expression only uses variables from the input.

You might find that your expression exceeds the maximum character limit, in which case you might need to split a function up into multiple functions (an example of this can be found further down),


How do I use my function?

To use the above function anywhere in my program, I would simply use it as follows:

GETDEV(PNT_1.ALL)

This could be used in another command or assigned to another variable like this:

ASSIGN/RESULT=GETDEV(PNT_1.ALL)

Note that I used the .ALL extension with my feature, this ensures that all the data elements of the feature is being passed to the function so that the function can use them.


Re-using functions

You might find that you'll use use the same functions in most of your programs. To save time you can have a 'new program' template which contains all of your most used functions. To keep things tidy it's good to group them so that they can be hidden like in the example below.

FUNCTIONS  =GROUP/SHOWALLPARAMS=YES
  $$ NO,
              FUNCTION GETDEV(V): GETS THE DEVIATION VALUES OF A POINT
              V = FEATURE
              GETDEV(PNT_1.ALL)
              
              ASSIGN/GETDEV=FUNCTION((V),V.XYZ-V.TXYZ)
  $$ NO,
              FUNCTION RADVEC(V1,V2): GETS THE VECTOR OF A CHAMFER FACE FOR LINE CONSTRUCTION
              V1 = CHAMFER POINT
              V2 = AXIS
              RADVEC(PNT_1.ALL, "X")
              
              ASSIGN/RADVECX=FUNCTION((V),CROSS(CROSS(MPOINT(1,0,0),V.TIJK),V.TIJK))
              ASSIGN/RADVECY=FUNCTION((V),CROSS(CROSS(MPOINT(0,1,0),V.TIJK),V.TIJK))
              ASSIGN/RADVECZ=FUNCTION((V),CROSS(CROSS(MPOINT(0,0,1),V.TIJK),V.TIJK))
              ASSIGN/RADVEC=FUNCTION((V1,V2),IF(V2 == "X",RADVECX(V1),IF(V2 == "Y",RADVECY(V1),IF(V2 == "Z",RADVECZ(V1),0))))
            ENDGROUP/ID=FUNCTIONS

The example above, I've also included comments in the program describing what each of the two functions do, what inputs they expect, and an example of how to use them.


Have fun creating your own functions, please feel free to share your own creations in the comments below.

Recent Posts

See All

Comentários


Metis Metrology Ltd | Registered Company No: 13456045

Metis Metrology Ltd, Lychett House, 13 Freeland Park, Wareham Road, Poole, Dorset, BH16 6FA, United Kingdom

bottom of page
Privacy Policy