External Data
This chapter explains using External Data in Web.Link.
External Data
This chapter describes how to store and retrieve external data. External data enables a Web.Link application to store its own data in a Creo Parametric database in such a way that it is invisible to the Creo Parametric user. This method is different from other means of storage accessible through the Creo Parametric user interface.
Introduction to External Data
External data provides a way for the Creo Parametric application to store its own private information about a Creo Parametric 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 Parametric; the application has complete control over form and content.
The external data for a specific Creo Parametric 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 Parametric 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:
Web.Link Type
Data
pfcExternalDataTypeEXTDATA_INTEGER
integer
pfcExternalDataType EXTDATA_DOUBLE
double
pfcExternalDataType EXTDATA_STRING
string
The Web.Link interfaces used to access external data in Creo Parametric are:
Web.Link 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 Parametric TOOLKIT
Web.Link and Creo TOOLKIT share external data in the same manner. Web.Link external data is accessible by Creo TOOLKIT and the reverse is also true. However, an error will result if Web.Link attempts to access external data previously stored by Creo TOOLKIT as a stream.
Accessing External Data
Methods Introduced:
  • pfcModel.AccessExternalData()
  • pfcModel.TerminateExternalData()
  • pfcExternalDataAccess.IsValid()
  • The method pfcModel.AccessExternalData() prepares Creo Parametric 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 Parametric 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 and Properties Introduced:
  • pfcExternalDataAccess.CreateClass()
  • pfcExternalDataClass.CreateSlot()
  • pfcExternalDataSlot.Value
  • 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 property pfcExternalDataSlot.Value 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:
  • MpfcExternal.CreateIntExternalData()
  • MpfcExternal.CreateDoubleExternalData()
  • MpfcExternal.CreateStringExternalData()
  • These methods initialize a pfcExternalData object with the appropriate data inputs.
    Retrieving External Data
    Methods and Properties Introduced:
  • pfcExternalDataAccess.LoadAll()
  • pfcExternalDataAccess.ListClasses()
  • pfcExternalDataClass.ListSlots()
  • pfcExternalData.discr
  • pfcExternalData.IntegerValue
  • pfcExternalData.DoubleValue
  • pfcExternalData.StringValue
  • 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 Parametric 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.
    To find out a data type of a pfcExternalData, call pfcExternalData.discr and then call one of these properties to get the data, depending on the data type:
    •  pfcExternalData.IntegerValue
    •  pfcExternalData.DoubleValue
    •  pfcExternalData.StringValue
    Exceptions
    Most exceptions thrown by external data methods in Web.Link 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 pfcExternalData object.