3D PLM PPR Hub Open Gateway

Feature Modeler

Working with Attribute Keys

Migrating GetAttribute to GetAttrKey

Technical Article

Abstract

This article is intended to help you understand the new way of accessing and valuating attributes. Specifically, you will learn how to:

  • Valuate existing attributes with ("new way") and without ("old way") attribute keys
  • Add new attributes to a feature
  • Valuate new attributes the "old" and "new" ways.

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].


Some Important Concepts about Attributes

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

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:

[Top]

Creating Feature 

  1. Retrieving a StartUp

    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 ).

  2. Instantiating a StartUp

    CATUnicodeString InstanceName("MyInstanceName1");
    CATISpecObject *pIInstanceOnSpecObj1 = pIStartUpOnSpecObj -> 
    		Instanciate(InstanceName,
    		            piRootContainer);
    ...

    A new feature, "MyInstanceName1" is created in the root container by instantiating the StartUp "MyStartUpType".

[Top]

Valuating Existing Attributes the "Old" and "New" Ways

  1. Old way

    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.

  2. New way

    1. Get attribute key

      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.

    2. Valuate attribute
      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]

Adding New Attributes

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]

Valuating New Attributes the "Old" and "New" Ways

  1. Old way

    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.

  2. New way
    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]


In Short

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:

[Top]


References

[1] Feature Modeler Overview
[Top]

History

Version: 1 [Feb 2005] Document created
[Top]

Copyright © 1994-2005, Dassault Systèmes. All rights reserved.