@@ -133,6 +133,8 @@ class Component:
133133 template : Component, default: None
134134 Template to create this component from. This creates an
135135 instance component that shares a master with the template component.
136+ instance_name: str, default: None
137+ User defined optional name for the component instance.
136138 preexisting_id : str, default: None
137139 ID of a component pre-existing on the server side to use to create the component
138140 on the client-side data model. If an ID is specified, a new component is not
@@ -160,6 +162,7 @@ def __init__(
160162 parent_component : Union ["Component" , None ],
161163 grpc_client : GrpcClient ,
162164 template : Optional ["Component" ] = None ,
165+ instance_name : Optional [str ] = None ,
163166 preexisting_id : str | None = None ,
164167 master_component : MasterComponent | None = None ,
165168 read_existing_comp : bool = False ,
@@ -171,21 +174,33 @@ def __init__(
171174 self ._bodies_stub = BodiesStub (self ._grpc_client .channel )
172175 self ._commands_stub = CommandsStub (self ._grpc_client .channel )
173176
177+ # Align instance name behavior with the server - empty string if None
178+ instance_name = instance_name if instance_name else ""
179+
174180 if preexisting_id :
175181 self ._name = name
176182 self ._id = preexisting_id
183+ self ._instance_name = instance_name
177184 else :
178185 if parent_component :
179186 template_id = template .id if template else ""
180187 new_component = self ._component_stub .Create (
181- CreateRequest (name = name , parent = parent_component .id , template = template_id )
188+ CreateRequest (
189+ name = name ,
190+ parent = parent_component .id ,
191+ template = template_id ,
192+ instance_name = instance_name ,
193+ )
182194 )
195+
183196 # Remove this method call once we know Service sends correct ObjectPath id
184197 self ._id = new_component .component .id
185198 self ._name = new_component .component .name
199+ self ._instance_name = new_component .component .instance_name
186200 else :
187201 self ._name = name
188202 self ._id = None
203+ self ._instance_name = instance_name
189204
190205 # Initialize needed instance variables
191206 self ._components = []
@@ -231,6 +246,11 @@ def name(self) -> str:
231246 """Name of the component."""
232247 return self ._name
233248
249+ @property
250+ def instance_name (self ) -> str :
251+ """Name of the component instance."""
252+ return self ._instance_name
253+
234254 @property
235255 def components (self ) -> list ["Component" ]:
236256 """List of ``Component`` objects inside of the component."""
@@ -367,7 +387,9 @@ def reset_placement(self):
367387
368388 @check_input_types
369389 @ensure_design_is_active
370- def add_component (self , name : str , template : Optional ["Component" ] = None ) -> "Component" :
390+ def add_component (
391+ self , name : str , template : Optional ["Component" ] = None , instance_name : str = None
392+ ) -> "Component" :
371393 """Add a new component under this component within the design assembly.
372394
373395 Parameters
@@ -383,18 +405,20 @@ def add_component(self, name: str, template: Optional["Component"] = None) -> "C
383405 Component
384406 New component with no children in the design assembly.
385407 """
386- new_comp = Component (name , self , self ._grpc_client , template = template )
408+ new_comp = Component (
409+ name , self , self ._grpc_client , template = template , instance_name = instance_name
410+ )
387411 master = new_comp ._master_component
388412 master_id = new_comp .id .split ("/" )[- 1 ]
389-
390413 for comp in self ._master_component .occurrences :
391414 if comp .id != self .id :
392415 comp .components .append (
393416 Component (
394417 name ,
395418 comp ,
396419 self ._grpc_client ,
397- template ,
420+ template = template ,
421+ instance_name = instance_name ,
398422 preexisting_id = f"{ comp .id } /{ master_id } " ,
399423 master_component = master ,
400424 read_existing_comp = True ,
0 commit comments