@@ -87,9 +87,9 @@ class Component:
8787 If a component already exists on the server, you can pass in its ID to create it on the
8888 client-side data model. If this is argument is present, a new Component will not be created
8989 on the server.
90- transformed_part : MasterComponent, optional
90+ master_component : MasterComponent, optional
9191 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.
9393 read_existing_comp : bool, optional
9494 Indicates whether an existing component on the service should be read
9595 or not. By default, ``False``. This is only valid when connecting
@@ -112,7 +112,7 @@ def __init__(
112112 grpc_client : GrpcClient ,
113113 template : Optional ["Component" ] = None ,
114114 preexisting_id : Optional [str ] = None ,
115- transformed_part : Optional [MasterComponent ] = None ,
115+ master_component : Optional [MasterComponent ] = None ,
116116 read_existing_comp : bool = False ,
117117 ):
118118 """Initialize ``Component`` class."""
@@ -146,32 +146,31 @@ def __init__(
146146 self ._parent_component = parent_component
147147 self ._is_alive = True
148148 self ._shared_topology = None
149- self ._transformed_part = transformed_part
149+ self ._master_component = master_component
150150
151151 # Populate client data model
152152 if template :
153153 # If this is not a nested instance
154- if not transformed_part :
154+ if not master_component :
155155 # Create new MasterComponent, but use template's Part
156- tp = MasterComponent (
156+ master = MasterComponent (
157157 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 ,
161161 )
162- tp .part .parts .append (tp )
163- self ._transformed_part = tp
162+ self ._master_component = master
164163
165164 # Recurse - Create more children components from template's remaining children
166165 self .__create_children (template )
167- return
168166
169167 elif not read_existing_comp :
170168 # This is an independent Component - Create new Part and MasterComponent
171169 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 )
175174
176175 @property
177176 def id (self ) -> str :
@@ -192,7 +191,7 @@ def components(self) -> List["Component"]:
192191 def bodies (self ) -> List [Body ]:
193192 """``Body`` objects inside of the component."""
194193 bodies = []
195- for body in self ._transformed_part .part .bodies :
194+ for body in self ._master_component .part .bodies :
196195 id = f"{ self .id } /{ body .id } " if self .parent_component else body .id
197196 bodies .append (Body (id , body .name , self , body ))
198197 return bodies
@@ -242,7 +241,7 @@ def __create_children(self, template: "Component") -> None:
242241 self ._grpc_client ,
243242 template = template_comp ,
244243 preexisting_id = new_id ,
245- transformed_part = template_comp ._transformed_part ,
244+ master_component = template_comp ._master_component ,
246245 )
247246 self .components .append (new )
248247
@@ -257,7 +256,7 @@ def get_world_transform(self) -> Matrix44:
257256 """
258257 if self .parent_component is None :
259258 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
261260
262261 @protect_grpc
263262 def modify_placement (
@@ -308,7 +307,7 @@ def modify_placement(
308307 rotation_angle = angle .value .m ,
309308 )
310309 )
311- self ._transformed_part .transform = grpc_matrix_to_matrix (response .matrix )
310+ self ._master_component .transform = grpc_matrix_to_matrix (response .matrix )
312311
313312 def reset_placement (self ):
314313 """
@@ -336,7 +335,25 @@ def add_component(self, name: str, template: Optional["Component"] = None) -> "C
336335 Component
337336 New component with no children in the design assembly.
338337 """
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 )
340357 return self ._components [- 1 ]
341358
342359 @protect_grpc
@@ -402,7 +419,7 @@ def extrude_sketch(
402419 self ._grpc_client .log .debug (f"Extruding sketch provided on { self .id } . Creating body..." )
403420 response = self ._bodies_stub .CreateExtrudedBody (request )
404421 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 )
406423 return Body (response .id , response .name , self , tb )
407424
408425 @protect_grpc
@@ -449,7 +466,7 @@ def extrude_face(self, name: str, face: Face, distance: Union[Quantity, Distance
449466 response = self ._bodies_stub .CreateExtrudedBodyFromFaceProfile (request )
450467
451468 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 )
453470 return Body (response .id , response .name , self , tb )
454471
455472 @protect_grpc
@@ -486,7 +503,7 @@ def create_surface(self, name: str, sketch: Sketch) -> Body:
486503 response = self ._bodies_stub .CreatePlanarBody (request )
487504
488505 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 )
490507 return Body (response .id , response .name , self , tb )
491508
492509 @protect_grpc
@@ -526,7 +543,7 @@ def create_surface_from_face(self, name: str, face: Face) -> Body:
526543 response = self ._bodies_stub .CreateBodyFromFace (request )
527544
528545 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 )
530547 return Body (response .id , response .name , self , tb )
531548
532549 @check_input_types
0 commit comments