forked from evereux/pycatia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_001.py
47 lines (33 loc) · 1.04 KB
/
example_001.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/python3.6
"""
Example 1:
Get the center of gravity for the part body 'PartBody'.
"""
from pycatia import catia
# initialise the catia automation application
caa = catia()
documents = caa.documents
documents.open(r'tests/cat_files/part_measurable.CATPart')
# get the active document
document = caa.active_document
# >>> print(document.path())
# >>> C:\Users\evereux\python\projects\pycatia\tests\CF_catia_measurable_part.CATPart
# get the Part() object.
part = document.part()
# get the Bodies() collection
bodies = part.bodies
# gets first Body()
body = bodies.item(1)
# >>> print(body)
# >>> Body(name="PartBody")
# or get the body by name
# >>> body_by_name = bodies.get_item_by_name('AnotherPartBody')
# >>> print(body)
# >>> Body(name="AnotherPartBody")
# initialise the spa workbench
spa_workbench = document.spa_workbench()
# create a reference to measure.
reference = part.create_reference_from_object(body)
measurable = spa_workbench.get_measurable(reference)
center_of_gravity = measurable.get_cog()
print(center_of_gravity)