Developing Custom Pro/ENGINEER Applications using J-Link
By J.D. Felkins, FELCO Solutions
J-Link is a Java language toolkit of Pro/ENGINEER built on top of the Pro/TOOLKIT API (Application Programming Interface). This object-oriented programming tool provides a powerful way to expand, customize and automate the functionality of Pro/ENGINEER and Windchill.
For example, J-Link lets you create items with fly-out menus on the Pro/ENGINEEER interface like this:
You can also replace mapkeys using the J-Link API. This allows seamless Pro/ENGINEER upgrades because the J-Link API is not dependent on a menu pick or a recording. A pull- down menu can preserve the real estate in the Pro/ENGINEER interface.
You can have a J-Link application to open several components in a Pro/ENGINEER session using a non-graphics mode, letting you modify, add, and remove parameters or perform other operations very quickly.
Other possibilities include:
Breaking up or removing family table components
Updating or removing model relations
Using MS Excel to drive Pro/ENGINEER
Creating several family table drawings
Model retrieving information from any database
Creating PDF documents from several drawings
Inputting parameter values into several models
Creating Action Listeners based on user events
Auto-replacing assembly components
Assembling components dynamically
J-Link versus Pro/TOOLKIT
J-Link access is provided by the JNI (Java Native Interface) calls into the Pro/TOOLKIT library. All methods and functions in J-Link are therefore in Pro/TOOLKIT. But the good news is that the Java API is free. In addition, J-Link uses Action Listener functions to listener for user events.
J-Link has “Model Programs” that allow associations between a Java program and a solid model. Model programs start when a model is retrieved and stop when it is erased from session. Pro/TOOLKIT does not have this capability.
J-Link offers other advantages over Pro/TOOLKIT:
A comprehensive set of built-in libraries and capabilities such as XML, GUI, Listeners, network programming, and JDBC
Free IDE (Intergraded Develop Environment) software
Ease of use for beginners
Hardware and platform independence
Support for signed applets using asynchronous mode on a local machine for web applications
Support for connections to a remote Pro/ENGINEER session using servlet technology on the server machine.
The disadvantages relative to Pro/TOOLKIT are that J-Link:
Does not include Pro/CABLE and Pro/WELD
Cannot access 3D annotations or feature element trees
Has manufacturing limitations.
Although J-Link will probably never cover the entire Pro/TOOLKIT interface, PTC remains committed to adding new methods and objects to give greater access to Pro/ENGINEER from Java applications.
J-Link can load or launch Pro/TOOLKIT applications and can call out Pro/TOOLKIT library functions if needed. For information on a JL-TK library that fills in the gaps of J-Link, go to www.jerand.com and select Products.
Installation and Setup
There is no special setup required to enable Pro/ENGINEER to run a J-Link program other then selecting the J-Link install option through PTC setup. All Pro/ENGINEER workstations should have the J-Link API.
J-Link Help Documentation
PTC includes two types of J-Link documentation with your installation:
The J-Link User’s Guide. This printable version is located in:
<Pro/E loadpoint>\jlink\jlinkug.pdf
The J-Link APIWizard. This online version, including cross-links between the user’s guide and function descriptions, is located in:
<Pro/E loadpoint>\jlink\jlinkdoc\index.html
PTC J-Link Examples
PTC provides some good examples of J-Link code, located in:
<Pro/E loadpoint>\jlink\jlink_appls\jlinkexamples.
Using a Java IDE
To successfully create and develop J-Link applications, you need to have a good integrated development environment. There are two free Java IDE applications that I recommend:
J-Builder is a Borland product that can be downloaded at www.codegear.com/tabid/143/Default.aspx. Select the foundation Version 2005 or Foundation and Enterprise Trail Version 2006.
The new Borland 2007 IDE will be integrated with Eclipse but is not available free of charge at this time.
J-Builder IDE
Eclipse IDE
The IDE must know where the J-Link libraries are located in order to build a J-Link application. Go to the IDE help to find out how to set up or add a library path to your project.
Creating Synchronous Applications
A synchronous application is an application that Pro/ENGINEER executes when invoked. The application is completely dependent on a Pro/ENGINEER session. Using synchronous applications, you can make additions to the Pro/ENGINEER user interface, gather or change data associated with the models in session, or add session-level Action Listener routines.
1. Registry files. A synchronous application requires a registry file, which contains Pro/ENGINEER-specific information about the standalone application you want to load. The registry file, called protk.dat, is a simple text file where each line consists of one predefined keyword followed by a value. Here’s an example
If a registry file includes a “delay_start” entry set to true, Pro/ENGINEER will not run the application upon startup. If a registry file includes an “allow_stop” entry set to true, Pro/ENGINEER will allow you to stop the application.
2. Registering an application. A J-Link application must be registered in Pro/ENGINEER before it can start or load. Pro/ENGINEER will then know where to execute the application Java classes when invoked.
Create a registry file, called “protk.dat” that Pro/ENGINEER will find and read. Pro/ENGINEER searches for the registry file in the following order:
A file called protk.dat in the current startup folder. Used normally during development, because the J-Link application is seen only if you start Pro/ENGINEER from the specific directory that contains protk.dat.
A file named in a “PROTKDAT”, “PRODEVDAT”, or “TOOLKIT_REGISTRY_FILE” statement in the Pro/ENGINEER configuration file (config.pro). Recommended when making an end-user installation because it ensures the registry file is found regardless of the directory used to start Pro/ENGINEER. (TOOLKIT_REGISTRY_FILE is the recommended choice.)
A file called protk.dat or prodev.dat in the directory <Pro/ENGINEER Load Point>/ i486_nt/text/usascii. Enables you to have a different registry file for each platform and for each Pro/ENGINEER language. This is more commonly used for J-Link applications that have a platform-dependent setup.
A file called protk.dat or prodev.dat in the directory <Pro/ENGINEER>/text.
Recommended for the same reason as option (2) above.
3. Creating New Buttons and Menus
To execute the synchronous J-Link application, you have to create buttons or menus in the top menu bar of the Pro/ENGINEER interface. The session objects allow a J-Link application to add commands on an existing menu bar or add a new button.
To create a new command:
UICommand cmd;
cmd = session.UICreateCommand( “CommandName”,
new MyButtonActionListener() );
class MyButtonActionListener extends DefaultUICommandActionListener {
public void OnCommand () {
// action code
}
}
4. Creating a Message File
A text message file is where you define strings that are displayed in the Pro/ENGINEER user interface. This includes the strings on the command buttons that you add to the Pro/ENGINEER menu, the help string that displays when you position your cursor over such a command button, and text strings that you display in the Message Window.
The message file consists of groups of four lines, one group for each message you want to write. The four lines are as follows:
Line 1. A string that acts as the identifier for the message. This keyword must be unique for all Pro/ENGINEER messages.
Line 2. The string that will be substituted for the identifier. This string can include placeholders for run-time information stored in a string seq object (shown in Writing Messages to the Message Window).
Line 3. The translation of the message into another language. Can be blank.
Line 4. Intentionally blank line reserved for future extensions.
Here’s a sample message text file:
5. Adding J-Link Code to a Class
Each synchronous class has a certain structure before it is registered. The following table displays a common synchronous template class.
The class connects to a current Pro/ENGINEER session and adds a new button under the Help menu. When you execute the new menu button, the Pro/ENGINEER internal browser goes to a specified website.
You have to compile your IDE project before you run the application.
Create and save the protk.dat file that is shown above in your startup folder. Open Pro/ENGINEER and select the Help menu. You should see a FELCO Solutions menu item.
You can go to www.felcosolutions.com to download the application and test it on your machine by selecting Free Download Example on the home page.