3D PLM PPR Hub Open Gateway

Product Modeler

Manipulating a Product's Temporary Data

Working with the CATIProductInSession Interface

Use Case

Abstract

This article presents  the CAAPstProductInSession use case which illustrates how to work with a product's temporary data.


What You Will Learn With This Use Case

Using the CATIProductInSession interface, a product's temporary data can be accessed and modified. Please note that the modifications cannot be saved and are lost once the session is closed.

[Top]

The CAAPstProductInSession Use Case

CAAPstProductInSession is a use case of the CAAProductStructure.edu framework that illustrates the ProductStructure framework capabilities.

[Top]

What Does CAAPstProductInSession Do

The goal of CAAPstProductInSession is to demonstrate the CATIProductInSession interface. It performs the following steps:

Below  is the Product document that will be loaded in the use case. It can be found in

InstallRoot/CAAProductStructure.edu/CNext/resources/graphic/CAAPstProductInSessionInput.CATProduct

Product1 has two possible representations that are listed using the contextual menu Representations -> Manage Representations:

The default representation is a cylinder named "Shape_Cyl". The other possible representation is a cube named "Shape_Cube" that is activated in the following screen:

[Top]

How to Launch CAAPstProductInSession

To launch CAAPstProductInSession:

  1. Set the current directory to InstallRoot/CAAProductStructure.edu
  2. Set up  the build time environment and build the CAAPstProductInSession.m module (see [2])
  3. Execute the following command:

    mkrun -c "CAAPstProductInSession input.CATProduct shape_name"

The following output will be obtained with the supplied document:

Session opened
Document opened
Working with 'Product1'
Activated 'Shape_Cube' representation
Current active representation: 'Shape_Cube'
Active shape representation retrieved
Session deleted

[Top]

Where to Find the CAAPstProductInSession Code

CAAPstProductInSession code is located in the CAAPstProductInSession.m module of the CAAProductStructure.edu framework.

[Top]

Step-by-Step

There are six logical steps in CAAPstProductInSession:

  1. Creating a session to load a Product document
  2. Retrieving the document's Root Product
  3. Changing the active representation
  4. Verifying that the active representation has been changed
  5. Retrieving the current active representation
  6. Closing the session

We will now detail  each of those sections:

[Top]

Loading a Product Document

Generally, the first thing that is necessary in a batch program is the creation of a new session. This is done using the Create_Session global function. It is important not to forget to delete the session when the program terminates. Once the session is created, a Product document can be loaded with CATDocumentServices::Open.

        CATSession *pSession = NULL;
        rc = ::Create_Session("CAA2_Sample_Session",pSession );
...
        CATDocument *pDoc = NULL;
        rc = CATDocumentServices::OpenDocument(inputFilename, pDoc);
...

[Top]

Retrieving the Document's Root Product

In order to work with a product structure within the Product document, it is necessary to access the root product. This is done using the GiveDocRoots method of CATIDocRoots which returns a list of all of the roots within the document, the first one being the root product we are looking for. From this root product, we can get then CATIProduct handle and subsequently the CATIProductInSession handle.

        CATIDocRoots *piDocRootsOnDoc = NULL;
        rc = pDoc->QueryInterface(IID_CATIDocRoots,(void**) &piDocRootsOnDoc);
...
        CATListValCATBaseUnknown_var *pRootProducts =
        piDocRootsOnDoc->GiveDocRoots();
        CATIProduct_var spRootProduct;
        if (NULL != pRootProducts && pRootProducts->Size() > 0) {
                spRootProduct = (*pRootProducts)[1];
...
        } else {
                cout << "Failed to find root products"<< endl;
                return 5;
        }
...
        // Get CATIProduct prointer of the root product.
        CATIProduct *piProductOnRoot = NULL;
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
                                           (void**) &piProductOnRoot);
...
        CATUnicodeString partNumber = piProductOnRoot->GetPartNumber();
        cout << "Working with '" << partNumber.ConvertToChar() << "'" << endl;
        //Get the ProductInSession Interface pointer

        CATIProductInSession * piProdInSession = NULL;
        rc = piProductOnRoot->QueryInterface(IID_CATIProductInSession,
                                             (void **) &piProdInSession);

[Top]

Changing the Active Representation

First we need to set the active representation by calling SetActiveShapeRep with the shape name input to the program. As this usecase is non-interactive, there might be no representation active when the product is opened.

	/* --------------------------------------------------------- */
	/*  3. Changing the active shape representation.             */
	/*                                                           */
	/*  Note: Since this code a non-interactive,                 */
	/*        SetActiveShapeRep must be called first for the     */
	/*        subsequent GetActiveShapeRep to work               */
	/* --------------------------------------------------------- */
	rc = piProdInSession->SetActiveShapeRep(shapeName, TRUE, FALSE,
                                                 CATPrd3D, TRUE, FALSE);

[Top]

Verifying the Active Representation

Now that the active representation has changed, we verify that its name has also changed accordingly.

	/* --------------------------------------------------------- */
	/*  4. Verifying the active shape representation name.       */
	/* --------------------------------------------------------- */
	CATUnicodeString activeShapeName;
	rc = piProdInSession->GetActiveShapeName(activeShapeName);
...
	if (activeShapeName != shapeName) {
		cout << "ERROR: the active representation is "
		     << activeShapeName.ConvertToChar() << " instead of "
		     << shapeName.ConvertToChar() << endl;
		return 11;
	}
	cout << "Current active representation: '"
	     << activeShapeName.ConvertToChar() << "'" << endl;

[Top]

Retrieving the Active Representation

Using the CATIProductInSession handle we can also retrieve the current active representation (a CATILinkabkeObject ) with GetActiveShapeRep.

	/* --------------------------------------------------------- */
	/*  5. Retrieving the active shape representation.           */
	/* --------------------------------------------------------- */
	
	CATILinkableObject_var spLinkedObject;
	rc = piProdInSession->GetActiveShapeRep(spLinkedObject);
...
	cout << "Active shape representation retrieved" << endl;

[Top]

Closing the Session

Before closing the session, we need to release the CATIProductInSession handle and remove the document from the session.

        rc = CATDocumentServices::Remove (*pDoc);
        if (!SUCCEEDED(rc)) return 11; 

        rc = ::Delete_Session("CAA2_Sample_Session");
        cout << "Session deleted" << endl;

[Top]


In Short

This use case has demonstrated how to make a sub-product flexible so that one of its parts can be moved:

[Top]


References

[1] The Product Structure Model
[2] Building and Launching a CAA V5 Use Case
[Top]

History

Version 2 [Aug 2004] SetActiveShapeRep first
Version 1 [Sep 2003] Document created
[Top]

Copyright © 2003, Dassault Systèmes. All rights reserved.