Catia的二次开发.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《Catia的二次开发.doc》由会员分享,可在线阅读,更多相关《Catia的二次开发.doc(31页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-*近的项目也快结束了,第一次接触Catia的二次开发,对于一个以前完全没有学过Catia的人来说,当时感觉这似乎是不可能完成的任务。Catia二次开发多数是以VB进行,网上的资料也偏VB居多,而我们偏偏选择了CAA,使用C+开发。网上关于CAA的二次开发相关资料不多,但是CAA自带了很详细的说明文档,类库,和大量示例程序(虽然我至今也仍未跑成功过它的例子)。现在就准备将项目开发过程中一些认为比较重要的部分记录下来。在项目中,有一个很重要的功能,就是上传Catia文件。普通的上传文档并不困难,但关键在于Catia文件带有相链接的文档,比如CATProduct文件,所以需要在程序中自动找到Cat
2、ia文件的相链接的文档。起初,在帮助文档中找到一篇关于Retrieving a Products Properties的文章,其中介绍了如何打印一个文档的属性。首先它获得文档的根CATIProduct对象,然后获得它的所有孩子GetAllChildren(),这个方法将获得CATIProduct对象的所有孩子,并且不分层次。然后使用CATIAttributesDescription类来获得CATIProduct的属性名,最后通过CATIInstance对象获得属性名对应的属性值,从CATIProduct获得CATIAttributesDescription和CATIInstance对象的操作如
3、下:CATIProduct *iInstanceProd;.CATIAttributesDescription *piAttrDesc = NULL;iInstanceProd-QueryInterface(IID_CATIAttributesDescription, (void *) &piAttrDesc);CATIInstance *piInstance = NULL;rc = iInstanceProd-QueryInterface(IID_CATIInstance, (void *) &piInstance);接着就可以使用CATIAttributesDescription的List
4、()方法将属性获取到一个CATListValCATAttributeInfos对象中,然后就是对CATListValCATAttributeInfos的一个遍历过程。CATListValCATAttributeInfos attrInfoList;piAttrDesc-List(&attrInfoList);for (int i = 1; i Name(); /属性类型CATIValue *pValue = piInstance-GetValue(propertyName); /获得对应属性名的属性值上面方式是在不知道有什么属性的时候将所有属性都获取出来,如果知道属性名称的话,直接通过CATI
5、Instance的GetValue(.)就可以获取该属性名的属性值,比如零部件号的属性名对应的是PartNumber,还有一些用户自定义的参数也可以同样获取到。到这时,我认为通过它能够获得文档的路径,因为里面有一个属性名DefaultRepSource,就是默认的链接文档源,的确在测试中,通过该属性也能获取部分文档的保存路径,但只限于CATPart文件,而对于CATProduct文件却是NULL,找了很多方法,但是通过使用CATIInstance对象来获取CATProduvt孩子中的CATProduct文件地址还是不行。如何获得孩子的所有文档路径,只能寻找别的方法。于是发现了CATIxPDMI
6、tem这个类,这个类很强大,它可以获得文档的所有属性,还有文档是否需要保存等信息。如何获得CATIxPDMItem的实例,版本不同CAA还是有区别,r_16之上和r_14(r_15没试过)的获取CATIxPDMItem对象方法完全不同,两个版本的CATIxPDMItem的方法也不同,虽然高版本的保留了低版本的方法。至于如何获取CATIxPDMItem对象,r_14版本中需要使用到CATxPDMSession对象,而r-16版本则使用CATxPDMSessionServices的静态方法,这里只说r_16版本的(可以在类库中查找CATIxPDMItem,查看不同版本的获得该对象方法)。CATIx
7、PDMItem_var mItem;CATDocument *pDoc;CATxPDMSessionServices:GetItemFromDocument(pDoc,mItem);以上方法将pDoc中获得CATIxPDMItem对象。现在看一下CATIxPDMItem的方法:GetChildren(CATLISTV(CATBaseUnknown_var)&,CATLISTP(CATMathTransformation)这是保留的低版本中的获取孩子的方法GetChildrenItems(CATListValCATIxPDMItem_var&,CATLISTP(CATMathTransforma
8、tion)两个方法都是获得CATIxPDMItem当前下一层的孩子,但是对于再下一层的孩子无法获得,所以如果要获得所有孩子需要递归或者迭代的方法。GetDocFileName(CATUnicodeString& ) 该方法可以获得文档的保存路径GetDocId(CATIDocId* ) CATIDocId是一个很基本的包含文档属性的类,通过它也可以获得文档路径,还有文档类型GetItemType(CATUnicodeString& ) 获得文档类型,由于在r_14版本中并没有该方法,所以在r_14中需要间接的从CATIDocId获得文档类型GetProperty(CATUnicodeStrin
9、g&,CATUnicodeString& )获得指定属性名的属性值SetProperty(CATUnicodeString&,CATUnicodeString& ) 设置指定属性名的值标准的属性名有:? CN_PART_NUMBER 零部件号? CN_REVISION 版本? CN_DEFINITION 定义? CN_NOMENCLATURE? CN_DESCRIPTIONREF 描述? CN_SOURCE 文档源,通过它也可以获得文档路径,但是我在尝试文档重定位的时候,并未成功?? 。? 下面是获得所有相联子部件的递归函数codevoid GetSource(CATIxPDMItem_var
10、 mItem)HRESULT rc;CATUnicodeString strSource;CATUnicodeString strType;CATUnicodeString strName;CATListValCATIxPDMItem_var oChildrenList;CATLISTP(CATMathTransformation) oChildrenLocationList ;rc=mItem- GetChildrenItems( oChildrenList, oChildrenLocationList) ;if(SUCCEEDED (rc)int n=oChildrenList.Size(
11、);for (int i = 1; i GetItemType(strType)item-GetDocFileName(strSource) ;if(strType=CATPart )coutCATPart , 文件 i strSource.ConvertToChar()endl;else if(strType=CATProduct )coutCATProduct , 文件 i strSource.ConvertToChar()endl;GetSource(item);/codeCATIA CAA 二次开发详细教程(10) 文档操作方法 创建 加载 保存一、创建(Create the new
12、document)CATDocument* pDoc = NULL; rc = CATDocumentServices:New(Part,pDoc); if (NULL != pDoc) cout New document created OK endl flush; else cout ERROR in creating New document endl flush; return 2; Now that the session is opened, you can create a new document using the New static method of CATDocume
13、ntServices. This method creates a document and initializes it, allowing it to be loaded and stored and making it editable. In this use case, a predefined document type, Part, is used as a document type. In interactive mode, this is the name that appears when performing a File/New operation. It is no
14、t the file extension, which, in this case, is CATPart.二、打开(Load the document)CATDocument *pDoc = NULL; rc = CATDocumentServices:Open(argv1, pDoc); if (SUCCEEDED(rc) & (NULL != pDoc) cout Document opened OK endl flush; else cout ERROR in opening an existing document endl flush; return 2; Now that the
15、 session is opened, you can load an existing document using the Open static method of CATDocumentServices. This method needs, as a first parameter, the entire storage path name and document name of the existing document that we want to load into the session. In this use case, we enter this informati
16、on as an argument to the program. The second parameter of the Open method returns a CATDocument pointer to the document it has loaded. Once the document exists in the session, you can work with objects within it, using specific interfaces external to the ObjectModelerBase framework.三、获取当前文档CATFrmEdi
17、tor * pEditor = GetEditor(); if (NULL != pEditor ) cout Editor got OK endl flush; else cout ERROR in getting the current editor endl GetDocument(); if (NULL != pDoc) cout Document opened OK endl flush; else cout ERROR in opening an existing document endl QueryInterface (IID_CATInit, (void*) &piInitO
18、nDoc); if (FAILED(rc) cout ERROR in QueryInterface on CATInit for doc endl GetRootContainer(idCATIContainer); if (NULL = piRootContainer) cout ERROR in GetRootContainer endl flush; return 4; The document root container is retrieved using the CATInit:GetRootContainer method. The CATIContainer handle
19、retrieved through GetRootContainer will be necessary whenever you want to create or manipulate objects in the document.五、保存文档(Save the Document) 5.1 另存rc = CATDocumentServices:SaveAs (*pDoc, argv1); if (SUCCEEDED(rc) cout Document saved OK endl flush; else cout ERROR in saving document endl flush; r
20、eturn 5; To save the new document, use the SaveAs static method of CATDocumentServices. This method takes the pointer to the document created by New as a first parameter, and the storage path name and document name under which the document is to be stored as a second parameter. In this use case, we
21、pass the storage path name and document name as an argument to the program.5.2 保存rc = CATDocumentServices:Save (*pDoc); if (SUCCEEDED(rc) cout Document saved OK endl flush; else cout ERROR in saving document endl flush; return 3; To save the new document under the same name, use the Save static meth
22、od ofCATDocumentServices. This method takes the CATDocument pointer to the documentas the only parameter.六、删除(Remove the document)rc = CATDocumentServices:Remove (*pDoc); if (SUCCEEDED(rc) cout Document removed OK endl flush; else cout ERROR in removing document endl flush; return 6; If you ever nee
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- catia 二次开发
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内