2323# SOFTWARE.
2424
2525
26+ from ansys .aedt .core .emit_core .nodes .emit_node import EmitNode
2627from ansys .aedt .core .generic .general_methods import pyaedt_function_handler
2728
2829
@@ -61,7 +62,7 @@ def _emit_com_module(self):
6162 raise RuntimeError (f"Failed to retrieve EmitCom module: { e } " )
6263
6364 @pyaedt_function_handler
64- def create_component (self , component_type : str , name : str = None , library : str = None ) -> int :
65+ def create_component (self , component_type : str , name : str = None , library : str = None ) -> EmitNode :
6566 """Create a component.
6667
6768 Parameters
@@ -75,8 +76,8 @@ def create_component(self, component_type: str, name: str = None, library: str =
7576
7677 Returns
7778 -------
78- int
79- The ID of the created component.
79+ EmitNode
80+ The EmitNode of the created component.
8081
8182 Raises
8283 ------
@@ -119,20 +120,22 @@ def create_component(self, component_type: str, name: str = None, library: str =
119120 f"Using exact match component '{ component .name } ' from library '{ component .component_library } "
120121 "' for type '{component_type}'."
121122 )
123+ revision = self .emit_instance .results .get_revision ()
122124
123125 # Create the component using the EmitCom module
124126 new_component_id = self ._emit_com_module .CreateEmitComponent (
125127 name , component .name , component .component_library
126128 )
127- return new_component_id
129+ component_node = revision ._get_node (node_id = new_component_id )
130+ return component_node
128131 except Exception as e :
129132 self .emit_instance .logger .error (f"Failed to create component '{ name } ' of type '{ component_type } ': { e } " )
130133 raise RuntimeError (f"Failed to create component of type '{ component_type } ': { e } " )
131134
132135 @pyaedt_function_handler
133136 def create_radio_antenna (
134137 self , radio_type : str , radio_name : str = None , antenna_name : str = None , library : str = None
135- ) -> tuple [int , int ]:
138+ ) -> tuple [EmitNode , EmitNode ]:
136139 """Create a new radio and antenna and connect them.
137140
138141 Parameters
@@ -152,8 +155,8 @@ def create_radio_antenna(
152155
153156 Returns
154157 -------
155- tuple
156- A tuple containing the IDs of the created radio and antenna.
158+ tuple[EmitNode, EmitNode]
159+ A tuple containing the EmitNode of the created radio and antenna.
157160
158161 Raises
159162 ------
@@ -165,74 +168,38 @@ def create_radio_antenna(
165168 library = library or ""
166169
167170 try :
168- new_radio_id = self .create_component (radio_type , radio_name , library )
169- new_antenna_id = self .create_component ("Antenna" , antenna_name , "Antennas" )
170- if new_radio_id and new_antenna_id :
171- self .connect_components (new_antenna_id , new_radio_id ) # Connect antenna to radio
172- return new_radio_id , new_antenna_id
171+ new_radio = self .create_component (radio_type , radio_name , library )
172+ new_antenna = self .create_component ("Antenna" , antenna_name , "Antennas" )
173+ if new_radio and new_antenna :
174+ self .connect_components (new_antenna . name , new_radio . name ) # Connect antenna to radio
175+ return new_radio , new_antenna
173176 except Exception as e :
174177 self .emit_instance .logger .error (f"Failed to create radio of type '{ radio_type } ' or antenna: { e } " )
175178 raise RuntimeError (f"Failed to create radio of type '{ radio_type } ' or antenna: { e } " )
176179
177180 @pyaedt_function_handler
178- def connect_components (self , component_id_1 : int , component_id_2 : int ) :
181+ def connect_components (self , component_name_1 : str , component_name_2 : str ) -> None :
179182 """Connect two components in the schematic.
180183
181184 Parameters
182185 ----------
183- component_id_1 : str
184- ID of the first component.
185- component_id_2 : str
186- ID of the second component.
186+ component_1 : str
187+ Name of the first component.
188+ component_2 : str
189+ Name of the second component.
187190
188191 Raises
189192 ------
190193 RuntimeError
191194 If the connection fails.
192195 """
193196 try :
194- component_name_1 = self .get_component_properties (component_id_1 , "Name" )
195- component_name_2 = self .get_component_properties (component_id_2 , "Name" )
196197 self .emit_instance ._oeditor .PlaceComponent (component_name_1 , component_name_2 )
197198 self .emit_instance .logger .info (
198199 f"Successfully connected components '{ component_name_1 } ' and '{ component_name_2 } '."
199200 )
200201 except Exception as e :
201202 self .emit_instance .logger .error (
202- f"Failed to connect components '{ component_id_1 } ' and '{ component_id_2 } ': { e } "
203+ f"Failed to connect components '{ component_name_1 } ' and '{ component_name_2 } ': { e } "
203204 )
204- raise RuntimeError (f"Failed to connect components '{ component_id_1 } ' and '{ component_id_2 } ': { e } " )
205-
206- @pyaedt_function_handler
207- def get_component_properties (self , component_id : int , property_key : str = None ) -> dict :
208- """Get properties of a component.
209-
210- Parameters
211- ----------
212- component_id : int
213- ID of the component.
214- property_key : str, optional
215- Specific property key to retrieve. If ``None``, all properties are returned.
216-
217- Returns
218- -------
219- dict or str
220- Dictionary containing all properties of the component if `property_key` is ``None``.
221- Otherwise, the value of the specified property key.
222-
223- Raises
224- ------
225- KeyError
226- If the specified property key is not found.
227- """
228- try :
229- props = self ._emit_com_module .GetEmitNodeProperties (0 , component_id , True )
230- props_dict = {prop .split ("=" , 1 )[0 ]: prop .split ("=" , 1 )[1 ] for prop in props }
231- if property_key is None :
232- return props_dict
233- if property_key in props_dict :
234- return props_dict [property_key ]
235- raise KeyError (f"Property key '{ property_key } ' not found." )
236- except Exception as e :
237- self .emit_instance .logger .error (f"Failed to retrieve properties for component '{ component_id } ': { e } " )
238- raise RuntimeError (f"Failed to retrieve properties for component '{ component_id } ': { e } " )
205+ raise RuntimeError (f"Failed to connect components '{ component_name_1 } ' and '{ component_name_2 } ': { e } " )
0 commit comments