Skip to content

Commit bcaa31a

Browse files
committed
Added example for Hole origin and direction
1 parent 81fe13f commit bcaa31a

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

docs/examples.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Index
4242

4343
:ref:`PARAMETERS EXAMPLES<Example Parameters>`
4444

45+
:ref:`PART EXAMPLES<Example Parts>`
46+
4547
:ref:`PRODUCT EXAMPLES<Example Product>`
4648

4749
:ref:`SELECTION EXAMPLES<Example Selection>`
@@ -402,6 +404,20 @@ Change the Length value of parameter named Thickness.
402404

403405

404406

407+
.. _Example Part:
408+
409+
PART EXAMPLES
410+
----------------
411+
412+
Part - Hole - Example 1
413+
~~~~~~~~~~~~~~~~~~~~~~~
414+
415+
For all the Hole(s) in a CATPart get the origin and direction of Hole.
416+
417+
`Part - Hole - 001 <https://github.com/evereux/pycatia/blob/master/examples/example__part_hole__001.py>`_
418+
419+
420+
405421
.. _Example Product:
406422

407423
PRODUCT EXAMPLES
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#! /usr/bin/python3.9
2+
3+
"""
4+
5+
Example - Part Hole 001
6+
7+
Description:
8+
Find all the Hole(s) in the active CATPart document and report it's origin
9+
and direction (relative to origin).
10+
11+
Requirements:
12+
- CATIA running.
13+
- A CATPart open that contains a PartBody with Hole(s).
14+
15+
"""
16+
17+
##########################################################
18+
# insert syspath to project folder so examples can be run.
19+
# for development purposes.
20+
import os
21+
import sys
22+
23+
sys.path.insert(0, os.path.abspath("..\\pycatia"))
24+
##########################################################
25+
26+
from pycatia import catia
27+
from pycatia.mec_mod_interfaces.part_document import PartDocument
28+
from pycatia.part_interfaces.hole import Hole
29+
30+
caa = catia()
31+
application = caa.application
32+
part_document: PartDocument = application.active_document
33+
part = part_document.part
34+
selection = part_document.selection
35+
selection.clear()
36+
# search the entire CATPart for all Holes belonging to the Part Design workbench.
37+
selection.search("'Part Design'.Hole,all")
38+
39+
# collect the co-ordinates into a list so we can draw the points afterwards
40+
# to visually check results.
41+
points = []
42+
43+
for feature in range(selection.count):
44+
n = feature + 1
45+
auto_object = selection.item2(n).value
46+
reference = part.create_reference_from_object(auto_object)
47+
48+
hole = Hole(auto_object.com_object)
49+
origin = hole.get_origin()
50+
direction = hole.get_direction()
51+
print(f"Name: {selection.item2(n).value.name}")
52+
print("Hole origin: \n"
53+
f"x = {origin[0]}\n"
54+
f"y = {origin[1]}\n"
55+
f"z = {origin[2]}")
56+
print("Direction: \n"
57+
f"x = {direction[0]}\n"
58+
f"y = {direction[1]}\n"
59+
f"z = {direction[2]}\n")
60+
61+
points.append((origin, direction))
62+
63+
selection.clear()
64+
65+
# create a new Geometrical Set called "Points" to which the origin and direction
66+
# points will be added.
67+
hybrid_bodies = part.hybrid_bodies
68+
hb_points = hybrid_bodies.add()
69+
hb_points.name = "Points"
70+
71+
hsf = part.hybrid_shape_factory
72+
73+
for p in points:
74+
origin = p[0]
75+
direction = p[1]
76+
77+
point_origin = hsf.add_new_point_coord(origin[0], origin[1], origin[2])
78+
point_origin_reference = part.create_reference_from_object(point_origin)
79+
hb_points.append_hybrid_shape(point_origin)
80+
81+
point_direction = hsf.add_new_point_coord_with_reference(
82+
direction[0],
83+
direction[1],
84+
direction[2],
85+
point_origin_reference
86+
)
87+
88+
hb_points.append_hybrid_shape(point_direction)
89+
90+
part.update()

0 commit comments

Comments
 (0)