Skip to content

Commit f9ce7dd

Browse files
jonahrbpyansys-ci-botRobPasMue
authored
feat: component operations - make_independent() and import_named_selections() (#2129)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>
1 parent aace701 commit f9ce7dd

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

doc/changelog.d/2129.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Component operations - make_independent() and import_named_selections()

src/ansys/geometry/core/designer/component.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
3838
from ansys.api.geometry.v0.components_pb2 import (
3939
CreateRequest,
40+
ImportGroupsRequest,
41+
MakeIndependentRequest,
4042
SetPlacementRequest,
4143
SetSharedTopologyRequest,
4244
)
@@ -70,6 +72,7 @@
7072
from ansys.geometry.core.math.matrix import Matrix44
7173
from ansys.geometry.core.math.point import Point3D
7274
from ansys.geometry.core.math.vector import UnitVector3D, Vector3D
75+
from ansys.geometry.core.misc.auxiliary import get_design_from_component
7376
from ansys.geometry.core.misc.checks import (
7477
ensure_design_is_active,
7578
graphics_required,
@@ -1876,3 +1879,43 @@ def build_parent_tree(comp: Component, parent_tree: str = "") -> str:
18761879
lines.extend([f"|{'-' * (indent - 1)}(comp) {comp.name}" for comp in comps])
18771880

18781881
return lines if return_list else print("\n".join(lines))
1882+
1883+
@protect_grpc
1884+
@min_backend_version(26, 1, 0)
1885+
def import_named_selections(self) -> None:
1886+
"""Import named selections of a component.
1887+
1888+
When a design is inserted, it becomes a component. From 26R1 onwards, the named selections
1889+
of that component will be imported by default. If a file is opened that contains a
1890+
component that did not have its named selections imported, this method can be used to
1891+
import them.
1892+
1893+
Warnings
1894+
--------
1895+
This method is only available starting on Ansys release 26R1.
1896+
"""
1897+
self._component_stub.ImportGroups(ImportGroupsRequest(id=self._grpc_id))
1898+
1899+
design = get_design_from_component(self)
1900+
design._update_design_inplace()
1901+
1902+
@protect_grpc
1903+
@min_backend_version(26, 1, 0)
1904+
def make_independent(self, others: list["Component"] = None) -> None:
1905+
"""Make a component independent if it is an instance.
1906+
1907+
If a component is an instance of another component, modifying one component modifies both.
1908+
When a component is made independent, it is no longer associated with other instances and
1909+
can be modified separately.
1910+
1911+
Parameters
1912+
----------
1913+
others : list[Component], default: None
1914+
Optionally include multiple components to make them all independent.
1915+
1916+
Warnings
1917+
--------
1918+
This method is only available starting on Ansys release 26R1.
1919+
"""
1920+
ids = [self._grpc_id, *[o._grpc_id for o in others or []]]
1921+
self._component_stub.MakeIndependent(MakeIndependentRequest(ids=ids))

tests/integration/files/cars.scdocx

77.7 KB
Binary file not shown.
Binary file not shown.

tests/integration/test_design.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,3 +3548,33 @@ def test_extrude_edges_missing_parameters(modeler: Modeler):
35483548
from_point=None,
35493549
direction=None,
35503550
)
3551+
3552+
3553+
def test_import_component_named_selections(modeler: Modeler):
3554+
"""Test importing named selections from an inserted design component."""
3555+
# This file had a component inserted into it that has named selections that we need to import
3556+
design = modeler.open_file(Path(FILES_DIR, "import_component_groups.scdocx"))
3557+
component = design.components[0]
3558+
3559+
assert len(design.named_selections) == 0
3560+
component.import_named_selections()
3561+
assert len(design.named_selections) == 3
3562+
3563+
3564+
def test_component_make_independent(modeler: Modeler):
3565+
"""Test making components independent."""
3566+
3567+
design = modeler.open_file(Path(FILES_DIR, "cars.scdocx"))
3568+
face = next((ns for ns in design.named_selections if ns.name == "to_pull"), None).faces[0]
3569+
comp = next(
3570+
(ns for ns in design.named_selections if ns.name == "make_independent"), None
3571+
).components[0]
3572+
3573+
comp.make_independent()
3574+
3575+
assert Accuracy.length_is_equal(comp.bodies[0].volume.m, face.body.volume.m)
3576+
3577+
modeler.geometry_commands.extrude_faces(face, 1)
3578+
comp = design.components[0].components[-1].components[-1] # stale from update-design-in-place
3579+
3580+
assert not Accuracy.length_is_equal(comp.bodies[0].volume.m, face.body.volume.m)

0 commit comments

Comments
 (0)