PLM之家 UG NX11.0二次开发(ufun和NXOpen C++)网络培训火热报名

PLM之家-上海点团信息科技有限公司工业4.0数字化软件官方知识管理平台

查看: 88|回复: 0

[资料] Catia二次开发源码分享: 获取装配所有组件列表

[复制链接]
  • TA的每日心情
    无聊
    昨天 09:37
  • 签到天数: 103 天

    连续签到: 9 天

    [LV.6]常住居民II

    1919

    主题

    3193

    帖子

    5万

    积分

    管理员

    PLM之家mildcat

    Rank: 9Rank: 9Rank: 9

    积分
    57829
    发表于 2018-1-10 10:12:25 | 显示全部楼层 |阅读模式

    请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

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

    x
    ' e. `% R) d9 A" N  x) ^! o% d
    Catia二次开发源码分享: 获取装配所有组件列表/ E1 z: `9 Y4 ~8 J% M! ^% r

    4 X( ^! x$ b& K+ p9 \7 [  p1 ~1 _  d3 {8 u& i; x- C
    [C] 纯文本查看 复制代码
    /* ----------------------------*/
    	/* 2. Retrieves Root Product   */
    	/* ----------------------------*/
    	
    	// Begin navigation through the document => start with the RootProduct.
    	CATIDocRoots* piDocRootsOnDoc = NULL;
    	rc = pDoc->QueryInterface(IID_CATIDocRoots,
    		                      (void**) &piDocRootsOnDoc);
    	if ( FAILED(rc) ) return 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;
    	}
    /** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 
    	piDocRootsOnDoc->Release();
    	piDocRootsOnDoc = NULL;
    	
    	// Get CATIProduct handle on the root product.
    	CATIProduct *piProductOnRoot = NULL;
    	rc = spRootProduct->QueryInterface(IID_CATIProduct,
    		                               (void**) &piProductOnRoot);
    	if ( FAILED(rc) ) return 3;
    
    	/* ---------------------------------------*/
    	/* 3. Retrieves children under the root   */
    	/* ---------------------------------------*/
    	
    	int nbOfDirectChidren = piProductOnRoot -> GetChildrenCount() ;
    	cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
    	
    	// then on a root product, get all the children agregated to it.
    	CATListValCATBaseUnknown_var*   ListChildren =
    		piProductOnRoot->GetAllChildren();
    /** @anchor err_2 piProductOnRoot not set to NULL after release */ 
    	piProductOnRoot -> Release();
    	piProductOnRoot = NULL;
    	if(NULL != ListChildren)
    	{
    		
    		int numberOfChildren = ListChildren->Size();
    		cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
    
    		/* -----------------------------------------------------------*/
    		/*  4. For each child, get its partNumber, and InstanceName   */
    		/* -----------------------------------------------------------*/
    		CATIProduct_var spChild = NULL_var;
    		for (int i=1;i<=numberOfChildren;i++)
    		{
    			spChild = (*ListChildren)[i];
    /** @anchor err_3 spChild not tested before use ( if !! ) */ 
    			if ( NULL_var == spChild ) return 4;
    			CATUnicodeString partNumber = spChild -> GetPartNumber();
    			CATUnicodeString instanceName (" ");
    			rc = spChild -> GetPrdInstanceName ( instanceName ) ;
    			if  ( FAILED(rc) ) return 4;
    			
    			cout << " child number : " << i << endl << flush;
    			cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
    			cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
    		}
    		delete ListChildren;
    		ListChildren=NULL;
    	}	
    	/* -------------------------------------------- */
    	/*   Ends the session                        */
    	/* -------------------------------------------- */
    : d9 M1 v) q7 ]9 {) i9 O( \
    上海点团信息科技有限公司,承接NX,CATIA,CREO等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施开发培训,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com
    回复

    使用道具 举报

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

    本版积分规则

    <

    QQ|小黑屋|手机版|Archiver|PLM之家-工业4.0数字化驱动之家 ( 沪ICP备13003373-3

    GMT+8, 2018-1-20 17:05 , Processed in 0.122700 second(s), 28 queries .

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