3D PLM PPR Hub Open Gateway |
Product Modeler |
Working with a Product's PublicationsUsing the CATIPrdObjectPublisher Interface |
Use Case |
AbstractThis article presents the CAAPstPrdObjectPublisher use case which illustrates how to work with a product's publications. |
Using the CATIPrdObjectPublisher interface, the publications of a product and its components can be accessed and modified.
[Top]
CAAPstPrdObjectPublisher is a use case of the CAAProductStructure.edu framework that illustrates the ProductStructure framework capabilities.
[Top]
The goal of CAAPstPrdObjectPublisher is to demonstrate the CATIPrdObjectPublisher 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/CAAPstPrdObjectPublisher.CATProduct
The CAAPstPrdObjectPublisher product consists of a single part, CAAPstPrdObjectPublisher_Part.1 which publishes four of its faces:
The product CAAPstPrdObjectPublisher has two publications:
The code in the use case displays all the publications, modifies it and displays it again. It produces the output below with CAAPstPrdObjectPublisher.CATProduct as input. There are three distinct sections in the output:
Publications of CAAPstPrdObjectPublisher: Publication 1: GreenPart is finally published as GreenPart is a subpublication of Green Publication 2: BlueProd is finally published as BlueProd is published as BlueProd Publications of CAAPstPrdObjectPublisher_Part: Publication 1: Green is finally published as Green is published as Green Publication 2: Yellow is finally published as Yellow is published as Yellow Publication 3: Red is finally published as Red is published as Red Publication 4: Orange is finally published as Orange is published as Orange >> deleted publication GreenPart >> unvaluated publication Green >> deleted publication Green >> created new publication OrangeProd >> valuated publication OrangeProd Publications of CAAPstPrdObjectPublisher: Publication 1: BlueProd is finally published as BlueProd is published as BlueProd Publication 2: OrangeProd is finally published as OrangeProd is published as OrangeProd Publications of CAAPstPrdObjectPublisher_Part: Publication 1: Yellow is finally published as Yellow is published as Yellow Publication 2: Red is finally published as Red is published as Red Publication 3: Orange is finally published as Orange is published as Orange |
The modified product is also saved in a new document showing that:
a publication has been removed both at the product level (GreenPart) and at the part level (Green)
a new publication has been added at the product level (OrangeProd).
[Top]
To launch CAAPstPrdObjectPublisher:
- input: path to the supplied document InstallRoot/CAAProductStructure.edu/CNext/resources/graphic/CAAPstPrdObjectPublisher.CATProduct
- pubToDelete: a publication to be deleted. It must exist at the product level and is a subpublication. The only valid choice for this argument is GreenPart.
- pubToPublish: a publication to be published at the product level. It must exist at the part level. The valid choices for this argument are: Yellow, Red and Orange.
- outpuDir: path of the output directory where the modified document will be stored. This document's name will be prepended with "New". Please note that the directory must be with a / on Unix or a \ on Windows.
[Top]
CAAPstPrdObjectPublisher code is located in the CAAPstPrdObjectPublisher.m module of the CAAProductStructure.edu framework.
[Top]
There are six logical steps in CAAPstPrdObjectPublisher:
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 exits. Once the session is created, a CATProduct document can be loaded
with CATDocumentServices::Open.
CATSession *pSession = NULL; rc = ::Create_Session("CAA_PrdObjectPub_Session", pSession); ... //---------------------------------------------------------------------- // Opening an existing document with full path specified //---------------------------------------------------------------------- CATDocument *pDoc = NULL; rc = CATDocumentServices::Open(inputDoc, 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.
//---------------------------------------------------------------------- // Search for the document's root product //---------------------------------------------------------------------- CATIDocRoots* piDocRootsOnDoc = NULL; rc = pDoc->QueryInterface(IID_CATIDocRoots, (void**) &piDocRootsOnDoc); ... CATListValCATBaseUnknown_var* pRootProducts = piDocRootsOnDoc->GiveDocRoots(); CATIProduct_var spRootProduct = NULL_var; if (NULL != pRootProducts && pRootProducts->Size() > 0) { spRootProduct = (*pRootProducts)[1]; ... } else { cout << "Failed to get Root Product" << endl; return 5; } |
[Top]
Now that we have the root product, it is necessary to get its CATIProduct handle in order to access to its components.
//---------------------------------------------------------------------- // Get CATIProduct handle on the root product. //---------------------------------------------------------------------- CATIProduct *piProductOnRoot = NULL; if (NULL_var != spRootProduct) rc = spRootProduct->QueryInterface(IID_CATIProduct, (void**) &piProductOnRoot); ... //---------------------------------------------------------------------- // Get the root product's children //---------------------------------------------------------------------- CATListValCATBaseUnknown_var *pChildren = NULL; pChildren = piProductOnRoot->GetAllChildren(); int childCount = (pChildren == NULL ? 0 : pChildren->Size()); |
[Top]
Now that we have the CATIProduct handle on the root product and its components, we can display all the publications
//---------------------------------------------------------------------- // Displaying the publications of the root product and its components //---------------------------------------------------------------------- rc = PrintPublications(piProductOnRoot); if (0 != rc) return rc; for (int i = 1; i <= childCount; i++) { rc = PrintPublications((CATIProduct_var) (*pChildren)[i]); if (0 != rc) return rc; } |
The goal of the PrintPublications function is to display a product's publications. Using the CATIPrdObjectPublisher interface, it does the following tasks:
static int PrintPublications(CATIProduct *ipiProduct) { int rc; CATIPrdObjectPublisher *piPublisher = NULL; if (NULL == ipiProduct) return 0; rc = ipiProduct->QueryInterface(IID_CATIPrdObjectPublisher, (void **) &piPublisher); ... CATUnicodeString productName = ipiProduct->GetPartNumber(); cout << endl << "Publications of " << productName << ":" << endl; // // Retrieve the list of the publications of the current product. // CATListValCATUnicodeString *pPubList = NULL; int pubCount = piPublisher->ListPublications(pPubList); if (0 == pubCount || NULL == pPubList) { pubCount = 0; cout << " none" << endl; } ... |
... for (int i = 1; i <= pubCount; i++) { // // Print the publication name // CATUnicodeString& pubName = (*pPubList)[i]; cout << " Publication " << i << ": " << pubName.ConvertToChar() << endl; // // Retrieve the final publication object pointed to by // this publication name. // CATBaseUnknown *pPubObject = piPublisher->GetFinalObject(pubName); if (NULL == pPubObject) { cout << "Failed to get publication object of " << pubName << endl; return 10; } ... |
... // // List publications pointing to other sub publications // CATListValCATBaseUnknown_var *pSubPubrList = NULL; CATListValCATUnicodeString *pSubPubNameList = NULL; rc = piPublisher->IsFinallyPublished(pPubObject, pSubPubrList, pSubPubNameList); if (rc && NULL != pSubPubrList && NULL != pSubPubNameList && pSubPubrList->Size() > 0 && pSubPubNameList->Size() > 0) { cout << " is finally published as"; for (int i = 1; i <= pSubPubNameList->Size(); i++) cout << " " << (*pSubPubNameList)[i]; cout << endl; } ... |
... // // List publications directly on the geometry // CATListValCATUnicodeString *pNameList = NULL; rc = piPublisher->IsPublished(pPubObject, pNameList); if (rc && NULL != pNameList && pNameList->Size() > 0) { cout << " is published as"; for (int i = 1; i <= pNameList->Size(); i++) cout << " " << (*pNameList)[i]; cout << endl; } ... |
... // // Get the direct publication object // CATBaseUnknown *pSubPubr = NULL; CATUnicodeString subPubName; rc = piPublisher->GetDirectObject(pubName, pSubPubr, subPubName); if (2 == rc && NULL != pSubPubr) { cout << " is a subpublication of " << subPubName.ConvertToChar() << endl; } ... |
[Top]
The CATIPrdObjectPublisher interface also provides means to modify a product's publications as demonstrated by the ModifyPublication function.
This function takes three inputs:
and executes the following steps:
static int ModifyPublications(CATIProduct *ipiProduct, const char *ipubToDelete, const char *isubPubToPublish) { int rc; CATBaseUnknown *pSubPubr = NULL; CATUnicodeString subPubName; CATIPrdObjectPublisher *piPublisher = NULL; if (NULL == ipiProduct || NULL == ipubToDelete || NULL == isubPubToPublish) return 0; // // Get CATIPrdObjectPublisher on product and subpublisher // rc = ipiProduct->QueryInterface(IID_CATIPrdObjectPublisher, (void **) &piPublisher); ... |
... rc = piPublisher->GetDirectObject(ipubToDelete, pSubPubr, subPubName); if (2 != rc || NULL == pSubPubr) { cout << ipubToDelete << " is not a subpublication" << endl; return 0; } ... |
... CATIPrdObjectPublisher *piSubPublisher = NULL; rc = pSubPubr->QueryInterface(IID_CATIPrdObjectPublisher, (void **) &piSubPublisher); ... |
... // // Unpublish product publicattion // also unvaluate and unpublish corresponding subpublication // cout << endl; rc = piPublisher->Unpublish(ipubToDelete); cout << (rc ? ">> unpublished" : ">> failed to unpublish") << " publication "<< ipubToDelete << endl; ... |
... rc = piSubPublisher->Unvaluate(subPubName); cout << (rc ? ">> unvaluated" : ">> failed to unvaluate") << " subpublication " << subPubName << endl; rc = piSubPublisher->Unpublish(subPubName); cout << (rc ? ">> unpublished" : ">> failed to unpublish") << " subpublication " << subPubName << endl; ... |
... // // Create a new publication at the root product level and valuate it // cout << endl; CATBaseUnknown *pPubObject = NULL; pPubObject = piSubPublisher->GetFinalObject(isubPubToPublish); ... |
... CATUnicodeString newPubName(isubPubToPublish); newPubName += "Prod"; rc = piPublisher->Publish(newPubName); cout << (rc ? ">> created" : ">> failed to create") << " new publication " << newPubName << endl; ... |
... rc = piPublisher->Valuate(newPubName, pPubObject); cout << (rc ? ">> valuated" : ">> failed to valuate") << " publication " << newPubName << endl; ... |
[Top]
... //---------------------------------------------------------------------- // Save modified document //---------------------------------------------------------------------- char docDir[CATMaxPathSize]; char docName[CATMaxPathSize]; CATSplitPath(inputDoc, docDir, docName); CATUnicodeString newDoc = CATUnicodeString(outputDir) + "New" + docName; rc = CATDocumentServices::SaveAs(*pDoc, newDoc); ... |
[Top]
Before terminating the use case, we need to remove the document from the session before closing it.
... //---------------------------------------------------------------------- // Remove opened document from session //---------------------------------------------------------------------- rc = CATDocumentServices::Remove (*pDoc); ... //---------------------------------------------------------------------- //Delete the session //---------------------------------------------------------------------- rc = ::Delete_Session("CAA_PrdProp_Session"); |
[Top]
This use case has demonstrated how to retrieve a product publications and how to modify it:
[Top]
[1] | The Product Structure Model |
[2] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1.1 [Aug 2004] | Document revised |
Version: 1 [Sep 2003] | Document created |
[Top] |
Copyright © 2003, Dassault Systèmes. All rights reserved.