From e81dd9c7df7bc13d8f4c1d0a7d51b0d8fad661ae Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sat, 26 Feb 2022 14:57:21 +0100 Subject: [PATCH] Option to yield progress from iterate() and consume_iterator() --- src/ifcopenshell-python/ifcopenshell/geom/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/geom/main.py b/src/ifcopenshell-python/ifcopenshell/geom/main.py index ee125ef9ce..5fd344e571 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/main.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/main.py @@ -211,17 +211,20 @@ def create_shape(settings, inst, repr=None): ) -def consume_iterator(it): +def consume_iterator(it, with_progress=False): if it.initialize(): while True: - yield it.get() + if with_progress: + yield it.progress(), it.get() + else: + yield it.get() if not it.next(): break -def iterate(settings, file_or_filename, num_threads=1, include=None, exclude=None): +def iterate(settings, file_or_filename, num_threads=1, include=None, exclude=None, with_progress=False): it = iterator(settings, file_or_filename, num_threads, include, exclude) - yield from consume_iterator(it) + yield from consume_iterator(it, with_progress=with_progress) def make_shape_function(fn):