Catia的二次开发
更新时间:2023-09-29 18:53:01 阅读量: 综合文库 文档下载
近的项目也快结束了,第一次接触Catia的二次开发,对于一个以前完全没有学过Catia的人来说,当时感觉这似乎是不可能完成的任务。Catia二次开发多数是以VB进行,网上的资料也偏VB居多,而我们偏偏选择了CAA,使用C++开发。网上关于CAA的二次开发相关资料不多,但是CAA自带了很详细的说明文档,类库,和大量示例程序(虽然我至今也仍未跑成功过它的例子)。现在就准备将项目开发过程中一些认为比较重要的部分记录下来。
在项目中,有一个很重要的功能,就是上传Catia文件。普通的上传文档并不困难,但关键在于Catia文件带有相链接的文档,比如CATProduct文件,所以需要在程序中自动找到Catia文件的相链接的文档。
起初,在帮助文档中找到一篇关于Retrieving a Product's 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 <= attrInfoList.Size(); i++) {
CATAttributeInfos attrInfo = attrInfoList[i];
const CATUnicodeString& propertyName = attrInfo.Name(); //属性名 const CATUnicodeString& valueType = attrInfo.Type()->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 文档源,通过它也可以获得文档路径,但是我在尝试文档重定位的时候,并未成功? ? 。。。。。
? 下面是获得所有相联子部件的递归函数 [code]
void 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 <= n; i++) {
CATIxPDMItem_var item=oChildrenList[i]; if(SUCCEEDED(item->GetItemType(strType))) {
item->GetDocFileName(strSource) ; if(strType==\{
cout<<\文件 \}
else if(strType==\{
cout<<\文件 \GetSource(item); }
} } } } [/code]
CATIA CAA 二次开发详细教程(10) 文档操作方法 创建 加载 保存
一、创建(Create the new document)
CATDocument* pDoc = NULL; rc = CATDocumentServices::New(\pDoc) { cout << \creating New document\
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, \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 \
二、打开(Load the document)
CATDocument *pDoc = NULL; rc = CATDocumentServices::Open(argv[1], pDoc); if (SUCCEEDED(rc) && (NULL != pDoc)) { cout << \opened OK\<< endl << flush; } else { cout << \
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\<< endl << flush; return 1; } CATDocument *pDoc = pEditor->GetDocument(); if (NULL != pDoc) { cout << \opened OK\<< endl << flush; } else { cout << \
四、提取根容器(Retrieving the Document Root Container)
CATInit *piInitOnDoc = NULL; rc = pDoc -> QueryInterface (IID_CATInit, (void**) &piInitOnDoc); if (FAILED(rc)) { cout << \endl << flush; return 3; } const CATIdent idCATIContainer = \CATIContainer *piRootContainer = NULL; piRootContainer = (CATIContainer*) piInitOnDoc -> GetRootContainer(idCATIContainer); if (NULL == piRootContainer) { cout << \GetRootContainer\
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, argv[1]); if (SUCCEEDED(rc)) { cout << \
正在阅读:
Catia的二次开发09-29
2010-2012全国各地中考英语试题精选-补全对话04-18
道达尔食品级液压油46#NSF认证08-31
实验_维生素B1片含量测定的方法验证07-17
《五人墓碑记》知识点最全整理11-22
珍贵的经历作文500字07-06
《生活中的线条》教学设计07-01
第一章粘土胶体化学05-21
成都公交线路表(大全)06-05
档案学概论05-12
- 高一物理牛顿运动定律全套学习学案
- 水处理一级反渗透加还原剂亚硫酸氢钠后为什么ORP会升高
- 毕业设计(论文)-正文董家口 - 图文
- 荣盛酒店经营管理公司录用通知及入职承诺书II
- 第二讲 大学英语四级快速阅读技巧
- 质量管理体系文件(2015年委托第三方医药物流配送企业专用版本)
- 214071收款办法
- 苏轼对《文选》选文的评价
- 《诊断学基础B》1-8作业
- 广东省东莞市高一数学下学期期末教学质量检查试题
- 海南电网公司VIS推广应用管理办法
- 红星照耀中国习题
- 苏教版小学语文六年级上册期末复习资料之生字词整理
- 局域网组建与应用—王向东
- 税务稽查内部管理文书样式
- 环保社会实践调查表
- 九年级思品第一单元复习
- 2016年全国注册咨询工程师继续教育公路路线设计规范试卷
- 毕业设计-青岛港董家口港区防波堤设计
- 撞背锻炼方法与益处
- 开发
- Catia
- FPGE 三速以太网说明
- 采购64排CT的论证报告
- 第六节 塑胶基础施工方案 第八节 合成面层施工方案合成面层施工方案跑道周长为环形跑道8道次、100m跑道为10
- 2015年中学语文教师资格《学科知识与教学能力》试题及答案(1)
- 三年级奥数第一讲 - - 整数加减法巧算
- 生理4
- 2017年贵州省贵阳市中考数学试卷
- 制度汇编(二仓储部分)
- 030101制信用证开证申请书 - 图文
- 通风空调系统降噪设计措施探讨
- §7.1.3三角形的稳定性导学案
- DZD-6A使用说明 - 图文
- 大豆中β淀粉酶的提取、分离纯化、测活及固定化
- 盘点那些在三亚拍婚纱照使用的高深技巧
- 卫星通信基础知识(五) EIRP G-T值的意义
- 数字媒体技术专业详细全面毕业实习报告范文总结模板(可编辑)
- 中国人民银行征信中心常见问题解答
- 控申工作办案流程
- 2017-2023中国光伏逆变器市场行情动态报告(目录) - 图文
- 药物分析期末考试