diff --git a/src/ifcopenshell-python/ifcopenshell/geom/main.py b/src/ifcopenshell-python/ifcopenshell/geom/main.py index 5f3e2079f2..fa1cbd22f2 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/main.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/main.py @@ -22,7 +22,7 @@ import os import sys import operator -from .. import ifcopenshell_wrapper +from .. import open, ifcopenshell_wrapper from ..file import file from ..entity_instance import entity_instance @@ -307,10 +307,7 @@ class iterator(ifcopenshell_wrapper.Iterator): self.file = file file_or_filename = file_or_filename.wrapped_data else: - # @todo? - self.file = None - # Makes sure people are able to use python's platform agnostic paths - file_or_filename = os.path.abspath(file_or_filename) + file_or_filename = self.file = open(file_or_filename) if include is not None and exclude is not None: raise ValueError("include and exclude cannot be specified simultaneously") @@ -342,7 +339,7 @@ class iterator(ifcopenshell_wrapper.Iterator): geometry_library, self.settings, file_or_filename, include_or_exclude, include is not None, num_threads ) else: - ifcopenshell_wrapper.Iterator.__init__(self, geometry_library, settings, file_or_filename, num_threads) + self.this = ifcopenshell_wrapper.construct_iterator(geometry_library, self.settings, file_or_filename, num_threads) if has_occ: diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 5b7b4aba0b..6991abbdaf 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -628,6 +628,7 @@ struct ShapeRTTI : public boost::static_visitor $result = boost::apply_visitor(ShapeRTTI(), (boost::variant) $1); } +%newobject construct_iterator; %newobject construct_iterator_with_include_exclude; %newobject construct_iterator_with_include_exclude_globalid; %newobject construct_iterator_with_include_exclude_id; @@ -635,6 +636,10 @@ struct ShapeRTTI : public boost::static_visitor // I couldn't get the vector typemap to be applied when %extending Iterator constructor. // anyway it does not matter as SWIG generates C code without actual constructors %inline %{ + IfcGeom::Iterator* construct_iterator(const std::string& geometry_library, ifcopenshell::geometry::Settings settings, IfcParse::IfcFile* file, int num_threads) { + return new IfcGeom::Iterator(ifcopenshell::geometry::kernels::construct(file, geometry_library, settings), settings, file, num_threads); + } + IfcGeom::Iterator* construct_iterator_with_include_exclude(const std::string& geometry_library, ifcopenshell::geometry::Settings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { std::set elems_set(elems.begin(), elems.end()); IfcGeom::entity_filter ef{ include, false, elems_set };