已阅读5页,还剩23页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
近的项目也快结束了,第一次接触Catia的二次开发,对于一个以前完全没有学过Catia的人来说,当时感觉这似乎是不可能完成的任务。Catia二次开发多数是以VB进行,网上的资料也偏VB居多,而我们偏偏选择了CAA,使用C+开发。网上关于CAA的二次开发相关资料不多,但是CAA自带了很详细的说明文档,类库,和大量示例程序(虽然我至今也仍未跑成功过它的例子)。现在就准备将项目开发过程中一些认为比较重要的部分记录下来。在项目中,有一个很重要的功能,就是上传Catia文件。普通的上传文档并不困难,但关键在于Catia文件带有相链接的文档,比如CATProduct文件,所以需要在程序中自动找到Catia文件的相链接的文档。起初,在帮助文档中找到一篇关于Retrieving a Products Properties的文章,其中介绍了如何打印一个文档的属性。首先它获得文档的根CATIProduct对象,然后获得它的所有孩子GetAllChildren(),这个方法将获得CATIProduct对象的所有孩子,并且不分层次。然后使用CATIAttributesDescription类来获得CATIProduct的属性名,最后通过CATIInstance对象获得属性名对应的属性值,从CATIProduct获得CATIAttributesDescription和CATIInstance对象的操作如下:CATIProduct *iInstanceProd;.CATIAttributesDescription *piAttrDesc = NULL;iInstanceProd-QueryInterface(IID_CATIAttributesDescription, (void *) &piAttrDesc);CATIInstance *piInstance = NULL;rc = iInstanceProd-QueryInterface(IID_CATIInstance, (void *) &piInstance);接着就可以使用CATIAttributesDescription的List()方法将属性获取到一个CATListValCATAttributeInfos对象中,然后就是对CATListValCATAttributeInfos的一个遍历过程。CATListValCATAttributeInfos attrInfoList;piAttrDesc-List(&attrInfoList);for (int i = 1; i Name(); /属性类型CATIValue *pValue = piInstance-GetValue(propertyName); /获得对应属性名的属性值上面方式是在不知道有什么属性的时候将所有属性都获取出来,如果知道属性名称的话,直接通过CATIInstance的GetValue(.)就可以获取该属性名的属性值,比如零部件号的属性名对应的是PartNumber,还有一些用户自定义的参数也可以同样获取到。到这时,我认为通过它能够获得文档的路径,因为里面有一个属性名DefaultRepSource,就是默认的链接文档源,的确在测试中,通过该属性也能获取部分文档的保存路径,但只限于CATPart文件,而对于CATProduct文件却是NULL,找了很多方法,但是通过使用CATIInstance对象来获取CATProduvt孩子中的CATProduct文件地址还是不行。如何获得孩子的所有文档路径,只能寻找别的方法。于是发现了CATIxPDMItem这个类,这个类很强大,它可以获得文档的所有属性,还有文档是否需要保存等信息。如何获得CATIxPDMItem的实例,版本不同CAA还是有区别,r_16之上和r_14(r_15没试过)的获取CATIxPDMItem对象方法完全不同,两个版本的CATIxPDMItem的方法也不同,虽然高版本的保留了低版本的方法。至于如何获取CATIxPDMItem对象,r_14版本中需要使用到CATxPDMSession对象,而r-16版本则使用CATxPDMSessionServices的静态方法,这里只说r_16版本的(可以在类库中查找CATIxPDMItem,查看不同版本的获得该对象方法)。CATIxPDMItem_var mItem;CATDocument *pDoc;CATxPDMSessionServices:GetItemFromDocument(pDoc,mItem);以上方法将pDoc中获得CATIxPDMItem对象。现在看一下CATIxPDMItem的方法:GetChildren(CATLISTV(CATBaseUnknown_var)&,CATLISTP(CATMathTransformation)这是保留的低版本中的获取孩子的方法GetChildrenItems(CATListValCATIxPDMItem_var&,CATLISTP(CATMathTransformation)两个方法都是获得CATIxPDMItem当前下一层的孩子,但是对于再下一层的孩子无法获得,所以如果要获得所有孩子需要递归或者迭代的方法。GetDocFileName(CATUnicodeString& ) 该方法可以获得文档的保存路径GetDocId(CATIDocId* ) CATIDocId是一个很基本的包含文档属性的类,通过它也可以获得文档路径,还有文档类型GetItemType(CATUnicodeString& ) 获得文档类型,由于在r_14版本中并没有该方法,所以在r_14中需要间接的从CATIDocId获得文档类型GetProperty(CATUnicodeString&,CATUnicodeString& )获得指定属性名的属性值SetProperty(CATUnicodeString&,CATUnicodeString& ) 设置指定属性名的值标准的属性名有:? CN_PART_NUMBER 零部件号? CN_REVISION 版本? CN_DEFINITION 定义? CN_NOMENCLATURE? CN_DESCRIPTIONREF 描述? CN_SOURCE 文档源,通过它也可以获得文档路径,但是我在尝试文档重定位的时候,并未成功?? 。? 下面是获得所有相联子部件的递归函数codevoid GetSource(CATIxPDMItem_var 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();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 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 CATDocumentServices. 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 not 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 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 information 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.三、获取当前文档CATFrmEditor * 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*) &piInitOnDoc); 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 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; return 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 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 method 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 needed to re-open the document during this same session, it would then be necessary to also remove it from the session after having saved it. Otherwise, you need not worry about it since deleting the session will automatically remove the document as well. To remove the document, you should use the Remove static method of CATDocumentServices.七、按指定文档格式保存(Exporting a Document Format Type) 7.1 Defining the New Document Format TypeCATProduct_OmbExportType CATIExportTypeManager libCAAOmbExportTypeA new document format type is simply defined by adding a new entry in the current frameworks dictionary. This new entry will cause the File/SaveAs dialog box to list the new format type among the types defined to the save operation. The first parameter,CATProduct_OmbExportType, indicates that the exporting document is a Product-typedocument (i.e., a document having a .CATProduct suffix) and that the exported document format type is OmbExportType, which will also be the suffix of the saved document. The second parameter indicates that this new document type will implement the CATIExportTypeManager interface in order to define the specific save operations necessary to export the new document. The last parameter is the name of the library in which the implementation module is to be found.7.2 Implementing CATIExportTypeManagerSee the Object Modeler articles 2 for a detailed explanation about interface implementations. The implementation of CATIExportTypeManager is found in the CAAOmbExportType.m module defining the CAAEOmbExportTypeData implementation class.CATImplementClass( CAAEOmbEExportTypeData, CodeExtension, CATBaseUnknown, CATProduct_OmbExportType );The CATImplementClass macro defines the implementation classCAAEOmbExportTypeData as a code extension implementing the CATProduct_OmbExportType late type.#include TIE_CATIExportTypeManager.h TIE_CATIExportTypeManager( CAAEOmbExportTypeData );The above statement indicates that this is an implementation of theCATIExportTypeManager interface.HRESULT CAAEOmbExportTypeData:ExportData ( CATDocument *pDoc, CATUnicodeString path ) cout * Begin ExportData 1 endl flush; HRESULT rc = CATDocumentServices:SaveAs (*pDoc, path); return rc;In this case, the document is simply saved using the SaveAs method ofCATDocumentServices. However, it is in this method that you must code any specificsave operations necessary for your new document type.三、使用组件应用架构的 CATIA 界面二次开发方法下面的例子说明了如何使用 CAA C+开发方式来建立一个 CATIA 内部程序。实现的功能是新建一个 独立的工作台(workbench),并在其下面实现添加自定义菜单,添加工具条以及按钮图标,插入 CATIA 风 格的对话框。并生成对界面功能的响应,建立 command,实现调用对话框,以及通过输入参数直接用代码 生成一个三维模型,并在 CATIA 主窗口中显示。1、 新建独立的 workbenchCATIA V5 将某类包含一系列交互命令的一些工具条分组显示在不同的工作台(workbench)中, 这样有 利于工具的查找和使用。通过自己新建的 workbench 可以将自己二次开发形成的一系列命令集中显示在一 个工作台中,便于以后的操作。工作台的建立需要以下几个步骤。创建工作台厂(factory)的接口(interface);创建工作台厂;创建工作台描述类;创建响应命令(command)的标题;创建工作台并排列图标按钮响应;提供图片及提示等资源并将新建的工作台插入开始菜单;创建工作台的显示界面。插入新建的工作台 MyWorkBench 后的 CATIA 开始菜单如图 3 所示,它与 CATIA 现有的模块成为并 列关系。现在进入 MyWorkBench 工作台里面没有任何工具条及按钮,下面添加这部分工具。生成的新的工作台2、 添加工具条及按钮首先创建按钮的描述类 CAAAfrGeoCreationWkb,派生于 CATBaseUnknown 类。CATBaseUnknow n 是创建用户界面并实现界面的基类,所有的接口都是从 IUnknown/CATBaseUnknown 继承的。这个类中 建立了两个函数分别为 CATCmdWorkbench *的 CreateWorkbench()函数和无返回值类型的 CreateComm ands()。前面的函数是用来实现顺序插入工具条、按钮图标以及菜单,后面的函数是实现对插入按钮以及 菜单和响应函数的关联。在 CreateWorkbench()函数中用到了宏 NewAccess(className,variableName,objectName)。CATIA 的工作场(workshop)或者工作台(workbench)可以被看作是一个入口的集合包,使用 NewAccess 宏可以创 建一个这样的入口。 使用 SetAccessChild(variableName,childName)以及 SetAccessNext (variableName, nextName)这两个宏则可以连接入口。其中 className 表示被创建类的类型,包括以下几种类型:CATC mdContainer,CATCmdWorkshop,CATCmdSeparator,CATCmdStarter。下面就是创建了一个按钮的 容器,也就是工具条,并在其中添加按钮的部分代码。NewAccess(CATCmdContainer,pCAAAfrTB1EltTlb,CAAAfrTB1EltTlb);/创建工具条 pCAAAfrTB1Elt TlbSetAccessChild(pCAAAfrGeoCreationWkb, pCAAAfrTB1EltTlb); /工具条加入工作台/创建按钮 cmd1,并设置其响应宏为 CAAAfrCmd1Hdr,最后将其加入工具条 TB1 中NewAccess(CATCmdStarter,pCAAAfrTTB1EltCmd1Str,CAAAfrTTB1EltCmd1Str);SetAccessCommand(pCAAAfrTTB1EltCmd1Str,CAAAfrCmd1Hdr);SetAccessChild(pCAAAfrTB1EltTlb,pCAAAfrTTB1EltCmd1Str);接下来绘制一个图标,并在 CAAAfrGeoCreationWkbHeader.CATRsc 中将其关联,具体如下,则 cm d1 按钮显示的是 CAACmd1.Bmp 图标。CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.Icon.Normal = I_CAACmd1;在 CAAAfrGeoCreationWkbHeader.CATNls 文件中设置新建按钮的标题以及提示内容CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.Category = Element;CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.Title = command1;CAAAfrGeoCreationWkbHeader.CAAAfrCmd1Hdr.ShortHelp = new cmd1;添加两个工具条并插入一系列按钮的效果图如下面图 4 所示。图 4 、5 新添加的按钮添加的菜单3、添加菜单菜单的添加与添加按钮类似,也是在 CreateWorkbench()函数中,只不过是在宏中的参数与添加按钮 并不一样。添加后的效果图如图 5 所示NewAccess(CATCmdContainer, pCAAAfrGeoCreationMbr, CAAAfrGeoCreationMbr);NewAccess(CATCmdContainer, pCATAfrInsertMnu, CATAfrInsertMnu);SetAccessChild(pCAAAfrGeoCreationMbr, pCATAfrInsertMnu);NewAccess(CATCmdSeparator, pCAAAfrGeoCreationInsertSep, CAAAfrGeoCreationInsertSep);SetAccessChild(pCATAfrInsertMnu, pCAAAfrGeoCreationInsertSep);NewAccess(CATCmdContainer, pCAAAfrMeu1EltSnu, CAAAfrMeu1EltSnu);SetAccessNext(pCAAAfrGeoCreationInsertSep, pCAAAfrMeu1EltSnu);NewAccess(CATCmdStarter, pCAAAfrMMeu1SubMn1Str, CAAAfrMMeu1SubMn1Str);SetAccessChild(pCAAAfrMeu1EltSnu, pCAAAfrMMeu1SubMn1Str);SetAccessCommand(pCAAAfrMMeu1SubMn1Str, CAAAfrCmd1Hdr);在 CAAAfrGeoCreationWkb.CATNls 文件中设置菜单显示的属性。CAAAfr Meu1EltSnu.Title = 新建菜单 1 ;CAAAfr Meu1EltTlb.Title = command1 ;3、 建立菜单以及按钮的响应类建好的 workbench 空框架中可以创建三种类型的响应(command)类, 他们都是 CATCommand 派生出 来的。具体添加过程是打开 CAA Rade 菜单Insert,选择 CATIA Resource下的Command.。可以 选择 Statechart command,dialog-box based command 和 Basic command。Basic command 是创建 一个空的响应类,在函数 Activate( CATCommand * iFromClient, CATNotification * iEvtDat)中添加响 应。dialog-box based command 在二次开发中会被更多的用到。选择该类型响应类,在运行的时候会直 接弹出一个对话框,当然,可以对这个对话框进行编辑。对话框编辑界面如图 6 所示,里面有一个正在编 辑的对话框,在图的中部,右边是自带的一些控件,包括 CATDlgFrame,CATDlgLabel,CATDlgEditor,CATDlgPushButton,CATDlgRadioButton 等等。对话框内所有的控件在 Build()函数中列出,应用函数 S etGridConstraints(short int iTopRow, short int iLeftColumn, short int iRowSpan, unsigned int iJustifi cation)通过设置控件在对话框中矩阵位置的方式来调整位置。为控件添加回调函数来响应各种操作。如图 7 所示,CATDlgPushButton 按钮控件包括 Creation,Vi sibility swap,Resizement,Button activation 以及 Repetitive button activation5 中回调函数。选择 Butt on activation 产生点击响应生成回调函数 On
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026江西南昌大学招聘科研助理1人(八)笔试备考试题及答案详解
- 2026广东清远市英德市人民医院招聘高层次卫生专业技术人才3人考试备考试题及答案详解
- 2026吴忠市红寺堡区公立医疗机构自主公开招聘备案制专业技术人员的笔试备考试题及答案详解
- 2026甘肃临夏州临夏市下半年征兵笔试备考试题及答案详解
- 2026浙江衢州市常山县招考教师8人笔试模拟试题及答案详解
- 2025年武汉市青山区网格员招聘笔试试题及答案详解
- 2026安徽合肥市第一人民医院康复技师招聘5人笔试备考题库及答案详解
- 2026甘肃酒泉市事业单位招聘466人笔试参考题库及答案详解
- 2026重庆市畜牧科学院科技成果转化(威远)示范基地招聘1人笔试备考题库及答案详解
- 2026广西南宁市第二十九中学招聘顶岗教师7人笔试参考题库及答案详解
- 2026届浙江省九年级数学中考一模模拟试卷(含答案详解与评分标准)
- 2026年幼儿园环境创设第一节的
- 2026年企业数据资源盘点与治理实施指南
- 北京中国民用航空适航审定中心2025年招聘事业单位工作人员笔试历年典型考点题库(附带答案详解)
- 作业活动风险分级管控清单
- EAST5.0数据结构一览表
- 脱硫综合楼上部结构模板支撑工程超危大专项施工方案
- 保健按摩师-国家职业标准(2023年版)
- 2024年中国融通医疗健康集团有限公司招聘笔试参考题库含答案解析
- 纪检机关查办案件分析报告
- 安徽精高水处理有限公司12.8万吨-年水处理剂系列产品项目环境影响报告书
评论
0/150
提交评论