找回密码 注册 QQ登录
一站式解决方案

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?快速3D打印 手板模型CNC加工服务在线3D打印服务,上传模型,自动报价
查看: 19669|回复: 6
打印 上一主题 下一主题

[求助] 怎么获得产品下面一个零件的document信息啊?

[复制链接]
跳转到指定楼层
1
发表于 2011-3-17 22:20:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
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,求高人指教!不甚感激!
这几天被搞得没有信心学了啊....
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 赞一下!赞一下!
2
发表于 2011-3-17 22:23:17 | 只看该作者
上面spCATILinkableObject 已经定义,刚复制漏了一行
CATILinkableObject_var   spCATILinkableObject ;
谢谢!期待高手解答 1# lyy4566
3
发表于 2011-3-23 09:35:13 | 只看该作者
你试下先得到CATIContainer,再将CATIContainer转化为CATIPrtContainer ~~,你出错很有可能是因为你的CATIPrtContainer 没有成功得到哦~~~
4
发表于 2011-3-24 16:38:54 | 只看该作者
恩,确实是CATIPrtContainer没有获得成功,现在先获得CATIContainer就可以了,谢谢楼上的 3# linlily0925
5
发表于 2011-3-26 22:06:11 | 只看该作者
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
6
发表于 2011-12-12 10:51:27 | 只看该作者
期待高手解答
7
发表于 2011-12-17 23:46:42 | 只看该作者
本帖最后由 yuhuimoon 于 2011-12-17 23:53 编辑

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;

您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-12-24 02:51 , Processed in 0.030091 second(s), 13 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

快速回复 返回顶部 返回列表