3D PLM PPR Hub Open Gateway |
Feature Modeler |
Working with Attribute KeysMigrating GetAttribute to GetAttrKey |
Technical Article |
AbstractThis article is intended to help you understand the new way of accessing and valuating attributes. Specifically, you will learn how to:
Before getting to the article itself, it is important to get an understanding of what a feature object is and how it is created [1]. |
Feature modeler proposes a new way of retrieving attributes. Instead of using the attribute name directly when retrieving an attribute, you can now retrieve an attribute key which is used in place of the attribute. The attribute key based on the StartUp is a global variable. This causes an improvement in performance since once the attribute key is acquired for a given StartUp, it need not be acquired again for all subsequent instances of that StartUp. However, if the attribute key is acquired on a feature instance, it is valid for that feature only.
[Top]
Loading the catalog means opening the catalog document and getting a CATICatalog handle that will be needed in order to retrieve StartUps from the catalog.
CATUnicodeString stgName = "...."; CATICatalog *piCatalog; CATUnicodeString clientId("MyClientId"); rc = ::AccessCatalog (&stgName, &clientId, piRootContainer, &piCatalog); ... |
To open a catalog, use the AccessCatalog
global function that
takes the following arguments:
stgName
- the name of the catalog without the storage path
and with the .CATfct extension. The catalog must be found under the "WS" +
"OS" + resources + graphic directory. clientId
- the client id defined on the catalog at the
time of its creation. piRootContainer
- a CATIContainer pointer to the
container in which StartUps from the catalog will be instantiated. piCatalog
- a CATICatalog pointer to the StartUps
catalog that has been opened. [Top]
CATBaseUnknown *pStartUpOnBU = NULL; CATUnicodeString MyStartUpType("MyStartUpType"); rc = piCatalogOnContainer -> RetrieveSU(&pStartUpOnBU, &MyStartUpType, "CATISpecObject"); ... CATISpecObject *pIStartUpOnSpecObj = (CATISpecObject*) pStartUpOnBU ; |
A StartUp is retrieved from the catalog using the CATICatalog::RetrieveSU
method. This method returns a CATBaseUnknown pointer in
pStartUpOnBU
which is directly cast into a CATISpecObject
pointer (pIStartUpOnSpecObj
).
CATUnicodeString InstanceName("MyInstanceName1");
CATISpecObject *pIInstanceOnSpecObj1 =
|
A new feature, "MyInstanceName1" is created in the root container by instantiating the StartUp "MyStartUpType".
[Top]
CATISpecAttribute *piTitleAttr = pIInstanceOnSpecObj1 -> GetAttribute("Title");
if (NULL != piTitleAttr)
piTitleAttr -> SetString("The JungleBook");
...
|
We valuate an attribute of "MyInstanceName1" the "old" way. This
is done by simply using GetAttribute
on the attribute's name
and then performing one of the "Set..."
operations of
CATISpecAttribute (for example, SetString
in this case) to
valuate the attribute.
In order to valuate another attribute of "MyInstanceName1" the "new" way, we need to get the attribute keys based on the StartUp of the feature. We then use this attribute key to valuate the attribute. The advantage of this method is that once the attribute key is retrieved, it remains valid for valuating the attributes of all other features based on the same StartUp, thus improving performance. It can even be saved in a static global variable to be used throughout the application.
CATISpecAttrAccess *piSpecAttrAccessOnMyStartUp = NULL;
rc = pIStartUpOnSpecObj -> QueryInterface(IID_CATISpecAttrAccess,
(void**) &piSpecAttrAccessOnMyStartUp);
...
CATISpecAttrKey *piKeyTitle = piSpecAttrAccessOnMyStartUp->GetAttrKey("Title");
...
|
First, we need to get a CATISpecAttrAccess handle on the
StartUp (pIStartUpOnSpecObj
).
Using this handle, (piSpecAttrAccessOnMyStartUp
),
we then use the GetAttrKey
method to retrieve the
attribute key on the StartUp.
CATISpecAttrAccess *piSpecAttrAccessOnInst1 = NULL;
rc = pIInstanceOnSpecObj1 -> QueryInterface(IID_CATISpecAttrAccess,
(void**) &piSpecAttrAccessOnInst1);
...
piSpecAttrAccessOnInst1 -> SetString(piKeyTitle , "The JungleBook");
...
|
Once the key has been retrieved, we need to get a
CATISpecAttrAccess handle on our feature instance. Using this handle,
we can actually valuate the attribute using a "Set..."
method of CATISpecAttrAccess to which we pass a CATISpecAttrKey
handle to the attribute key and the value the attribute is to receive.
[Top]
Now, let's see how to valuate attributes added to a feature instance, in other words, attributes that have not been defined on a StartUp.
CATUnicodeString volume("Volume");
CATISpecAttribute *piVolumeNumber = pIInstanceOnSpecObj1 ->
AddAttribute(volume,tk_integer);
...
|
First, we add a new attribute to "MyInstanceName1" by simply using the
AddAttribute
method of CATISpecObject.
[Top]
CATISpecAttribute *piVolumeAttr = pIInstanceOnSpecObj1 -> GetAttribute("Volume");
if (NULL != piVolumeAttr)
piVolumeAttr -> SetInteger(1);
...
|
The "old" way of valuating the attribute needs to retrieve the attribute
itself (using GetAttribute
) before it can valuate it.
CATISpecAttrKey *piKeyVolume = piSpecAttrAccessOnInst1 -> GetAttrKey("Volume"); ... piSpecAttrAccessOnInst1 -> SetInteger(piKeyVolume, 1); ... |
The "new" way needs to acquire the attribute key (using GetAttrKey
)
and then uses this key to valuate the attribute.
Note that CATISpecAttrKey handles retrieved through
GetAttrKey
and CATISpecAttribute handles retrieved through
AddAttribute
must also be released
[Top]
This article has demonstrated how to work with attributes. It has also explained the concepts behind the migration from working with attributes directly to working with attribute keys. Specifically, it has illustrated:
GetAttrKey
method "Set..."
methods of
CATISpecAttrAccess AddAttribute
method of CATISpecAttribute GetAttrKey
and the
"Set..."
methods of CATISpecAttrAccess [Top]
[1] | Feature Modeler Overview |
[Top] |
Version: 1 [Feb 2005] | Document created |
[Top] |
Copyright © 1994-2005, Dassault Systèmes. All rights reserved.