KF Application Development Environment

This is a recommendation for configuring a Microsoft Windows computer for developing and debugging Knowledge Fusion applications.  The ideas presented here are not meant to be applied to production machines.  Since most KF application developers have multiple projects on their computer, this recommendation addresses the need to isolate the files of each application and to turn each application on or off independently.  This recommendation includes the following features:

File Types Related to KF

On non-Windows platforms, all of these file extensions must be lower case.

Extension

Description

DLG

Open User Interface Styler dialog file

BMP

Windows bitmap image file

UBM

NX bitmap file

DLL

File that contains functions written in C using NX Open, called from KF with the CFUNC function, compiled for Windows platform.

MEN

Menu customization file

TBR

NX tool bar definition file

DFA

Knowledge Fusion ASCII definition file for classes, functions, and methods

PRT

NX part file containing a binary, read-only copy of a one or more DFA files.


Launch NX with a BAT file

Most application developers have multiple versions of NX on their machine.  Launching NX with a BAT file is recommended on a Windows development machine so that environment variables can be set uniquely for each version of NX.

@echo off

echo Starting NX

rem ----------------------------------------------------------------------
rem  This causes env variables set in this file to affect only this session
rem ----------------------------------------------------------------------

setlocal

rem ----------------------------------------------------------------------
rem NX installation directory:
rem   If you have only one version of NX installed at a time, and if the
rem   desired version of NX starts OK without these variables, then don't 
rem   set them here.  If you use the variables, be sure the directory shown
rem   here is correct for your machine.
rem ----------------------------------------------------------------------

    set UGII_BASE_DIR=c:\NX5
    set UGII_ROOT_DIR=%UGII_BASE_DIR%\ugii\

rem ----------------------------------------------------------------------
rem  Default directory:
rem  This will be the default directory for actions like opening files.
rem ----------------------------------------------------------------------

    cd /d  c:\data

rem ----------------------------------------------------------------------
rem Set up menuscript customization directory:
rem   Set this variable to point to a text file, which contains a list of 
rem   fully qualified folder names. Create a folder for each application, 
rem   a folder for files that are common to all applications and a folder 
rem   for experimental files. Each of these folders should contain the 
rem   following sub-folders: "application", "dfa". Rename the folder dfa 
rem   to something like dfa1 to allow you to reload dfa files during 
rem   development. Other folders could be added such as "C" for NX Open 
rem   source, "help_src" for help file source, "data" for misc data such 
rem   as spreadsheets and help files, "docs" for development documents, 
rem   "test_data", "bitmaps", etc.
rem ----------------------------------------------------------------------

    set UGII_CUSTOM_DIRECTORY_FILE=c:\data\bat\custom_dirs.dat

rem ----------------------------------------------------------------------
rem Customize customer defaults:
rem   This is not needed for newer versions of NX that use DPX and DPV
rem   files.
rem   To customize your NX "customer defaults", you could edit the 
rem   ug_metric.def file where NX is installed, but you would lose those
rem   edits every time you installed a new version of NX. In the same 
rem   folder as this BAT file, there is a ".def" that contains only those 
rem   parameters that you want to change. Change this file as needed.
rem   The exact filename is identified by SITE_EDITS below. The code 
rem   below will merge yoursite edit file with the master copy of 
rem   ug_metric.def before launching NX.
rem ----------------------------------------------------------------------

    set BATDIR=%~dp0%
    set CUSTOM_EDITS_FILE=%BATDIR%\nx1_cust_def_changes.def
    set MASTER=%UGII_BASE_DIR%\ugii\ug_metric.def
    set UGII_DEFAULTS_FILE=%HOME%\.ug_metric.def
    if exist %UGII_DEFAULTS_FILE% attrib -H -R %UGII_DEFAULTS_FILE%
    copy %MASTER% + %CUSTOM_EDITS_FILE% %UGII_DEFAULTS_FILE% > NUL
    attrib +H %UGII_DEFAULTS_FILE%

rem ----------------------------------------------------------------------
rem  If UGII_KEEP_SYSTEM_LOG is not set, then NX will delete the syslog
rem  when it is exited.  If you set this variable, then you should also
rem  have an automated means of cleaning out the old syslog files.
rem ----------------------------------------------------------------------

rem    set UGII_KEEP_SYSTEM_LOG=1

rem ----------------------------------------------------------------------
rem  Debug option.  Display all attributes in KF Navigator
rem ----------------------------------------------------------------------

rem    set UGII_KF_SHOW_ALL_RULES=1

rem -------------------------------------
rem  Launch NX
rem -------------------------------------

    start "NX Console" %UGII_BASE_DIR%\ugii\ugraf.exe

:BOTTOM

Having the BAT file, you may want to create a shortcut to the BAT file on your Windows Start Menu or Desktop.  To create a shortcut, find the BAT file using Windows Explorer (My Computer), right-click on the BAT file and choose "Create Shortcut".  Locate the newly created shortcut file and rename it from "Shortcut to start_nx.bat" to a name that you prefer.  Then move the shortcut file to your desktop, Quick-Launch Toolbar or the Start Menu.

KF Project Organization

Organize your KF application files into project folders that can quickly be packaged for release without much effort.  Create a project folder for each KF application, a folder for KF files that are common to all KF applications, and a folder for experimental DFA files.  The following figure illustrates an example of this configuration.

kf_projects — Collects all KF projects

Driveline — Application Folder

Exhaust — Application Folder

C — NX Open Source for KF C functions

deploy — Collects Files to be deployed (1)

application — BMP, UBM, DLL files

data — Application specific data files (XLS, CHM, and so on)

dfa_1 — DFA, DLG files (2)

startup — MEN, TBR files

docs — Development documents

help src — Help file source

TestData — Other folders as needed

KF_common — Files common to all applications

Temp — Experimental DFA files

Project directory structure


  1. The deploy folder collects all of the files that are to be deployed to the run-time environment.  This should include the following file types: DFA, DLG, BMP, UBM, DLL, MEN, TBR, and supporting data files such as help files and database files.  You will usually not want to deploy C source code, help source, test data and development documentation to the user community.

  2. In a production environment, the dfa_1 folder should be renamed to dfa .  If it is named dfa, NX identifies it as a system DFA folder and automatically loads the DFA files in that folder and in its sub-folders.  But you don't want that in a development environment, because the Reload All and the Check DFA operations cannot work if the folder is named dfa.  That would make debugging syntax errors more difficult.  In a development environment, name the folder something like dfa_1 to prevent NX from identifying it as a system DFA folder.  Then you must add the dfa_1 folder name to the KF search directories using Knowledge Fusion Preferences.  When you're ready to package the application for release, rename the folder to dfa before creating the package.

Location of DLG Files

Note that DLG files can go in the application directory and/or the dfa directory.  NX Open documentation recommends putting DLG files in the application folder, however, keeping the DLG file in the same folder as the assocaited DFA file may be more desireable.

DFA Search Directories

If you name a DFA folder dfa, and if it resides under a custom folder listed in the %UGII_CUSTOM_DIRECTORY_FILE% file, then the system automatically loads the DFA files found in the dfa folder and in all sub-folders under that.  In this case, you do not have to add this DFA folder to the KF Search Directory list under KF Preferences.  If you name a DFA folder something other than dfa, then the fully qualified folder name must be manually added to the KF search directory list under KF Preferences in order of for that application to work.

Application Development

DFA files that were previously placed in a DFA folder in an application can now be reside in Teamcenter Engineering.

Environment Variables

UGII_BASE_DIR and UGII_ROOT_DIR may or may not be required in your BAT file.  If the desired version of UG starts without setting these variables, then you don't need to set them.

set UGII_BASE_DIR=c:\ugs190 set UGII_ROOT_DIR=%UGII_BASE_DIR%\ugii\

Set UGII_CUSTOM_DIRECTORY_FILE to point to a text file that contains the names of your project folders.  For example:

set UGII_CUSTOM_DIRECTORY_FILE=c:\data\bat\custom_dirs19.dat

The contents of this file is a list of fully qualified folder names that contain the subfolders application, startup and dfa.  Based on the figure above, the contents of this file might be:

C:\data\kf_projects\KF_common
C:\data\kf_projects\Exhaust\menufiles
C:\data\kf_projects\Driveline\menufiles
C:\data\kf_projects\Temp


Customer Defaults Settings

The customer defaults parameters are set in the Customer Defaults dialog box (In NX, choose File→Utilities→Customer Defaults→Knowledge Fusion→General→All.  The following KF parameters are handy:

Parameter

Description

Prefix for Object Names

Lets you to specify a prefix for the name of new Knowledge Fusion child rule objects. The prefix specified has an ascending number appended. If this option is not set, then no default name is supplied when a child rule object is created.

Prefix for Attribute Names

Lets you to specify a prefix for the name of new Knowledge Fusion attributes. The prefix specified has an ascending number appended. If this option is not set, then no default name is supplied when an attribute is created.

Modifiable Search Directories

Determines whether or not the DFA search directories are to be read from the registry. When selected, DFA search directories can be registered from either the DFA Manager or from Preferences→Knowledge Fusion.

The toggle's off state means that the search directories are to be read from the environment variable UGII_KF_USER_CLASS_DIR and no modifications of the search directories are permitted.


Menuscript (toolbar icons)

A toolbar with icon buttons can be set up to launch a Knowledge Fusion application (that has an Open User Interface Styler dialog).  For more details on this, see the Help for Menuscript.

Here is an example:

Create a file with a .MEN extension something like this and put it in the startup folder shown above.  In this example, a new menu titled "Driveline" will be inserted into the UG "Edit" menu after the Knowledge Fusion -> "KF Debug" menu item.  When this menu is chosen, the application km_driveline.dfa runs.

VERSION 120 
EDIT UG_GATEWAY_MAIN_MENUBAR
AFTER UG_KBE_DEBUG
SEPARATOR
BUTTON MY_DRIVELINE
LABEL DriveLine
ACTIONS km_driveline.dfa
END_OF_AFTER

Create a file with a .TBR extension something like this and put it in the same startup folder.  This example creates a new toolbar titled "Knowledge Fusion Applications" with one button titled "Driveline".  (Other buttons could be added.)  The button displays the bitmap image "DriveLine_TBR.bmp", which resides in one of the application directories shown above.  Clicking this button is like choosing the MY_DRIVELINE menu defined above.

TITLE Knowledge Fusion Applications 
VERSION 160
BUTTON MY_DRIVELINE
LABEL DriveLine
BITMAP DriveLine_TBR.bmp