Skip to content

FIX: Schematic name argument optional in edit_external_circuit method #6092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/6092.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Schematic name argument optional in edit_external_circuit method
66 changes: 32 additions & 34 deletions src/ansys/aedt/core/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,15 +2016,15 @@
return circuit

@pyaedt_function_handler()
def edit_external_circuit(self, netlist_file_path, schematic_design_name, parameters=None):
def edit_external_circuit(self, netlist_file_path, schematic_design_name=None, parameters=None):
"""
Edit the external circuit for the winding and allow editing of the circuit parameters.

Parameters
----------
netlist_file_path : str
Path to the circuit netlist file.
schematic_design_name : str
schematic_design_name : str, optional
Name of the schematic design.
parameters : dict, optional
Name and value of the circuit parameters.
Expand All @@ -2039,42 +2039,40 @@
bool
``True`` when successful, ``False`` when failed.
"""
if schematic_design_name not in self.design_list:
raise AEDTRuntimeError(f"Schematic design '{schematic_design_name}' is not in design list.")

odesign = self.desktop_class.active_design(self.oproject, schematic_design_name)
oeditor = odesign.SetActiveEditor("SchematicEditor")
if is_linux and settings.aedt_version == "2024.1": # pragma: no cover
time.sleep(1)
self.desktop_class.close_windows()
comps = oeditor.GetAllComponents()
sources_array = []
sources_type_array = []
for comp in comps:
if "Voltage Source" in oeditor.GetPropertyValue("ComponentTab", comp, "Description"):
comp_id = "V" + comp.split("@")[1].split(";")[1]
elif "Current Source" in oeditor.GetPropertyValue("ComponentTab", comp, "Description"):
comp_id = "I" + comp.split("@")[1].split(";")[1]
else:
continue
sources_array.append(comp_id)
refdes = oeditor.GetPropertyValue("ComponentTab", comp, "RefDes")
comp_instance = oeditor.GetCompInstanceFromRefDes(refdes)
if "DC" in oeditor.GetPropertyValue("ComponentTab", comp, "Description"):
sources_type_array.append(1)
else:
source_type = comp_instance.GetPropHost().GetText("Type")
if source_type == "TIME":
if schematic_design_name:
if schematic_design_name not in self.design_list:
raise AEDTRuntimeError(f"Schematic design '{schematic_design_name}' is not in design list.")

odesign = self.desktop_class.active_design(self.oproject, schematic_design_name)
oeditor = odesign.SetActiveEditor("SchematicEditor")

if is_linux and settings.aedt_version == "2024.1": # pragma: no cover
time.sleep(1)
self.desktop_class.close_windows()

sources_array, sources_type_array = [], []
for comp in oeditor.GetAllComponents():
if "Voltage Source" in oeditor.GetPropertyValue("ComponentTab", comp, "Description"):
comp_id = "V" + comp.split("@")[1].split(";")[1]
elif "Current Source" in oeditor.GetPropertyValue("ComponentTab", comp, "Description"):
comp_id = "I" + comp.split("@")[1].split(";")[1]
else:
continue

sources_array.append(comp_id)
refdes = oeditor.GetPropertyValue("ComponentTab", comp, "RefDes")
comp_instance = oeditor.GetCompInstanceFromRefDes(refdes)

if "DC" in oeditor.GetPropertyValue("ComponentTab", comp, "Description"):
sources_type_array.append(1)
elif source_type == "POS":
sources_type_array.append(2)
elif source_type == "SPEED":
sources_type_array.append(3)
else:
source_type = comp_instance.GetPropHost().GetText("Type")
sources_type_array.append({"TIME": 1, "POS": 2, "SPEED": 3}.get(source_type, 0))

names = []
values = []
if parameters:
names = list(parameters.keys())
values = list(parameters.values())
names, values = list(parameters.keys()), list(parameters.values())

Check warning on line 2075 in src/ansys/aedt/core/maxwell.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/maxwell.py#L2075

Added line #L2075 was not covered by tests
netlist_file_path = ""
self.oboundary.EditExternalCircuit(netlist_file_path, sources_array, sources_type_array, names, values)
return True
Expand Down
3 changes: 3 additions & 0 deletions tests/system/general/test_35_MaxwellCircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ansys.aedt.core import Maxwell2d
from ansys.aedt.core import MaxwellCircuit
from ansys.aedt.core.generic.constants import SOLUTIONS
from ansys.aedt.core.internal.checks import AEDTRuntimeError
import pytest

from tests import TESTS_GENERAL_PATH
Expand Down Expand Up @@ -110,6 +111,8 @@ def test_07_export_netlist(self, add_app):
m2d.assign_coil(assignment=["Circle_inner"])
m2d.assign_winding(assignment=["Circle_inner"], winding_type="External", name="Ext_Wdg")
assert m2d.edit_external_circuit(netlist_file, self.aedtapp.design_name)
with pytest.raises(AEDTRuntimeError):
m2d.edit_external_circuit(netlist_file, "invalid")

def test_08_import_netlist(self):
self.aedtapp.insert_design("SchematicImport")
Expand Down
Loading