@@ -87,9 +87,9 @@ class Component:
87
87
If a component already exists on the server, you can pass in its ID to create it on the
88
88
client-side data model. If this is argument is present, a new Component will not be created
89
89
on the server.
90
- transformed_part : MasterComponent, optional
90
+ master_component : MasterComponent, optional
91
91
This argument should be present when creating a nested instance component. It will use the
92
- given transformed_part instead of creating a new one.
92
+ given master_component instead of creating a new one.
93
93
read_existing_comp : bool, optional
94
94
Indicates whether an existing component on the service should be read
95
95
or not. By default, ``False``. This is only valid when connecting
@@ -112,7 +112,7 @@ def __init__(
112
112
grpc_client : GrpcClient ,
113
113
template : Optional ["Component" ] = None ,
114
114
preexisting_id : Optional [str ] = None ,
115
- transformed_part : Optional [MasterComponent ] = None ,
115
+ master_component : Optional [MasterComponent ] = None ,
116
116
read_existing_comp : bool = False ,
117
117
):
118
118
"""Initialize ``Component`` class."""
@@ -146,32 +146,31 @@ def __init__(
146
146
self ._parent_component = parent_component
147
147
self ._is_alive = True
148
148
self ._shared_topology = None
149
- self ._transformed_part = transformed_part
149
+ self ._master_component = master_component
150
150
151
151
# Populate client data model
152
152
if template :
153
153
# If this is not a nested instance
154
- if not transformed_part :
154
+ if not master_component :
155
155
# Create new MasterComponent, but use template's Part
156
- tp = MasterComponent (
156
+ master = MasterComponent (
157
157
uuid .uuid4 (),
158
- f"tp_ { name } " ,
159
- template ._transformed_part .part ,
160
- template ._transformed_part .transform ,
158
+ f"master_ { name } " ,
159
+ template ._master_component .part ,
160
+ template ._master_component .transform ,
161
161
)
162
- tp .part .parts .append (tp )
163
- self ._transformed_part = tp
162
+ self ._master_component = master
164
163
165
164
# Recurse - Create more children components from template's remaining children
166
165
self .__create_children (template )
167
- return
168
166
169
167
elif not read_existing_comp :
170
168
# This is an independent Component - Create new Part and MasterComponent
171
169
p = Part (uuid .uuid4 (), f"p_{ name } " , [], [])
172
- tp = MasterComponent (uuid .uuid4 (), f"tp_{ name } " , p )
173
- p .parts .append (tp )
174
- self ._transformed_part = tp
170
+ master = MasterComponent (uuid .uuid4 (), f"master_{ name } " , p )
171
+ self ._master_component = master
172
+
173
+ self ._master_component .occurrences .append (self )
175
174
176
175
@property
177
176
def id (self ) -> str :
@@ -192,7 +191,7 @@ def components(self) -> List["Component"]:
192
191
def bodies (self ) -> List [Body ]:
193
192
"""``Body`` objects inside of the component."""
194
193
bodies = []
195
- for body in self ._transformed_part .part .bodies :
194
+ for body in self ._master_component .part .bodies :
196
195
id = f"{ self .id } /{ body .id } " if self .parent_component else body .id
197
196
bodies .append (Body (id , body .name , self , body ))
198
197
return bodies
@@ -242,7 +241,7 @@ def __create_children(self, template: "Component") -> None:
242
241
self ._grpc_client ,
243
242
template = template_comp ,
244
243
preexisting_id = new_id ,
245
- transformed_part = template_comp ._transformed_part ,
244
+ master_component = template_comp ._master_component ,
246
245
)
247
246
self .components .append (new )
248
247
@@ -257,7 +256,7 @@ def get_world_transform(self) -> Matrix44:
257
256
"""
258
257
if self .parent_component is None :
259
258
return IDENTITY_MATRIX44
260
- return self .parent_component .get_world_transform () * self ._transformed_part .transform
259
+ return self .parent_component .get_world_transform () * self ._master_component .transform
261
260
262
261
@protect_grpc
263
262
def modify_placement (
@@ -308,7 +307,7 @@ def modify_placement(
308
307
rotation_angle = angle .value .m ,
309
308
)
310
309
)
311
- self ._transformed_part .transform = grpc_matrix_to_matrix (response .matrix )
310
+ self ._master_component .transform = grpc_matrix_to_matrix (response .matrix )
312
311
313
312
def reset_placement (self ):
314
313
"""
@@ -336,7 +335,25 @@ def add_component(self, name: str, template: Optional["Component"] = None) -> "C
336
335
Component
337
336
New component with no children in the design assembly.
338
337
"""
339
- self ._components .append (Component (name , self , self ._grpc_client , template = template ))
338
+ new_comp = Component (name , self , self ._grpc_client , template = template )
339
+ master = new_comp ._master_component
340
+ master_id = new_comp .id .split ("/" )[- 1 ]
341
+
342
+ for comp in self ._master_component .occurrences :
343
+ if comp .id != self .id :
344
+ comp .components .append (
345
+ Component (
346
+ name ,
347
+ comp ,
348
+ self ._grpc_client ,
349
+ template ,
350
+ preexisting_id = f"{ comp .id } /{ master_id } " ,
351
+ master_component = master ,
352
+ read_existing_comp = True ,
353
+ )
354
+ )
355
+
356
+ self .components .append (new_comp )
340
357
return self ._components [- 1 ]
341
358
342
359
@protect_grpc
@@ -402,7 +419,7 @@ def extrude_sketch(
402
419
self ._grpc_client .log .debug (f"Extruding sketch provided on { self .id } . Creating body..." )
403
420
response = self ._bodies_stub .CreateExtrudedBody (request )
404
421
tb = MasterBody (response .master_id , name , self ._grpc_client , is_surface = False )
405
- self ._transformed_part .part .bodies .append (tb )
422
+ self ._master_component .part .bodies .append (tb )
406
423
return Body (response .id , response .name , self , tb )
407
424
408
425
@protect_grpc
@@ -449,7 +466,7 @@ def extrude_face(self, name: str, face: Face, distance: Union[Quantity, Distance
449
466
response = self ._bodies_stub .CreateExtrudedBodyFromFaceProfile (request )
450
467
451
468
tb = MasterBody (response .master_id , name , self ._grpc_client , is_surface = False )
452
- self ._transformed_part .part .bodies .append (tb )
469
+ self ._master_component .part .bodies .append (tb )
453
470
return Body (response .id , response .name , self , tb )
454
471
455
472
@protect_grpc
@@ -486,7 +503,7 @@ def create_surface(self, name: str, sketch: Sketch) -> Body:
486
503
response = self ._bodies_stub .CreatePlanarBody (request )
487
504
488
505
tb = MasterBody (response .master_id , name , self ._grpc_client , is_surface = True )
489
- self ._transformed_part .part .bodies .append (tb )
506
+ self ._master_component .part .bodies .append (tb )
490
507
return Body (response .id , response .name , self , tb )
491
508
492
509
@protect_grpc
@@ -526,7 +543,7 @@ def create_surface_from_face(self, name: str, face: Face) -> Body:
526
543
response = self ._bodies_stub .CreateBodyFromFace (request )
527
544
528
545
tb = MasterBody (response .master_id , name , self ._grpc_client , is_surface = True )
529
- self ._transformed_part .part .bodies .append (tb )
546
+ self ._master_component .part .bodies .append (tb )
530
547
return Body (response .id , response .name , self , tb )
531
548
532
549
@check_input_types
0 commit comments