diff --git a/src/ansys/aedt/core/maxwellcircuit.py b/src/ansys/aedt/core/maxwellcircuit.py index 033424e26f7..bb9c94a371a 100644 --- a/src/ansys/aedt/core/maxwellcircuit.py +++ b/src/ansys/aedt/core/maxwellcircuit.py @@ -242,3 +242,53 @@ def export_netlist_from_schematic(self, output_file): return output_file except Exception: return False + + def create_page(self, name): + """Add a new page to circuit schematic. + + Parameters + ---------- + name : str, int or float + Name to be used when creating the new circuit schematic. + + Returns + ------- + bool + ``True`` when page added, ``False`` when failed. + + References + ---------- + >>> oEditor.CreatePage() + + Examples + -------- + >>>from ansys.aedt.core import MaxwellCircuit + >>>app=MaxwellCircuit() + >>>component=app.create_page(name="page_name") + """ + if not isinstance(name, (str, int, float)): + self.logger.error("Wrong type for argument ``name``.") + return False + self.oeditor.CreatePage(name) + return True + + def get_num_pages(self): + """Gets the number of circuit schematic pages. + + Returns + ------- + int + The number of pages in the circuit schematic. + + References + ---------- + >>> oEditor.GetNumPages() + + Examples + -------- + >>>from ansys.aedt.core import MaxwellCircuit + >>>app=MaxwellCircuit() + >>>component=app.get_num_pages() + """ + pages = self.oeditor.GetNumPages() + return pages diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_circuit.py b/src/ansys/aedt/core/modeler/circuits/primitives_circuit.py index 065d001a95f..42e06168a09 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_circuit.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_circuit.py @@ -1262,6 +1262,57 @@ def create_wire(self, points, name=""): except Exception: return False + def create_page(self, name): + """Add a new circuit schematic page. + + Parameters + ---------- + name : str, int or float + Name to be used when creating the new circuit schematic. + + Returns + ------- + bool + ``True`` when successful, ``False`` when failed. + + References + ---------- + >>> oEditor.CreatePage() + + Examples + -------- + >>>from ansys.aedt.core import MaxwellCircuit + >>>app=MaxwellCircuit () + >>>component=app.modeler.schematic.create_page(name=page_name) + + """ + if not isinstance(name, (str, int, float)): + self.logger.error("Wrong type for argument ``name``.") + return False + self.oeditor.CreatePage(name) + return True + + def get_num_pages(self): + """Gets the number of circuit schematic pages. + + Returns + ------- + int + The number of pages in the circuit schematic. + References + ---------- + >>> oeditor.GetNumPages () + Examples + -------- + >>>from ansys.aedt.core import MaxwellCircuit + >>>app=MaxwellCircuit () + >>>schematic=app.modeler.schematic + >>>schematic.get_num_pages () + + """ + pages = self.oeditor.GetNumPages() + return pages + class ComponentInfo(object): """Manages Circuit Catalog info.""" diff --git a/src/ansys/aedt/core/modeler/circuits/primitives_maxwell_circuit.py b/src/ansys/aedt/core/modeler/circuits/primitives_maxwell_circuit.py index fe2b6844302..b46b2b36ee8 100644 --- a/src/ansys/aedt/core/modeler/circuits/primitives_maxwell_circuit.py +++ b/src/ansys/aedt/core/modeler/circuits/primitives_maxwell_circuit.py @@ -85,8 +85,8 @@ def create_resistor(self, name=None, value=50, location=None, angle=0, use_insta Parameters ---------- - name : str, optional - Name of the resistor. The default is ``None``. + name : str, int, float or optional + Name of the resistor. The default is ``None`` which adds a resistor without a name. value : float, optional Value for the resistor. The default is ``50``. location : list of float, optional @@ -109,7 +109,7 @@ def create_resistor(self, name=None, value=50, location=None, angle=0, use_insta if location == None: location = [] - id = self.create_component( + component = self.create_component( name, component_library="Passive Elements", component_name="Res", @@ -117,10 +117,10 @@ def create_resistor(self, name=None, value=50, location=None, angle=0, use_insta angle=angle, use_instance_id_netlist=use_instance_id_netlist, ) - - id.set_property("R", value) - id.set_property("Name", name) - return id + component.set_property("R", value) + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component @pyaedt_function_handler(compname="name") def create_inductor(self, name=None, value=50, location=None, angle=0, use_instance_id_netlist=False): @@ -128,8 +128,8 @@ def create_inductor(self, name=None, value=50, location=None, angle=0, use_insta Parameters ---------- - name : str, optional - Name of the inductor. The default is ``None``. + name : str, int, float or optional + Name of the inductor. The default is ``None`` which adds an inductor without a name. value : float, optional Value for the inductor. The default is ``50``. location : list of float, optional @@ -152,7 +152,7 @@ def create_inductor(self, name=None, value=50, location=None, angle=0, use_insta if location == None: location = [] - id = self.create_component( + component = self.create_component( name, component_library="Passive Elements", component_name="Ind", @@ -161,9 +161,10 @@ def create_inductor(self, name=None, value=50, location=None, angle=0, use_insta use_instance_id_netlist=use_instance_id_netlist, ) - id.set_property("L", value) - id.set_property("Name", name) - return id + component.set_property("L", value) + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component @pyaedt_function_handler(compname="name") def create_capacitor(self, name=None, value=50, location=None, angle=0, use_instance_id_netlist=False): @@ -171,8 +172,8 @@ def create_capacitor(self, name=None, value=50, location=None, angle=0, use_inst Parameters ---------- - name : str, optional - Name of the capacitor. The default is ``None``. + name : str, int, float or optional + Name of the capacitor. The default is ``None`` which adds a capacitor without a name. value : float, optional Value for the capacitor. The default is ``50``. location : list of float, optional @@ -194,7 +195,7 @@ def create_capacitor(self, name=None, value=50, location=None, angle=0, use_inst """ if location is None: location = [] - id = self.create_component( + component = self.create_component( name, component_library="Passive Elements", component_name="Cap", @@ -203,9 +204,10 @@ def create_capacitor(self, name=None, value=50, location=None, angle=0, use_inst use_instance_id_netlist=use_instance_id_netlist, ) - id.set_property("C", value) - id.set_property("Name", name) - return id + component.set_property("C", value) + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component @pyaedt_function_handler(compname="name") def create_diode(self, name=None, location=None, angle=0, use_instance_id_netlist=False): @@ -213,8 +215,8 @@ def create_diode(self, name=None, location=None, angle=0, use_instance_id_netlis Parameters ---------- - name : str, optional - Name of the diode. The default is ``None``. + name : str, int, float or optional + Name of the diode. The default is ``None`` which adds a diode without a name. location : list of float, optional Position on the X axis and Y axis. The default is ``None``. angle : float, optional @@ -235,7 +237,7 @@ def create_diode(self, name=None, location=None, angle=0, use_instance_id_netlis if location is None: location = [] - id = self.create_component( + component = self.create_component( name, component_library="Passive Elements", component_name="DIODE", @@ -244,8 +246,9 @@ def create_diode(self, name=None, location=None, angle=0, use_instance_id_netlis use_instance_id_netlist=use_instance_id_netlist, ) - id.set_property("Name", name) - return id + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component @pyaedt_function_handler(compname="name") def create_winding(self, name=None, location=None, angle=0, use_instance_id_netlist=False): @@ -253,8 +256,8 @@ def create_winding(self, name=None, location=None, angle=0, use_instance_id_netl Parameters ---------- - name : str, optional - Name of the winding. The default is ``None``. + name : str, int, float or optional + Name of the winding. The default is ``None`` which adds a winding without a name. location : list of float, optional Position on the X axis and Y axis. angle : float, optional @@ -274,7 +277,7 @@ def create_winding(self, name=None, location=None, angle=0, use_instance_id_netl """ if location is None: location = [] - id = self.create_component( + component = self.create_component( name, component_library="Dedicated Elements", component_name="Winding", @@ -282,5 +285,99 @@ def create_winding(self, name=None, location=None, angle=0, use_instance_id_netl angle=angle, use_instance_id_netlist=use_instance_id_netlist, ) - id.set_property("Name", name) - return id + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component + + def create_i_sin(self, name=None, value=1, location=None, angle=0, use_instance_id_netlist=False): + """Create a sinusoidal current source. + + Parameters + ---------- + name : str, int, float or optional + Name of the current source. The default is ``None`` which adds a current source without a name. + value : float, optional + Value for the amplitude of current. The default is ``1``. + location : list of float, optional + Position on the X axis and Y axis. + angle : float, optional + Angle of rotation in degrees. The default is ``0``. + use_instance_id_netlist : bool, optional + Whether to use the instance ID in the net list or not. The default is ``False``. + + Returns + ------- + :class:`ansys.aedt.core.modeler.cad.object_3dcircuit.CircuitComponent` + Circuit Component Object. + + References + ---------- + >>> oEditor.CreateComponent + + Examples + -------- + >>>from ansys.aedt.core import MaxwellCircuit + >>>app=MaxwellCircuit() + >>>component=app.modeler.schematic.create_i_sin(name="new_current_source", value = 100) + """ + if location is None: + location = [] + component = self.create_component( + name, + component_library="Sources", + component_name="ISin", + location=location, + angle=angle, + use_instance_id_netlist=use_instance_id_netlist, + ) + component.parameters["Ia"] = value + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component + + def create_v_sin(self, name=None, value=1, location=None, angle=0, use_instance_id_netlist=False): + """Create a sinusoidal voltage source. + + Parameters + ---------- + name : str, int, float or optional + Name of the voltage source. The default is ``None`` which adds a voltage source without a name. + value : float, optional + Value for the amplitude of voltage. The default is ``1``. + location : list of float, optional + Position on the X axis and Y axis. + angle : float, optional + Angle of rotation in degrees. The default is ``0``. + use_instance_id_netlist : bool, optional + Whether to use the instance ID in the net list or not. The default is ``False``. + + Returns + ------- + :class:`ansys.aedt.core.modeler.cad.object_3dcircuit.CircuitComponent` + Circuit Component Object. + + References + ---------- + + >>> oEditor.CreateComponent + + Examples + -------- + >>>from ansys.aedt.core import MaxwellCircuit + >>>app=MaxwellCircuit() + >>>component=app.modeler.schematic.create_v_sin(name="new_voltage_source", value = 240) + """ + if location is None: + location = [] + component = self.create_component( + name, + component_library="Sources", + component_name="VSin", + location=location, + angle=angle, + use_instance_id_netlist=use_instance_id_netlist, + ) + component.parameters["Va"] = value + if isinstance(name, (str, int, float)): + component.parameters["Name"] = name + return component diff --git a/tests/system/general/test_35_MaxwellCircuit.py b/tests/system/general/test_35_MaxwellCircuit.py index 39ef4277df4..43b3e0ab44f 100644 --- a/tests/system/general/test_35_MaxwellCircuit.py +++ b/tests/system/general/test_35_MaxwellCircuit.py @@ -115,3 +115,27 @@ def test_08_import_netlist(self): self.aedtapp.insert_design("SchematicImport") self.aedtapp.modeler.schematic.limits_mils = 5000 assert self.aedtapp.create_schematic_from_netlist(self.netlist_file1) + + def test_09_create_voltage_source(self): + name_type = ["voltage_source", 123, 1.23] + for item in name_type: + self.component = self.aedtapp.modeler.schematic.create_v_sin(name=item, value=3.14, angle=90) + assert self.component.parameters["Name"] == item + assert self.component.parameters["Va"] == 3.14 + + def test_10_create_current_source(self): + name_type = ["current_source", 456, 4.56] + for item in name_type: + self.component = self.aedtapp.modeler.schematic.create_i_sin(name=item, value=2.72, angle=90) + assert self.component.parameters["Name"] == item + assert self.component.parameters["Ia"] == 2.72 + + def test_11_create_page(self): + assert self.aedtapp.create_page("string_test") == True + assert self.aedtapp.create_page(123) == True + assert self.aedtapp.create_page(3.14) == True + assert not self.aedtapp.create_page(["create_page_test"]) + + def test_12_get_num_pages(self): + assert type(self.aedtapp.get_num_pages()) == int + assert not type(self.aedtapp.get_num_pages()) == str, float