The following is the example GRIP program.
$$
$$ GRIP calling User Function sample program
$$
$$ This program uses GRIP interaction to gather the information
$$ needed to create a simple hole. It then passes this data to an
$$ internal UG/Open API program which creates the simple
$$ hole and reports back errors.$$
$$ This interaction prompts for the specification of:
$$ IDENT : the face on which the hole is created,
$$ and an optional through face.$$ PARAM : the diameter, depth, angle, and absolute position of the
$$ hole.$$
$$ The direction of the hole is always perpendicular to the face.$$$$ Declarationsgripsw / declrv
entity / hfaces(2)
number / poswcs(3), posabs(3), dirwcs(3), dirabs(3), facdat(20),$
usresp
number / dianum, depnum, angnum
string / diastr(132), depstr(132), angstr(132), errstr(132)$$ Initialize defaultsstep0:
dianum = 0.25
depnum = 0.25
angnum = 0.00
poswcs(1) = 0.00
poswcs(2) = 0.00
poswcs(3) = 0.00$$ Select the placement facestep1:
hfaces(1) = &nulent
hfaces(2) = &nulent
mask / 71
ident / 'Select Placement Face [,Thru Face]', hfaces, usresp
jump / halt:, halt:, usresp$$ Specify the simple hole parametersstep2:
param / 'Specify Simple Hole Parameters', $
'Diameter = ', dianum, $
'Depth = ', depnum, $
'Angle = ', angnum, $
'Position(xc) = ', poswcs(1), $
'Position(yc) = ', poswcs(2), $
'Position(zc) = ', poswcs(3), usresp
jump / step1:, halt:, usresp$$ Convert data and determine the hole directionstep3:
posabs = map / poswcs, from, &wcs, to, &abs
diastr = fstr(dianum)
depstr = fstr(depnum)
angstr = fstr(angnum)
facdat = spropf( hfaces(1), 0.5, 0.5 )
dirwcs(1) = -facdat(16)
dirwcs(2) = -facdat(17)
dirwcs(3) = -facdat(18)
dirwcs = poswcs + dirwcs
dirabs = map / dirwcs, from, &wcs, to, &abs
dirabs = dirabs - posabs$$ Create the simple holestep4:
errstr = 'Unknown error.'
grargs / posabs, dirabs, diastr, depstr, angstr, hfaces, errstr
xspawn / ufun, 'demo_grip_call_ufun'$$ Inform user of any errorsstep5:
ifthen / errstr <> 'No error.'
eject / print
print / 'The hole was not added to the face.'
print / ' Reason: ' + errstr
endif$$ Donehalt:
halt
C User Function Example
The following is the example User Function program. You invoke this program from a GRIP program and then receive from it the data required to create a simple hole. This program returns a string indicating any errors that may occur.
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_modl.h>#define GRIP_ARG_COUNT 7extern void ufusr (char *param, int *retcod, int param_len)
{/* Declarations */tag_t hole_faces[2], hole_feature;
double hole_position[3], hole_direction[3];
char hole_diameter[133], hole_depth[133];
char hole_angle[133], error_string[133];
UF_args_t grip_arg_list[GRIP_ARG_COUNT];
int error_status;/* Define the argument list for GRIP calling User Function */grip_arg_list[0].type = UF_TYPE_DOUBLE_ARRAY;
grip_arg_list[0].length = 3;
grip_arg_list[0].address = hole_position;grip_arg_list[1].type = UF_TYPE_DOUBLE_ARRAY;
grip_arg_list[1].length = 3;
grip_arg_list[1].address = hole_direction;grip_arg_list[2].type = UF_TYPE_CHAR;
grip_arg_list[2].length = 0;
grip_arg_list[2].address = hole_diameter;grip_arg_list[3].type = UF_TYPE_CHAR;
grip_arg_list[3].length = 0;
grip_arg_list[3].address = hole_depth;grip_arg_list[4].type = UF_TYPE_CHAR;
grip_arg_list[4].length = 0;
grip_arg_list[4].address = hole_angle;grip_arg_list[5].type = UF_TYPE_TAG_T_ARRAY;
grip_arg_list[5].length = 2;
grip_arg_list[5].address = hole_faces;grip_arg_list[6].type = UF_TYPE_CHAR;
grip_arg_list[6].length = 0;
grip_arg_list[6].address = error_string;/* Initialize User Function */UF_initialize();/* Update the local arguments with the contents from the GRIP variables */error_status = UF_ask_grip_args (GRIP_ARG_COUNT, grip_arg_list);
if (error_status != 0)
{UF_get_fail_message (error_status, error_string);
fprintf (stderr, "UF_ask_grip_args failed due to: %s\n", error_string);
return;}/* Create the simple hole */error_status = UF_MODL_create_simple_hole (hole_position, hole_direction,
hole_diameter, hole_depth,
hole_angle, hole_faces[0],
hole_faces[1], &hole_feature);if (error_status != 0)
UF_get_fail_message (error_status, error_string);
else
strcpy (error_string, "No error.");/* Update the GRIP arguments with the contents from the local variables */error_status = UF_set_grip_args (GRIP_ARG_COUNT, grip_arg_list);
if (error_status != 0)
{
UF_get_fail_message (error_status, error_string);
fprintf (stderr, "UF_set_grip_args failed due to: %s\n", error_string);
return;
}/* Terminate User Function */UF_terminate();
}