Skip to content
Draft
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/7029.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
N port component multi
65 changes: 65 additions & 0 deletions src/ansys/aedt/core/arguments/component_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pydantic import BaseModel
from pydantic import Field


class Files(BaseModel):
files: List[str] = Field(..., min_length=1)

@classmethod
def create(cls, **kwargs):
return cls.model_validate(kwargs)

def to_aedt_args(self):
args = ["NAME:Files"]
if self.files is not None:
args.extend(["Files:=", self.files])
return args


class Options(BaseModel):
num_ports_or_lines: int = Field(..., ge=1)
array_name: str
array_id_name: str
comp_name: str

@classmethod
def create(cls, **kwargs):
return cls.model_validate(kwargs)

def to_aedt_args(self):
args = ["NAME:Options"]
if self.num_ports_or_lines is not None:
args.extend(["NumPortsOrLines:=", self.num_ports_or_lines])
args.extend(["CreateArray:=", True])
if self.array_name is not None:
args.extend(["ArrayName:=", self.array_name])
if self.array_id_name is not None:
args.extend(["ArrayIdName:=", self.array_id_name])
args.extend(["CompType:=", 2])
if self.comp_name is not None:
args.extend(["CompName:=", self.comp_name])
return args
82 changes: 82 additions & 0 deletions src/ansys/aedt/core/arguments/editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pydantic import BaseModel

from ansys.aedt.core.generic.numbers_utils import Quantity


def convert_to_meter(value):
"""Convert numbers automatically to mils.

It is rounded to the nearest 100 mil which is minimum schematic snap unit.
"""
value = Quantity(value, "mil")

value = value.to("mil")
value.value = round(value.value, -2)
value = value.to("meter")
return value.value


class ComponentProps(BaseModel):
name: str

@classmethod
def create(cls, **kwargs):
return cls.model_validate(kwargs)

def to_aedt_args(self):
args = ["NAME:ComponentProps"]
if self.name is not None:
args.extend(["Name:=", self.name])
return args


class Attributes(BaseModel):
page: int = 1
x: float
y: float
angle: float = 0.0
flip: bool = False

@classmethod
def create(cls, **kwargs):
kwargs["x"] = convert_to_meter(kwargs.pop("x"))
kwargs["y"] = convert_to_meter(kwargs.pop("y"))
return cls.model_validate(kwargs)

def to_aedt_args(self):
args = ["NAME:Attributes"]
if self.page is not None:
args.extend(["Page:=", self.page])
if self.x is not None:
args.extend(["X:=", self.x])
if self.y is not None:
args.extend(["Y:=", self.y])
if self.angle is not None:
args.extend(["Angle:=", self.angle])
if self.flip is not None:
args.extend(["Flip:=", self.flip])
return args
26 changes: 26 additions & 0 deletions src/ansys/aedt/core/modeler/circuits/primitives_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,32 @@ def create_wire(self, points, name="", page=1):
except Exception:
return False

@pyaedt_function_handler()
def create_nport_multi(
self, component_name, num_ports_or_lines, array_name, array_id_name, files, x, y, page=1, angle=0.0, flip=False
):
from ansys.aedt.core.arguments.component_manager import Files
from ansys.aedt.core.arguments.component_manager import Options
from ansys.aedt.core.arguments.editor import Attributes
from ansys.aedt.core.arguments.editor import ComponentProps

files_args = Files.create(files=files).to_aedt_args()
options_args = Options.create(
num_ports_or_lines=num_ports_or_lines,
array_name=array_name,
array_id_name=array_id_name,
comp_name=component_name,
).to_aedt_args()
self.ocomponent_manager.ImportSandWComponent(files_args, options_args)

props_args = ComponentProps.create(name=component_name).to_aedt_args()
attributes_args = Attributes.create(x=x, y=y, page=page, flip=flip, angle=angle).to_aedt_args()

comp_name = self.oeditor.CreateComponent(props_args, attributes_args)
comp_id = int(comp_name.split(";")[-1])
self.add_id_to_component(comp_id, comp_name)
return self.components[comp_id]


class ComponentInfo(PyAedtBase):
"""Manages Circuit Catalog info."""
Expand Down
Loading