mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
typing
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user