diff --git a/_unittest/test_00_EDB.py b/_unittest/test_00_EDB.py index 2b70f3e01da..d0dcb2b9882 100644 --- a/_unittest/test_00_EDB.py +++ b/_unittest/test_00_EDB.py @@ -165,6 +165,12 @@ def test_08_nets_query(self): assert not signalnets[list(signalnets.keys())[0]].IsPowerGround() assert len(list(signalnets[list(signalnets.keys())[0]].primitives)) > 0 + assert self.edbapp.core_nets.find_or_create_net("GND") + assert self.edbapp.core_nets.find_or_create_net(start_with="gn") + assert self.edbapp.core_nets.find_or_create_net(start_with="g", end_with="d") + assert self.edbapp.core_nets.find_or_create_net(end_with="d") + assert self.edbapp.core_nets.find_or_create_net(contain="usb") + def test_09_assign_rlc(self): assert self.edbapp.core_components.set_component_rlc( "C3B14", res_value=1e-3, cap_value="10e-6", isparallel=False diff --git a/pyaedt/edb_core/nets.py b/pyaedt/edb_core/nets.py index 4406ce4ae9f..a8769a4eafd 100644 --- a/pyaedt/edb_core/nets.py +++ b/pyaedt/edb_core/nets.py @@ -598,7 +598,7 @@ def delete_nets(self, netlist): return nets_deleted @pyaedt_function_handler() - def find_or_create_net(self, net_name=""): + def find_or_create_net(self, net_name="", start_with="", contain="", end_with=""): """Find or create the net with the given name in the layout. Parameters @@ -606,19 +606,71 @@ def find_or_create_net(self, net_name=""): net_name : str, optional Name of the net to find or create. The default is ``""``. + start_with : str, optional + All net name starting with the string. Not case-sensitive. + + contain : str, optional + All net name containing the string. Not case-sensitive. + + end_with : str, optional + All net name ending with the string. Not case-sensitive. + Returns ------- object Net Object """ - if not net_name: + if not net_name and not start_with and not contain and not end_with: net_name = generate_unique_name("NET_") net = self._edb.Cell.Net.Create(self._active_layout, net_name) + return net else: - net = self._edb.Cell.Net.FindByName(self._active_layout, net_name) - if net.IsNull(): - net = self._edb.Cell.Net.Create(self._active_layout, net_name) - return net + if not start_with and not contain and not end_with: + net = self._edb.Cell.Net.FindByName(self._active_layout, net_name) + if net.IsNull(): + net = self._edb.Cell.Net.Create(self._active_layout, net_name) + return net + elif start_with: + nets_found = [ + self.nets[net].net_object for net in list(self.nets.keys()) if net.lower().startswith(start_with) + ] + return nets_found + elif start_with and end_with: + nets_found = [ + self.nets[net].net_object + for net in list(self.nets.keys()) + if net.lower().startswith(start_with) and net.lower().endswith(end_with) + ] + return nets_found + elif start_with and contain and end_with: + nets_found = [ + self.nets[net].net_object + for net in list(self.nets.keys()) + if net.lower().startswith(start_with) and net.lower().endswith(end_with) and contain in net.lower() + ] + return nets_found + elif start_with and contain: + nets_found = [ + self.nets[net].net_object + for net in list(self.nets.keys()) + if net.lower().startswith(start_with) and contain in net.lower() + ] + return nets_found + elif contain and end_with: + nets_found = [ + self.nets[net].net_object + for net in list(self.nets.keys()) + if net.lower().endswith(end_with) and contain in net.lower() + ] + return nets_found + elif end_with and not start_with and not contain: + nets_found = [ + self.nets[net].net_object for net in list(self.nets.keys()) if net.lower().endswith(end_with) + ] + return nets_found + elif contain and not start_with and not end_with: + nets_found = [self.nets[net].net_object for net in list(self.nets.keys()) if contain in net.lower()] + return nets_found @pyaedt_function_handler() def is_net_in_component(self, component_name, net_name):