This commit is contained in:
Andrej730
2024-05-13 12:27:53 +05:00
parent c3bfd7354f
commit ebd03e9290
56 changed files with 244 additions and 127 deletions
@@ -21,15 +21,15 @@ import ifcopenshell.api
import ifcopenshell.util.element
def change_nest(file, item=None, new_parent=None) -> None:
def change_nest(
file: ifcopenshell.file, item: ifcopenshell.entity_instance, new_parent: ifcopenshell.entity_instance
) -> None:
"""Assigns a cost item to a new parent cost item"""
settings = {"item": item, "new_parent": new_parent}
if not settings["item"].Nests:
if not item.Nests:
return
nests = settings["item"].Nests[0]
nests = item.Nests[0]
related_objects = list(nests.RelatedObjects)
related_objects.remove(settings["item"])
related_objects.remove(item)
if related_objects:
nests.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": nests})
@@ -41,6 +41,6 @@ def change_nest(file, item=None, new_parent=None) -> None:
ifcopenshell.api.run(
"nest.assign_object",
file,
related_objects=[settings["item"]],
relating_object=settings["new_parent"],
related_objects=[item],
relating_object=new_parent,
)
@@ -15,19 +15,18 @@
#
# 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
def reorder_nesting(file, item=None, old_index=0, new_index=0) -> None:
def reorder_nesting(
file: ifcopenshell.file, item: ifcopenshell.entity_instance, old_index: int = 0, new_index: int = 0
) -> None:
"""Reorders an item in a nesting set"""
settings = {"item": item, "old_index": old_index, "new_index": new_index}
if not settings["item"].Nests:
if not item.Nests:
return
nesting_set = settings["item"].Nests[0]
if not settings["old_index"]:
old_index = nesting_set.RelatedObjects.index(settings["item"])
else:
old_index = settings["old_index"]
nesting_set = item.Nests[0]
if not old_index:
old_index = nesting_set.RelatedObjects.index(item)
items = list(getattr(nesting_set, "RelatedObjects") or [])
items.insert(settings["new_index"], items.pop(old_index))
items.insert(new_index, items.pop(old_index))
setattr(nesting_set, "RelatedObjects", items)