External Data
This section explains using External Data in Creo Object TOOLKIT C++.
External Data
This chapter describes how to store and retrieve external data. External data enables a Creo Object TOOLKIT C++ 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 C++ Type
Data
pfcEXTDATA_INTEGER
integer
pfcEXTDATA_DOUBLE
double
pfcEXTDATA_STRING
string
The Creo Object TOOLKIT C++ interfaces used to access external data in Creo are:
Creo Object TOOLKIT C++ Type
Data Type
pfcExternalDataAccess
This is the top level object and is created when attempting to access external data.
pfcExternalDataClass
This is a class of external data and is identified by a unique name.
pfcExternalDataSlot
This is a container for one item of data. Each slot is stored in a class.
pfcExternalData
This is a compact data structure that contains either an integer, double or string value.
Compatibility with Creo TOOLKIT
Creo Object TOOLKIT C++ and Creo TOOLKIT share external data in the same manner. Creo Object TOOLKIT C++ external data is accessible by Creo TOOLKIT and the reverse is also true. However, an error will result if Creo Object TOOLKIT C++ attempts to access external data previously stored by Creo TOOLKIT as a stream.
Accessing External Data
Methods Introduced:
The method pfcModel::AccessExternalData prepares Creo application to read external data from the model file. It returns the pfcExternalDataAccess 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::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 pfcExternalDataAccess::IsValid determines if the pfcExternalDataAccess 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 pfcExternalDataAccess::CreateClass, which provides the class name. The method outputs pfcExternalDataClass, used by the application to reference the class.
The next step is to use pfcExternalDataClass::CreateSlot to create an empty data slot and input a slot name. The method outputs a pfcExternalDataSlot object to identify the new slot.
Note
Slot names cannot begin with a number.
The method pfcExternalDataSlot::SetValue specifies the data type of a slot and writes an item of that type to the slot. The input is a pfcExternalData 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 pfcExternalData 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 pfcExternalDataAccess::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 pfcExternalDataAccess::ListClasses returns a sequence of pfcExternalDataClasses registered in the model. The method pfcExternalDataClass::ListSlots provide a sequence of pfcExternalDataSlots existing for each class.
The method pfcExternalDataSlot::GetValue reads the pfcExternalData from a specified slot.
To find out a data type of a pfcExternalData, call pfcExternalData::Getdiscr and then call one of these methods to get the data, depending on the data type:
•  pfcExternalData::GetIntegerValue
•  pfcExternalData::GetDoubleValue
•  pfcExternalData::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 wfcWSession::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 wfcExternalSelectionHighlight::StartNotify is called when the method pfcBaseSession::Select is activated. It notifies the application about entering pfcBaseSession::Select. The callback method wfcExternalSelectionHighlight::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 wfcExternalSelectionHighlight::EndNotify is called when the applications is about to exit the method pfcBaseSession::Select.
On clicking a tree node, the application creates a wfcWSelection object and uses the method wfcWSelection::RecordExternalSelection to pass it to pfcBaseSession::Select. The input arguments of this method is enumerated data type wfcSelectionRecordAction. The valid values are:
•  wfcSELECT_OVERRIDE—Specifies that the previous selection is overridden.
•  wfcSELECT_TOGGLE—Specifies that the last two selections are toggled.
Use the method wfcWSession::ReleaseExternalSelectionHighlight to release the memory of the client interface wfcExternalSelectionHighlight in the method wfcWSession::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 C++ extend pfcXExternalDataError, which is a subclass of pfcXToolkitError.
An additional exception thrown by external data methods is pfcXBadExternalData. 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
pfcXExternalDataInvalidObject
Generated when a model or class is invalid.
pfcXExternalDataClassOrSlotExists
Generated when creating a class or slot and the proposed class or slot already exists.
pfcXExternalDataNamesTooLong
Generated when a class or slot name is too long.
pfcXExternalDataSlotNotFound
Generated when a specified class or slot does not exist.
pfcXExternalDataEmptySlot
Generated when the slot you are attempting to read is empty.
pfcXExternalDataInvalidSlotName
Generated when a specified slot name is invalid.
pfcXBadGetExternalData
Generated when you try to access an incorrect data type in a External.ExternalData object.