profile.copy_profile

Fixes issue duplicated profile missing it's psets.
This commit is contained in:
Andrej730
2024-09-07 11:09:47 +05:00
parent e224bfd19f
commit 33001e6c6d
5 changed files with 97 additions and 1 deletions
@@ -26,6 +26,7 @@ from .. import wrap_usecases
from .add_arbitrary_profile import add_arbitrary_profile
from .add_arbitrary_profile_with_voids import add_arbitrary_profile_with_voids
from .add_parameterized_profile import add_parameterized_profile
from .copy_profile import copy_profile
from .edit_profile import edit_profile
from .remove_profile import remove_profile
@@ -35,6 +36,7 @@ __all__ = [
"add_arbitrary_profile",
"add_arbitrary_profile_with_voids",
"add_parameterized_profile",
"copy_profile",
"edit_profile",
"remove_profile",
]
@@ -0,0 +1,47 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
def copy_profile(file: ifcopenshell.file, profile: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
"""Copies a profile
All profile's psets are copied. The copied profile is not
associated to any elements.
:param profile: The IfcProfileDef to copy
:return: The new copy of the profile
Example:
.. code:: python
profile = ifcopenshell.api.profile.add_profile(model, ifc_class="IfcRectangleProfileDef")
# Let's duplicate the rectangle profile
profile_copy = ifcopenshell.api.profile.copy_profile(model, profile=profile)
"""
new_profile = ifcopenshell.util.element.copy_deep(file, profile)
inverses = file.get_inverse(profile)
psets = [i for i in inverses if i.is_a("IfcProfileProperties")]
for pset in psets:
new_pset = ifcopenshell.util.element.copy_deep(file, pset, exclude=["IfcProfileDef"])
new_pset.ProfileDefinition = new_profile
return new_profile