mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
more descriptive errors creating entities - setting incorrect attributes
example:
```
ifc_file = ifcopenshell.file(schema="IFC4")
entity = ifc_file.create_entity("IfcRoot", "xxx", None, None, None, None)
entity = ifc_file.create_entity("IfcRoot", Location=None)
```
This commit is contained in:
@@ -332,7 +332,14 @@ class file:
|
|||||||
# @todo we should probably check that values for
|
# @todo we should probably check that values for
|
||||||
# attributes are not passed as duplicates using
|
# attributes are not passed as duplicates using
|
||||||
# both regular arguments and keyword arguments.
|
# both regular arguments and keyword arguments.
|
||||||
attrs = list(enumerate(args)) + [(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
|
kwargs_attrs = [(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
|
||||||
|
attrs = list(enumerate(args)) + kwargs_attrs
|
||||||
|
|
||||||
|
if len(attrs) > len(e):
|
||||||
|
raise ValueError(
|
||||||
|
"entity instance of type '%s' has only %s attributes but %s attributes were provided."
|
||||||
|
% (e.is_a(True), len(e), len(attrs))
|
||||||
|
)
|
||||||
|
|
||||||
# Don't store these attributes as transactions
|
# Don't store these attributes as transactions
|
||||||
# as the creation it self is already stored with
|
# as the creation it self is already stored with
|
||||||
@@ -341,8 +348,18 @@ class file:
|
|||||||
transaction = self.transaction
|
transaction = self.transaction
|
||||||
self.transaction = None
|
self.transaction = None
|
||||||
|
|
||||||
for idx, arg in attrs:
|
try:
|
||||||
e[idx] = arg
|
for idx, arg in attrs:
|
||||||
|
e[idx] = arg
|
||||||
|
except IndexError:
|
||||||
|
invalid_attrs = []
|
||||||
|
for (attr_index, _), attr_name in zip(kwargs_attrs, kwargs):
|
||||||
|
if attr_index == 0xFFFFFFFF:
|
||||||
|
invalid_attrs.append(attr_name)
|
||||||
|
raise ValueError(
|
||||||
|
"entity instance of type '%s' doesn't have the following attributes: %s."
|
||||||
|
% (e.is_a(True), ", ".join(invalid_attrs))
|
||||||
|
)
|
||||||
|
|
||||||
# Restore transaction status
|
# Restore transaction status
|
||||||
if attrs:
|
if attrs:
|
||||||
|
|||||||
Reference in New Issue
Block a user