一、前言
上一期主要带大家一起熟悉了 CATIA V6 API
的架构,如何高效地搜索 API
以及 CATIA
对象本身的一些属性和方法。这一期主要围绕基于服务器的搜索功能展开,并在文末为广大(实则不到300人😂)的读者们准备的一份新年福利。言归正传,前几期也都提到了,CATIA V6
采用的是中央服务器的存储架构,以数据库的形式来存储模型数据,这种方式大大提高了协同工作效率,但同时也给文件的CUID
(增删改查)操作带来了诸多不便,原来直接操作文件即可完成的功能变成了需要用数据库查询语言间接操作数据库中的文件/数据,虽然 3DE
平台提供了 高级的搜索功能 和 BookMark
文件管理功能,避免了用户直接输入SQL
语句,但这些功能的易用性还有待提高,例如在搜索功能中,用户通常需要记住多种类型的缩写,并了解数据输入的结构才能实现有效地搜索(图1
中为搜索含有主梁字符的物理产品),对于使用度较低的用户,要实现复杂的,多条件的搜索实在是不友好,而且偶尔还有彩(奔)蛋(溃)。在确认过COM
开发能够较为稳定且快速地实现数据搜索之后,断断续续花了1周
🕜左右的时间通过二次开发重新定制了🔍CATIA搜索功能(图3
)。
图1.3DE自带搜索功能
图2.搜索功能奔溃截图
图3.定制搜索功能 (特别鸣谢xscode提供的样式)
二、方法及步骤
🔉 官方说明:PLM server contains PLM entities that can be queried against a set of PLM attributes, using the SearchService service object. The result of a query is a set of PLM entities that must be opened using the PLMOpen method of the PLMOpenServiceobject before being browsed or edited through specific editors。
译文:SearchService 对象可用于服务器数据的检索, 并可以使用 PLM 属性对PLM server中的 entities 进行精准搜索,在浏览和编辑之前需要通过 PLMOpenService 对象打开。
在Autimation API
手册中,不难找到关于搜索功能的叙述,在Getting Started With VBA
章节就已经出现了部分代码,而且其本身也并不复杂。主要包含四个搜索关键词的定义,分别是类型、标题、版本号和全称,其与UI界面的对应关系,我已在图4
中标明。需要提醒🔔的是,全称在不同类型的搜索模式下有着不同含义。在搜索物理产品、图纸、工程模板等模型文件时,其为模型的全局ID,正如图4
所示;而当切换至文件夹、目录、章节等容器类搜索时,其就是容器的名称,正如图5
所示。
图4.参数理解
图5.文件夹属性
SearchService searchService =(SearchService) CATIA.GetSessionService("Search");
DatabaseSearch databaseSearch = searchService.DatabaseSearch;
// 指定文件类型
// VPMReference 为 物理产品
databaseSearch.set_BaseType("VPMReference");
// 指定文件全称
databaseSearch.AddEasyCriteria("V_Name", elemName);
// 指定文件版本号
databaseSearch.AddEasyCriteria("revision", version);
// 指定文件Id
databaseSearch.AddEasyCriteria("PLM_ExternalID ", externalID);
searchService.Search();
上述代码为搜索功能的核心内容,正如前文所述并不复杂。然而,其难点😫落在了如何获得不同文件类型的标识字符串上,即上述代码中的VPMReference
。翻阅Autimation API
手册,仅找到为数不多的已知类型,包括物理产品、图纸和 3D Shape
。既然是重新定制,那就要好用且全面,所以得找到查询不同文件类型所对应标识字符的方法。笔者尝试了将软件调为英文版,以此来找到不同类型所对应的英文词汇(图7
),并将其代入程序进行测试,最终都无功而返😓。
图6.笔者开发的程序所提供的搜索类型
图7.CATIA文件类型中英对应
多次尝试无果后,在国外开发论坛中发起提问🙋。
Q(cao bingyong):
Hi, all
I want to develop a search tool using COM in catia v6. There are four parameters for input when starting a search, namely BaseType, Title, Revision, Name, But, it’s not easy to find the right basetype string, the following types are found in the automation doc. So, anyone can help?
Thanks in advance.
switch (mainwin.SearchKeyForBinding.Type)
{
case "Physical Product":
databaseSearch.set_BaseType("VPMReference");
break;
case "Drawing":
databaseSearch.set_BaseType("Drawing");
break;
}
提问数日后,得到了热心回复👍:
A(Jason Curtis):
Hi Cao, there are a couple of ways to find the object types, but I’ll just share the one I use most often because it is quick, available in every app (even works in the search results window if you start the CollabLifecycle app), and doesn’t require any additional licensing.
In the BI Essentials, all the way at the bottom of the list is “Check BI Essentials customization” option. A dialog box will pop up. Click “Check an item type” and then select an object. The object type and all of the attributes defined on that type will be displayed. Very useful for database objects, but it won’t work for features or anything like that. See attached images.
笔者回复并表示感谢🌹
Q(cao bingyong):
Hi, Jason.
Thanks for your reply. I used BI Essentials Checker as you said, and got the right type str successfully. The following strs corresponding to the object types are what I got in this way, hope to help someone else.
kudos to you.
对象类型 | 中文注释 | 标识字符串 |
---|---|---|
Physical Product | 物理产品 | VPMReference |
VPM Document | VPM文档 | PLMDMTDocument |
Drawing | 图纸 | Drawing |
3D Shape | 3D Shape | VPMRepReference |
Engineering Template | 工程模板 | PLMTemplateRepReference |
Site | 场地 | AecSite |
Folder | 文件夹 | ENOFLD_FolderRootReference |
Catalog | 目录 | ENOCLG_LibraryReference |
Catalog Chapter | 章节 | ENOCLG_ClassReference |
BridgeTower | 桥塔 | BridgeTower |
BridgeTowerSegment | 桥塔节段 | BridgeTowerSegment |
在Jason
的帮助下,上述问题得到解决,我也留下了自己成果,以便帮助社区里的其他人✌️。
春节将临,粉丝福利不能少,笔者一穷二白,仅有手敲的这一行一行代码和程序,所以已经将 CATIA Search Tool 开源,供大家下载、使用和学习。
公众号回复:catsearch
,即可获得笔者所开发的定制搜索功能,且本项目已在Gitee
(https://gitee.com/wx_61043d9a92/CATSearch)上开源,欢迎大家Fork
,共同维护。
附使用说明
- 根据类型、标题、版本号和全称进行搜索
- 类型支持:物理产品、图纸、3D形状、工程模板、场地、桥塔、桥塔节段、文件夹、目录、章节、VPM文档(还在不断扩充)
- 支持模糊搜索(如:
桥梁*
:*为通配符) - 建议的搜索模式:(1)
标题
+版本号
;(2)全称
; 标题
区分 大小写;- 输入完成后,在任意输入框中按
Enter
键,可开始搜索; - Reset :清空
标题
、版本号
和全称
;
三、参考资料
《3DEXPEROENCE Automation Help》