// Begin navigation through the document => start with the RootProduct.
CATIDocRoots* piDocRootsOnDoc = NULL;
rc = pProductDocument->QueryInterface(IID_CATIDocRoots,
(void**) &piDocRootsOnDoc);
if ( FAILED(rc) ) AfxMessageBox(_T("3!"));
// get the root product which is the first element of root elements
CATListValCATBaseUnknown_var * pRootProducts =
piDocRootsOnDoc->GiveDocRoots();
CATIProduct_var spRootProduct = NULL_var;
// Get CATIProduct handle on the root product.
CATIProduct *piProductOnRoot = NULL;
rc = spRootProduct->QueryInterface(IID_CATIProduct,
(void**) &piProductOnRoot);
if ( FAILED(rc) ) AfxMessageBox(_T("3!"));
/* --------------------------------------------------------- */
/* Imports an existing CATProduct under the root product. */
/* --------------------------------------------------------- */
CATDocument *pDocPart = NULL;
CATIProduct *piInstanceProd = NULL;
// load the given CATPart
rc = CATDocumentServices::OpenDocument(ifileName,pDocPart);
if ( FAILED(rc) || (NULL==pDocPart) ) AfxMessageBox(_T("4!"));
// agregates an instance of the CATPart root element under the product
rc = OpenResource::AddExternalComponent(piProductOnRoot,pDocPart,&piInstanceProd);
if ( FAILED(rc) ) AfxMessageBox(_T("5!"));
/* ---------------------------------------*/
/* 3. Retrieves children under the root */
/* ---------------------------------------*/
// then on a root product, get all the children agregated to it.
CATListValCATBaseUnknown_var* ListChildren = piProductOnRoot->GetChildren("CATIProduct");
/** @anchor err_2 piProductOnRoot not set to NULL after release */
int numberOfChildren = 0;
numberOfChildren = ListChildren->Size();
CString str;
str.Format(_T("%d"), numberOfChildren);
AfxMessageBox(str);
/* -----------------------------------------------------------*/
/* 4. For each child, get its partNumber, and InstanceName */
/* -----------------------------------------------------------*/
CATIProduct_var spChild = NULL_var;
CATIProduct_var spChild1 = NULL_var;
Set assemblyConvertor1 = product1.GetItem("BillOfMaterial")
Dim arrayOfVariantOfBSTR1(7) 'change number if you have more custom columns/array...
arrayOfVariantOfBSTR1(0) = "Quantity"
arrayOfVariantOfBSTR1(1) = "Part Number"
arrayOfVariantOfBSTR1(2) = "Type"
arrayOfVariantOfBSTR1(3) = "Nomenclature"
arrayOfVariantOfBSTR1(4) = "Revision"
arrayOfVariantOfBSTR1(5) = "Mass" 'in addition of what is by default
arrayOfVariantOfBSTR1(6) = "Density" 'in addition of what is by default
arrayOfVariantOfBSTR1(7) = "Material" 'in addition of what is by default
Dim arrayOfVariantOfBSTR2(1) 'change number if you have more custom columns/array...
arrayOfVariantOfBSTR2(0) = "Quantity"
arrayOfVariantOfBSTR2(1) = "Part Number"