External Data
This chapter explains using External Data in Creo Object TOOLKIT Java.
External Data
This chapter describes how to store and retrieve external data. External data enables a Creo Object TOOLKIT Java application to store its own data in a Creo database in such a way that it is invisible to the Creo user. This method is different from other means of storage accessible through the Creo user interface.
Introduction to External Data
External data provides a way for the Creo application to store its own private information about a Creo model within the model file. The data is built and interrogated by the application as a workspace data structure. It is saved to the model file when the model is saved, and retrieved when the model is retrieved. The external data is otherwise ignored by Creo; the application has complete control over form and content.
The external data for a specific Creo model is broken down into classes and slots. A class is a named ‘‘bin’’ for your data, and identifies it as yours so no other Creo API application (or other classes in your own application) will use it by mistake. An application usually needs only one class. The class name should be unique for each application and describe the role of the data in your application.
Each class contains a set of data slots. Each slot is identified by an identifier and optionally, a name. A slot contains a single data item of one of the following types:
Creo Object TOOLKIT Java Type
Data
pfcExternal.ExternalDataType.EXTDATA_INTEGER
integer
pfcExternal.ExternalDataType.EXTDATA_DOUBLE
double
pfcExternal.ExternalDataType.EXTDATA_STRING
string
The Creo Object TOOLKIT Java interfaces used to access external data in Creo applications are:
Creo Object TOOLKIT Java Type
Data Type
com.ptc.pfc.External.ExternalDataAccess
This is the top level object and is created when attempting to access external data.
com.ptc.pfc.pfcExternal.ExternalDataClass
This is a class of external data and is identified by a unique name.
com.ptc.pfc.pfcExternal.ExternalDataSlot
This is a container for one item of data. Each slot is stored in a class.
com.ptc.pfc.pfcExternal.ExternalData
This is a compact data structure that contains either an integer, double or string value.
Compatibility with Creo TOOLKIT
Creo Object TOOLKIT Java and Creo TOOLKIT share external data in the same manner. Creo Object TOOLKIT Java external data is accessible by Creo TOOLKIT and the reverse is also true. However, an error will result if Creo Object TOOLKIT Java attempts to access external data previously stored by Creo TOOLKIT as a stream.
Accessing External Data
Methods Introduced:
The method pfcModel.Model.AccessExternalData prepares Creo application to read external data from the model file. It returns the pfcExternal.ExternalDataAccess object that is used to read and write data. This method should be called only once for any given model in session.
The method pfcModel.Model.TerminateExternalData stops Creo application from accessing external data in a model. When you use this method all external data in the model will be removed. Permanent removal will occur when the model is saved.
Note
If you need to preserve the external data created in session, you must save the model before calling this function. Otherwise, your data will be lost.
The method pfcExternal.ExternalDataAccess.IsValid determines if the ExternalDataAccess object can be used to read and write data.
Storing External Data
Methods Introduced:
The first step in storing external data in a new class and slot is to set up a class using the method pfcExternal.ExternalDataAccess.CreateClass, which provides the class name. The method outputs pfcExternal.ExternalDataClass, used by the application to reference the class.
The next step is to use pfcExternal.ExternalDataClass.CreateSlot to create an empty data slot and input a slot name. The method outputs a pfcExternal.ExternalDataSlot object to identify the new slot.
Note
Slot names cannot begin with a number.
The method pfcExternal.ExternalDataSlot.SetValue specifies the data type of a slot and writes an item of that type to the slot. The input is a pfcExternal.ExternalData object that you can create by calling any one of the methods in the next section.
Initializing Data Objects
Methods Introduced:
These methods initialize a pfcExternal.ExternalData object with the appropriate data inputs.
Retrieving External Data
Methods Introduced:
For improved performance, external data is not loaded automatically into memory with the model. When the model is in session, call the method pfcExternal.ExternalDataAccess.LoadAll to retrieve all the external data for the specified model from the Creo model file and put it in the workspace. The method needs to be called only once to retrieve all the data.
The method pfcExternal.ExternalDataAccess.ListClasses returns a sequence of ExternalDataClasses registered in the model. The method pfcExternal.ExternalDataClass.ListSlots provide a sequence of ExternalDataSlots existing for each class.
The method pfcExternal.ExternalDataSlot.GetValue reads the pfcExternal.ExternalData from a specified slot.
To find out a data type of a pfcExternal.ExternalData, call pfcExternal.ExternalData.Getdiscr and then call one of these methods to get the data, depending on the data type:
•  pfcExternal.ExternalData.GetIntegerValue
•  pfcExternal.ExternalData.GetDoubleValue
•  pfcExternal.ExternalData.GetStringValue
Selecting the Node from the External Application Tree
The tree created by an external application is similar to the Creo model tree. Each node of this tree represents an external object that has been created by the application. The external objects could be different types of entities, such as, light sources, light sensors, and so on.
Methods Introduced:
The method wfcSession.WSession.RegisterExternalSelectionHighlight registers the callback methods when you select or deselect a node in the user tree or an object in the graphics window. The notification method wfcSelect.ExternalSelectionHighlight.StartNotify is called when the method pfcSession.BaseSession.Select is activated. It notifies the application about entering pfcSession.BaseSession.Select. The callback method wfcSelect.ExternalSelectionHighlight.Action is called when you select or deselect an external object. The Creo Object TOOLKIT C++ application will highlight the external object or remove the highlight according to the selection. The notification method wfcSelect.ExternalSelectionHighlight.EndNotify is called when the applications is about to exit the method pfcSession.BaseSession.Select.
On clicking a tree node, the application creates a WSelection object and uses the method wfcSelect.WSelection.RecordExternalSelection to pass it to pfcSession.BaseSession.Select. Pass the enumerated data type SelectionRecordAction as the input argument. The valid values are:
•  wfcSELECT_OVERRIDE—Specifies that the previous selection is overridden.
•  wfcSELECT_TOGGLE—Specifies that the last two selections are toggled between.
Use the method wfcSession.WSession.ReleaseExternalSelectionHighlight to release the memory of the client interface ExternalSelectionHighlight in the method wfcSession.WSession.RegisterExternalSelectionHighlight. After the client interface is released it cannot be used by the application.
Exceptions
Most exceptions thrown by external data methods in Creo Object TOOLKIT Java extend pfcExceptions.XExternalDataError, which is a subclass of pfcExceptions.XToolkitError.
An additional exception thrown by external data methods is pfcExceptions.XBadExternalData. This exception signals an error accessing data. For example, external data access might have been terminated or the model might contain stream data from Creo TOOLKIT .
The following table lists these exceptions.
Exception
Cause
XExternalDataInvalidObject
Generated when a model or class is invalid.
XExternalDataClassOrSlotExists
Generated when creating a class or slot and the proposed class or slot already exists.
XExternalDataNamesTooLong
Generated when a class or slot name is too long.
XExternalDataSlotNotFound
Generated when a specified class or slot does not exist.
XExternalDataEmptySlot
Generated when the slot you are attempting to read is empty.
XExternalDataInvalidSlotName
Generated when a specified slot name is invalid.
XBadGetExternalData
Generated when you try to access an incorrect data type in a External.ExternalData object.