3D PLM PPR Hub Open Gateway |
Product Modeler |
Manipulating a Product's Temporary DataWorking with the CATIProductInSession Interface |
Use Case |
AbstractThis article presents the CAAPstProductInSession use case which illustrates how to work with a product's temporary data. |
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]
CAAPstProductInSession is a use case of the CAAProductStructure.edu framework that illustrates the ProductStructure framework capabilities.
[Top]
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]
To launch CAAPstProductInSession:
- input.CATProduct: path to the supplied document whose path is InstallRoot/CAAProductStructure.edu/CNext/resources/graphic/CAAPstProductInSessionInput.CATProduct
- shape_name: name of the representation to change to. Shape_Cube can be used with the document provided.
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]
CAAPstProductInSession code is located in the CAAPstProductInSession.m module of the CAAProductStructure.edu framework.
[Top]
There are six logical steps in CAAPstProductInSession:
We will now detail each of those sections:
[Top]
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]
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]
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]
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]
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]
This use case has demonstrated how to make a sub-product flexible so that one of its parts can be moved:
[Top]
[1] | The Product Structure Model |
[2] | Building and Launching a CAA V5 Use Case |
[Top] |
Version 2 [Aug 2004] | SetActiveShapeRep first |
Version 1 [Sep 2003] | Document created |
[Top] |
Copyright © 2003, Dassault Systèmes. All rights reserved.