访问catia可测量对象的python模块。
pycatia的Python项目详细描述
pycatia的创建主要是为了访问catia api 对象及其方法,不需要visual basic/catscripts。 还有更多的功能可以通过查看 提供的示例和在pycatia.readthedocs.io读取api。
一些方法可以简单地使用pywin32模块访问,但是 使用纯python似乎无法访问getcog等方法。 有几个关于堆栈溢出和pywin32邮件列表的问题 这个。但是,他们没有提供vb可测量对象的任何工作示例 在Python中。
pycatia通过使用 dispatch('catia.application').systemservice.evaluate()需要时的函数 把一个小小的公共职能交给它。否则,pycatia使用vb方法 直接在同一个python类中公开它。
目前仅在catia v5 r21中进行了测试。
要求
- python=3.6
- Catia V5
- 参见requirements.txt
安装
带PIP
pipinstallpycatia
有关详细说明,请参阅安装说明
在pycatia.readthedocs.io提供。
用法
本例说明如何获取几何集合“点”中的第一个点。
# initial set-up to get access to the CATIA COM objects.importpycatiacatia=pycatia.CATIAApplication()document=pycatia.Document(catia.catia)part=pycatia.Part(document.document)spa_workbench=pycatia.create_spa_workbench(document.document)# find the geometrical set by name called 'Points'hybrid_body=part.get_hybrid_body_by_name('Points')# get the first point in the geometrical set.point1=hybrid_body.HybridShapes.Item(1)# create the reference and measurable objectspoint1_reference=pycatia.create_reference(part.part,point1)point1_measurable=pycatia.create_measurable(spa_workbench,point1_reference)# create the catia measurable objectmeasurable=pycatia.CATIAMeasurable(point1_measurable)# run the get_point() method from CATIAMeasurable.point_coordinate=measurable.get_point()# point_coordinate is a tuple representing it's x, y, z values.print(point_coordinate)# outputs (0.0, 8.0, -4.0)# print xprint(point_coordinate[0]# output 0,0document.close()
请参阅提供的示例以了解更多pycatia goody。
示例
从“测试”文件夹中打开catia_measurable.catpart文件。
运行示例脚本。
显示如何在.catpart打开且 获取零件主体“零件主体”的重心。
演示如何获取几何集合“points”中的所有点,以及 找到坐标。
显示如何搜索文档中的所有点,打印结果 到控制台并写入csv文件。
演示如何遍历产品并确定子级是否 猫产品或猫部件
演示如何在catia零件中解析和csv文件并创建点。
如何打开、另存为和关闭catia文件的示例。
如何使用上下文管理器打开文档的示例。
如何遍历目录并将所有catpart转换为igs。
运行测试
要在覆盖范围内运行测试:
py.test-v--cov-reportterm-missing--cov=pycatia