iCAx开思工具箱

标题: 怎么获得产品下面一个零件的document信息啊? [打印本页]

作者: lyy4566    时间: 2011-3-17 22:20
标题: 怎么获得产品下面一个零件的document信息啊?
CATDocument * pProductDocument = NULL;
rc = CATDocumentServices::OpenDocument("E:\\14V_1\\ass2\\r14WK.CATProduct",pProductDocument);

if ( FAILED(rc) || (NULL == pProductDocument) )  AfxMessageBox(_T("2!"));
/* ----------------------------*/
/* 2. Retrieves Root Product   */
/* ----------------------------*/


// 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;

     if (pRootProducts && pRootProducts->Size())
{   
  spRootProduct = (*pRootProducts)[1];
          delete   pRootProducts;
    pRootProducts=NULL;
}
     piDocRootsOnDoc->Release();


// 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;

  spChild = (*ListChildren)[6];
    spChild1 = (*ListChildren)[7];   

spChild->GetShapeRep(spCATILinkableObject ,"Default", CATPrd3D, TRUE);
  CATDocument * pCATDocument=NULL;
  pCATDocument=spCATILinkableObject->GetDocument();
CATInit  *pInitOnDoc=NULL ;
pCATDocument->QueryInterface(IID_CATInit,(void **) &pInitOnDoc);
CATIPrtContainer *pPrtCont = NULL ;
  pPrtCont=  (CATIPrtContainer*) pInitOnDoc->GetRootContainer("CATIPrtContainer");
    CATIPrtPart_var spPart = pPrtCont->GetPart();

为什么编译的时候能够成功,而在运行的时候到最后一句CATIPrtPart_var spPart = pPrtCont->GetPart();就出错啊?

新人刚学CAA,求高人指教!不甚感激!
这几天被搞得没有信心学了啊....
作者: lyy4566    时间: 2011-3-17 22:23
上面spCATILinkableObject 已经定义,刚复制漏了一行
CATILinkableObject_var   spCATILinkableObject ;
谢谢!期待高手解答 1#  
作者: linlily0925    时间: 2011-3-23 09:35
你试下先得到CATIContainer,再将CATIContainer转化为CATIPrtContainer ~~,你出错很有可能是因为你的CATIPrtContainer 没有成功得到哦~~~
作者: lyy4566    时间: 2011-3-24 16:38
恩,确实是CATIPrtContainer没有获得成功,现在先获得CATIContainer就可以了,谢谢楼上的 3#  
作者: 一朵梨花    时间: 2011-3-26 22:06
Language="VBSCRIPT"

Sub CATMain()


Set productDocument1 = CATIA.ActiveDocument


Set product1 = productDocument1.Product


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

'assemblyConvertor1.SetCurrentFormat arrayOfVariantOfBSTR1

Dim arrayOfVariantOfBSTR2(1)  'change number if you have more custom columns/array...
arrayOfVariantOfBSTR2(0) = "Quantity"
arrayOfVariantOfBSTR2(1) = "Part Number"

'assemblyConvertor1.SetSecondaryFormat arrayOfVariantOfBSTR2

assemblyConvertor1.Print "TXT", "c:\OutPut_BOM.txt", product1

End Sub
作者: huahua90428    时间: 2011-12-12 10:51
期待高手解答
作者: yuhuimoon    时间: 2011-12-17 23:46


CATSession * CATIASession=NULL;
        CATDocument * pRootDoc  = NULL ;
        CATIASession=CATSession::GetPtrSession();

         CATFrmEditor * piEditor =CATFrmEditor::GetCurrentEditor();
        pRootDoc = piEditor->GetDocument();

        CATInit_var spInit = pRootDoc;
        spInit->Init(TRUE);

        CATIPrtContainer * piPartContainer = (CATIPrtContainer*) spInit->GetRootContainer("CATIPrtContainer");
        if (piPartContainer == NULL)
        {
                return E_FAIL;
        }
        CATIGSMFactory * pFact = NULL;
        rc = piPartContainer -> QueryInterface(IID_CATIGSMFactory, (void**)&pFact);
        if (pFact == NULL)
        {
                return E_FAIL;
        }

        CATIContainer_var    spCont     = pFact ;
        CATIPrtContainer_var spPartCont = spCont;






欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3