Setting Up Creo Object TOOLKIT Java
This section describes how to set up your environment so you can run Creo Object TOOLKIT Java.
Setting Up Your Machine
See Java Options and Debugging for more information about supported Java Virtual Machines and how to setup Creo application.
Setting Up a Synchronous Creo Object TOOLKIT Java Program
A synchronous Creo Object TOOLKIT Java application is started and managed by Creo application. Control belongs to either Creo or the application, but not both at the same time.
All Creo Object TOOLKIT Java applications must be packaged as a jar. The .class files will be ignored, even if their locations are present either in the java_app_classpath field in the registry file, or in the classpath. Refer to the section Unlockin, for more information.
You can run synchronous Creo Object TOOLKIT Java programs as standalone applications or model-specific programs. Most of the required settings for these two programs are independent of the programs themselves. This enables you to convert an application program to a model program, or vice versa.
Standalone Applications
You can start the Creo Object TOOLKIT Java application independently at any time, regardless of which models are in session. A registry file contains key information regarding the execution of the program.
Using application programs you can make additions to the Creo user interface, gather or change data associated with the models in session, or add session-level ActionListener routines.
Registry File
A registry file contains Creo-specific information about the standalone application you want to load.
The registry file called creotk.dat or protk.dat is a simple text file, where each line consists of one predefined keyword followed by a value. The standard form of the creotk.dat or protk.dat file is as follows:
name                              java_demo
startup                            otk_java
toolkit                             object
creo_type                       parametric
java_app_class               MyJavaApp
java_app_classpath         <full path to the application classes 
                                      and archives>
java_app_start                 start
java_app_stop                 stop
allow_stop                       true
delay_start                      true
text_dir                           <path to text directory used by
                                      message and menu related commands>
end
The fields of the registry file are as follows:
•  name—Assigns a unique name to this Creo Object TOOLKIT Java application. The name identifies the application when there is more than one in the creotk.dat or protk.dat file. The maximum size of the name is 31 characters for the name, plus the end-of-string character.
•  startup—Specifies the method Creo should use to communicate with the Creo Object TOOLKIT Java application. For Creo Object TOOLKIT Java applications, set startup to otk_java.
•  toolkitSpecifies the name of the Toolkit which was used to create the customization. The valid values for this field are object and protoolkit.
An application created in Creo Object TOOLKIT Java must always have the value of this field set as object.
Note
This field can also be used to indicate other toolkits. Its default value is protoolkit, which specifies that the customizing application was created in Creo TOOLKIT. If you set the value for this field as protoolkit, or omit this field, then the application can be used only with Creo Parametric.
•  creo_typeSpecifies the Creo applications that support the Creo Object TOOLKIT Java applications. The valid values for this field are:
  parametric—This is the default value. Specify parametric to load the Creo Object TOOLKIT Java application in Creo Parametric.
Note
Other Creo applications will be supported in future releases.
•  java_app_class—Specifies the fully qualified package and name of a Java class. This class contains the Creo Object TOOLKIT Java application’s start and stop methods.
•  java_app_classpath—An optional field to specify the full path to the Creo Object TOOLKIT Java application jar file. Refer to the section CLASSPATH Variables for more information on the other available mechanisms to set the CLASSPATH. This field has a character limit of 2047 wide characters (wchar_t).
•  java_app_start—Specifies the start method of your program. See the section Start and Stop Methods for more information.
•  java_app_stop—Specifies the stop method of your program. See the section Start and Stop Methods for more information.
•  allow_stop—Stops the application during the session if it is set to true. If this field is missing or set to false, you cannot stop the application, regardless of how it was started.
•  delay_start—Enables you to choose when to start the Creo Object TOOLKIT Java application if it is set to true. Creo application does not start the Creo Object TOOLKIT Java application during startup. If this field is missing or is set to false, the Creo Object TOOLKIT Java application starts automatically.
•  text_dir—Specifies the location of the text directory that contains the language-specific directories. The language-specific directories contain the message files, menu files, resource files and UI bitmaps in the language supported by the Creo Object TOOLKIT Java application. The files must be located under a directory called text or text/<language>, if localized messages are used in the application. This field has a character limit of 2047 wide characters (wchar_t).
•  rbn_path—Specifies the name of the ribbon file along with its path, which must be loaded when you open the Creo application. The location of the ribbon file is relative to the location of the text directory. The field text_dir specifies the path for the text directory.
If the field is not specified, by default, the ribbon file with its location, text_dir/toolkitribbonui.rbn is used.
•  end—Indicates the end of the description of the Creo Object TOOLKIT Java application. You can define multiple Creo Object TOOLKIT Java applications in the registry files. All these applications are started by Creo application.
Registering a Creo Object TOOLKIT Java Application
Registering a Creo Object TOOLKIT Java application means providing information about the files that form the Creo Object TOOLKIT Java application to Creo application. To do this, create a small text file, called the Creo Object TOOLKIT Java “registry file,” that Creo application will find and read.
Creo application searches for the registry file in the following order:
1. A file called creotk.dat or protk.dat in the current directory
2. A file named in a creotk.dat, protk.dat, or toolkit_registry_file statement in theCreo application configuration file
3. A file called creotk.dat or protk.dat in the directory <creo_loadpoint>\<version>\Common Files\<machine type>\text\<language>
4. A file called creotk.dat or protk.dat in the directory <creo_loadpoint>\<version>\Common Files\text
In the last two options, the variables are as follows:
•  <creo_loadpoint>—The Creo loadpoint (not the Creo Object TOOLKIT Java loadpoint)
•  <machine type>—The machine-specific subdirectory such as x86e_win64 or i486_nt
•  <language>—The language of Creo application with which the Creo Object TOOLKIT Java application is used such as usascii (English), german, or japanese
If more than one registry file having the same filename exists in this search path, Creo Object TOOLKIT Java stops searching after finding the first instance of the file and starts all the Creo Object TOOLKIT Java applications specified in it. If more than one registry file having different filenames exists in this search path, Creo application stops searching after finding one instance of each of them and starts all the Creo Object TOOLKIT Java applications specified in them.
Option 1 is used normally during development, because the Creo Object TOOLKIT Java application is seen only if you start Creo application from the specific directory that contains creotk.dat or protk.dat.
Option 2 or 4 is recommended when making an end-user installation, because it makes sure that the registry file is found irrespective of the directory used to start Creo application.
Option 3 enables you to have a different registry file for each platform, and for each Creo application language. This is more commonly used for Creo Object TOOLKIT Java applications that have a platform dependent setup.
Starting and Stopping a Standalone Application
If the delay_start field in the registry file is set to false, the Creo Object TOOLKIT Java application starts automatically when you start Creo. Otherwise start the program by following these steps:
1. From the Creo Parametric toolbar, select Utilities  Auxiliary Applications.
2. Choose the name of the application.
3. Click Start.
•  Start—activates start method
•  Stop— activates stop method
If the allow_stop field in the registry file is set to true, you can click Stop in the Auxiliary Applications dialog box to stop the application. Click Start to restart it. If the allow_stop field is set to false, the program runs until the Creo Parametric session ends.
Setting Up a Model Program
A model program is a Creo Object TOOLKIT Java program specific to a particular solid model, that is part or assembly. Creo application activates the start method for a program when it loads the part into memory and activates the stop method when it erases the part from memory.
Using model programs you can add programming logic to the interaction with a solid model. You can create a dialog box to drive the regeneration of a part or create model-specific utilities to generate reports or engineering information from a model. As Java programs are platform independent, the same model program runs on any Windows installation of Creo application.
To setup a model program you need to:
•  Associate and run a Creo Object TOOLKIT Java application with a model
•  Create a JAR file for Model-Program Dependency
Associating and Running a Creo Object TOOLKIT Java Application with a Model
1. Load the solid model that you want to associate and run with the Creo Object TOOLKIT Java application.
2. From the PART or ASSEMBLY menu, select Tools  Program  Object TOOLKIT Java.
3. If the application is stored in a Java archive (JAR) file, click Add File in the Model Programs dialog box and add the JAR file to the list of Java archive files. If the application is stored in a .class file proceed to the next step.
4. Click Add and enter the following information in the Java Application Properties dialog box:
•  Application Name—A unique name for this Object TOOLKIT Java application. The maximum size of the name is 31 characters for the name, plus the end-of-string character.
•  Class Name—The Java class that contains the start and stop methods for the Creo Object TOOLKIT Java application. This class must reside in a JAR file you have added to the list or in a directory that is part of your CLASSPATH.
•  Start Method Name—The method in the Class Name class that will be called whenever the model is loaded into a session.
•  Stop Method Name—The method in the Class Name class that will be called whenever the model is erased.
The Creo Object TOOLKIT Java application immediately attempts to run. If it cannot start successfully an exception condition is listed in the Status column of the Model Programs dialog box.
JAR File Needed for Model-Program Dependency
Although individual class files are associated with a model, there is no dependency between the model and the program. Therefore, Windchill server is not able to recognize the relationship between the class files and the model. To create a dependency, include all the class files and the source code in a Java archive file (jar file). JAR files are created through the command jar, which is a part of the standard Java Development Kit (JDK) package.
To create a JAR file use a command similar to the following command string:
jar cvf0 myjar.jar *.java *.class
Note
You must use the command-line switch 0 (zero) because JAVA cannot read classes from compressed JAR files.
You can add JAR files to, or remove them from, a model by using the buttons on the left side of the model program interface. All the JAR files for the model program must be placed in the Creo search path.
Note
When naming a Creo Object TOOLKIT Java model program JAR file, you must use lower case.
Start and Stop Methods
All synchronous Creo Object TOOLKIT Java programs must have a static start and stop method regardless of whether they will run standalone or as model programs. You can give these methods any name you want because you identify them in the registry file or in the model program setup. The Creo application automatically calls these methods upon starting or stopping a program. All methods that you want to call in a particular program must be called in the start and stop methods, or you must use the start method to register listeners to react to events in the Creo user interface.
For example:
public static void startMyProgram() 
{
    runMyUtilities();
    configureMyModels();
    addMyUI();
}

public static void stop() {
    cleanupModels();
    outputToPrinterFiles();
}
Creo Object TOOLKIT Java start and stop methods must be public, static, return void and take no arguments. You can configure applications based on the Creo version and build or custom command line arguments using methods described in the Session Objects section.