-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicate_or_select_element_3d.py
207 lines (142 loc) · 6.09 KB
/
indicate_or_select_element_3d.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"""
Example - indicate_or_select_element_3d - xxx:
Creates plane parallel to screen in viewpoint origin.
Loops indicate_or_select_element_3d until mouse is clicked, while checking that sight direction is not changed.
Creates projection point on surface at clicked position or if point or vertex is selected, a point in that position.
Requirements: CATIA runnig. A Part with a geometrical set named "Geometrical Set.1" with a surface "Extract.1" inside.
"""
##########################################################
# 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 import catia
caa = catia()
document = caa.active_document
part = document.part
hsf = part.hybrid_shape_factory
hbs = part.hybrid_bodies
hb = hbs.item("Geometrical Set.1")
hs = hb.hybrid_shapes
def sight_coords():
#get viewer object
active_window = caa.active_window
active_viewer = active_window.active_viewer
#get viewpoint object
view_point_3D = active_viewer.create_viewer_3d().viewpoint_3d
sight = view_point_3D.get_sight_direction()
return sight
def scr_pln():
#get viewer object
active_window = caa.active_window
active_viewer = active_window.active_viewer
#get viewpoint object
view_point_3D = active_viewer.create_viewer_3d().viewpoint_3d
#get viewpoint coords
viewpoint_coords = view_point_3D.get_origin()
#create viewpoint
origin_point = hsf.add_new_point_coord(viewpoint_coords[0], viewpoint_coords[1], viewpoint_coords[2])
#create reference to viewpoint
origin_point_ref = part.create_reference_from_object(origin_point)
#get sight direction coords
sight_dir_coords = sight_coords()
#create sight direction
sight_dir = hsf.add_new_direction_by_coord(sight_dir_coords[0], sight_dir_coords[1], sight_dir_coords[2])
#create sight direction line
sight_dir_line = hsf.add_new_line_pt_dir(origin_point_ref, sight_dir, 0, 20, False)
#create reference to sight direction line
sight_dir_line_ref = part.create_reference_from_object(sight_dir_line)
#reate sight direction plane
scr_pln = hsf.add_new_plane_normal(sight_dir_line_ref, origin_point_ref)
hb.append_hybrid_shape(scr_pln)
#update
part.update_object(scr_pln)
return scr_pln
#get plane parallel to screen
scr_pln_res = scr_pln()
#create reference to sigh direction plane
scr_pln_ref = part.create_reference_from_object(scr_pln_res)
#define selection
selection = document.selection
selection.clear()
#define indicate or select element 3D
status = "MouseMove"
#set whats allowed to select
input_type = ("Point", "Vertex")
selection.clear()
status = selection.indicate_or_select_element_3d(scr_pln_res, "Select a point or click to locate the point", input_type, False, False, True)
#get in value for sight direction coords
in_coords = sight_coords()
in_coordx = in_coords[0]
#do loop while checking if viewer direction is modified
while (status[0] == "MouseMove"):
out_coords = sight_coords()
out_coordx = out_coords[0]
if in_coordx == out_coordx:
status = selection.indicate_or_select_element_3d(scr_pln_res, "Select a point or click to locate the point", input_type, False, False, True)
else:
hsf.delete_object_for_datum(scr_pln_ref)
scr_pln_res = scr_pln()
scr_pln_ref = part.create_reference_from_object(scr_pln_res)
status = selection.indicate_or_select_element_3d(scr_pln_res, "Select a point or click to locate the point", input_type, False, False, True)
in_coords = sight_coords()
in_coordx = in_coords[0]
if not status[0] == "MouseMove":
break
#if bailing
if status[0] == "Cancel" or status[0] == "Undo" or status[0] == "Redo":
hsf.delete_object_for_datum(scr_pln_ref)
#if selecting existing point or vertex
elif status[1]:
existing_point = selection.item2(1)
coords = existing_point.get_coordinates()
vertex_point = hsf.add_new_point_coord(coords[0], coords[1], coords[2])
hb.append_hybrid_shape(vertex_point)
selection.clear()
part.update_object(vertex_point)
vertex_point_ref = part.create_reference_from_object(vertex_point)
vertex_point_datum = hsf.add_new_point_datum(vertex_point_ref)
hb.append_hybrid_shape(vertex_point_datum)
part.update_object(vertex_point_datum)
hsf.delete_object_for_datum(vertex_point_ref)
hsf.delete_object_for_datum(scr_pln_ref)
else:
try:
#create screen point
scr_point = hsf.add_new_point_coord(status[3][0], status[3][1], status[3][2])
hb.append_hybrid_shape(scr_point)
#update
part.update_object(scr_point)
#create reference to screen point
scr_point_ref = part.create_reference_from_object(scr_point)
#project on surface
# path to surface
project_surface = hs.item("Extract.1")
#create reference to surface
project_surface_ref = part.create_reference_from_object(project_surface)
projected_point = hsf.add_new_project(scr_point_ref, project_surface_ref)
projected_point_ref = part.create_reference_from_object(projected_point)
#get sight direction coords
sight_dir_coords = sight_coords()
#create sight direction
sight_dir = hsf.add_new_direction_by_coord(sight_dir_coords[0], sight_dir_coords[1], sight_dir_coords[2])
#need to import projection?
projected_point.normal = False
projected_point.direction = sight_dir
hb.append_hybrid_shape(projected_point)
part.update_object(projected_point)
projected_point_datum = hsf.add_new_point_datum(projected_point_ref)
hb.append_hybrid_shape(projected_point_datum)
part.update_object(projected_point_datum)
# Delete history
hsf.delete_object_for_datum(projected_point_ref)
hsf.delete_object_for_datum(scr_point_ref)
hsf.delete_object_for_datum(scr_pln_ref)
except:
hsf.delete_object_for_datum(projected_point_ref)
hsf.delete_object_for_datum(scr_point_ref)
hsf.delete_object_for_datum(scr_pln_ref)
buttons = 0
result = caa.message_box("Aim better ;)", buttons=buttons, title="You missed.")