diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index ba1658d188..a3e87e1acb 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -610,7 +610,7 @@ class file_mixin: """ eid = kwargs.pop("id", -1) - e = self.create(type) + e = self.create(type, eid) # Create pairs of {attribute index, attribute value}. # Keyword arguments are mapped to their corresponding diff --git a/src/ifcparse/IfcFile.cpp b/src/ifcparse/IfcFile.cpp index 80582167d7..2ef3d4f8ea 100644 --- a/src/ifcparse/IfcFile.cpp +++ b/src/ifcparse/IfcFile.cpp @@ -797,6 +797,9 @@ express::Base IfcParse::impl::in_memory_file_storage::create(const IfcParse::dec express::Base IfcParse::IfcFile::create(const IfcParse::declaration* decl, int id) { if (id != -1) { + if (decl->as_entity() == nullptr) { + throw IfcParse::IfcException("Assigning instance id during creation is only valid for entity declarations"); + } bool id_already_exists = false; try { if (check_existance_before_adding) { @@ -808,6 +811,9 @@ express::Base IfcParse::IfcFile::create(const IfcParse::declaration* decl, int i if (id_already_exists) { throw IfcParse::IfcException("An instance with id " + boost::lexical_cast(id) + " is already part of this file"); } + if ((unsigned)id > max_id_) { + max_id_ = (unsigned)id; + } } return std::visit([&](auto& m) -> express::Base {