Writing Open API Programs


 
In general, NX Manager Open C API programs are written in a similar manner to standard NX Open C API programs. There are, however, a few minor differences that should be taken into account before attempting to design an Open C API program to run in NX Manager mode.
 
You can compile and link your programs in exactly the same way whether or not you plan to use them with NX Manager. The include file uf_ugmgr.h is now included as part of the standard Open C kit.
 
Initialization in External Open C API
 
When running in external Open C API, you can choose 2 ways to initialize your program.
 
You can force the program to run in NX Manager mode, by calling the special initialization function UF_UGMGR_initialize. This initializes NX Manager, and the program then runs in NX Manager mode with a background server process.
 
You can write the program so that it works correctly whether running in NX Manager mode or not, and allow Open C API initialization to decide which mode to run it in. In this case, NX Manager is initialized only if the the switch -pim=yes was specified on the command line.
 
To achieve this effect, you should initialize your program by calling UF_initialize immediately followed by a call to uc4624. You must pass the command line arguments (argc and argv) to uc4624.
 
Here is a short example of a external Open C API program which runs in NX Manager mode if "-pim=yes" appears on the command line, and in standard NX if it is omitted.
 
To run it in standard NX you might type:
 
<program-name> -part=newpart.prt
 
To run it in NX Manager mode you might type:
 
<program-name> -pim=yes -part=@DB/newpart/A
 
Note:  The part referenced above needs to be a new part that does not already exist in the database and a valid string is used for the revision.
 /* Sample program to show how to initialize the
program, open a new part by reading the arguments
passed in on the command line and save the part  */
 
#include<stdio.h>
#include <uf.h>
#include <uf_cfi.h>
#include <uf_part.h>
 
extern int main (int argc, char, **argv)
{
  char part_name[133];
  int ifail;
  tag_t tag;
 
  ifail = UF_initialize();
  if (ifail != 0)
  {
    printf("ERROR: Failed to initialize Open C API\n");
    return;
  }
 
  ifail = uc4624(0, argc, argv);
  if (ifail < 0)
  {
    printf("ERROR: Failed to pass command line args\n");
    return;
  }
 
  ifail = uc4620("PART", part_name);
  if (ifail < 0)
  {
    printf("ERROR: Failed to get part filename\n");
    return;
  }
 
  ifail = UF_PART_new(part_name, 1, &tag);
  if (ifail != 0)
  {
    printf("ERROR: Failed to create part\n");
    return;
  }
 
  ifail = UF_PART_save();
  if (ifail != 0)
  {
    printf("ERROR: Failed to save part\n");
    exit(1);
  }
 
   UF_terminate();
}

 
Initialization in Internal Open C API
 
In internal Open C API, your program runs in the same mode as the NX session it is part of. You cannot change this. You should initialize such programs for NX Manager exactly as when running in standard NX.
 
Writing Programs for Use With and Without NX Manager
 
Many Open C API programs are equally applicable in either standard or NX Manager mode. You can write such programs so that they can be used in either mode.
 
An external Open C API program can be run in either mode by specifying or omitting the -pim=yes command line keyword when running it.
 
For initialization, follow the instructions above, then write scripts to handle the command line keyword for external programs, or tell your users how to use it.
 
Part file names on the command line for use in NX Manager mode should follow the Command Line Input format described below. You can convert these into the internal format using the routine UF_UGMGR_convert_name_from_cli before passing them to Open C API routines. A few routines carry out this conversion automatically:
 
An existing external Open C API program which makes no assumptions about the format of part filenames and does not pass them to any routine other than these, is likely to work with NX Manager without any change.
 
An internal program runs in whichever mode the interactive NX session is using. The UF_UI routines which allow you to prompt the user for part filenames display the NX Manager part selection dialog when running in NX Manager mode, and the normal file selection box when running standard NX. The part filenames returned to your program by these routines are internal format NX Manager part filenames when in NX Manager mode, and OS filenames in standard NX. In either case, they can be passed to any Open C API routine without conversion.
 
Checking for an active NX Manager session
 
You can use UF_is_ugmanager_active to check for an active NX Manager session. This routine returns True if NX Manager is running, False otherwise.
 
Running External Open C API
 
You run your NX Manager external Open C API program exactly as any other external Open C API program, except that you may give some optional command line arguments:
 
-pim=yes  if present, signals to a program that it should run in NX Manager mode (see Initialization above) 
-user 
 
-password 
 
-group 
same purpose, syntax and possible values as when starting interactive NX Manager from the command line (see the NX Manager user manual)