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
@@ -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)