/
example__selection__002.py
71 lines (53 loc) · 1.97 KB
/
example__selection__002.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/python3.9
"""
Example - Selection - 002
Description:
Prompt the user to select 2 vertexes and create line in selected geometrical set
Requirements:
- CATIA must be running with part document open and active.
- Part document must contain 2 vertex (points) and a geometrical set.
"""
##########################################################
# insert syspath to project folder so examples can be run.
# for development purposes.
import os
import sys
sys.path.insert(0, os.path.abspath('..\\pycatia'))
##########################################################
from pycatia.mec_mod_interfaces.part import Part
from pycatia import catia
caa = catia()
documents = caa.documents
document = caa.active_document
part = Part(document.part.com_object)
hybrid_bodies = part.hybrid_bodies
hsf = part.hybrid_shape_factory
# create selection object
selection = document.selection
filter_type = ("Vertex",)
# i_object_selection_before_command_use_possibility - True = pre-selection is allowed.
status = selection.select_element2(filter_type, "Select the first vertex", True)
# status==Normal is vertex selected
if status == "Cancel":
caa.message_box("Canceled", 16)
exit()
first_vertex = selection.item(1).reference
selection.clear()
status = selection.select_element2(filter_type, "Select the second vertex", True)
if status == "Cancel":
caa.message_box("Cancelled", 16)
exit()
second_vertex = selection.item(1).reference
selection.clear()
filter_type = ("HybridBody",)
status = selection.select_element2(filter_type, "Select Geometrical set", True)
if status == "Cancel":
caa.message_box("Cancelled", 16)
exit()
# set pointer to selected geometrical set
hb_construction_geometry = hybrid_bodies.get_item_by_name(selection.item(1).value.name)
# create line
line = hsf.add_new_line_pt_pt(first_vertex, second_vertex)
hb_construction_geometry.append_hybrid_shape(line)
part.update()
caa.message_box("Line is created!", 0, "Congratulations!")