diff --git a/src/ifcparse/IfcUntypedEntity.cpp b/src/ifcparse/IfcUntypedEntity.cpp index 0ac2416abe..3d8981e8aa 100644 --- a/src/ifcparse/IfcUntypedEntity.cpp +++ b/src/ifcparse/IfcUntypedEntity.cpp @@ -30,6 +30,13 @@ IfcParse::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity* e) { entity = e; _type = e->type(); } +unsigned int IfcParse::IfcUntypedEntity::id() const { + if (entity->file) { + return static_cast(entity->id()); + } else { + throw IfcException("Entity not bound to a file"); + } +} bool IfcParse::IfcUntypedEntity::is(IfcSchema::Type::Enum v) const { IfcSchema::Type::Enum _ty = _type; if (v == _ty) return true; diff --git a/src/ifcparse/IfcUntypedEntity.h b/src/ifcparse/IfcUntypedEntity.h index 0d1bc287e4..84c0f1e1ba 100644 --- a/src/ifcparse/IfcUntypedEntity.h +++ b/src/ifcparse/IfcUntypedEntity.h @@ -17,10 +17,13 @@ namespace IfcParse { public: IfcUntypedEntity(const std::string& s); IfcUntypedEntity(IfcAbstractEntity* e); + bool is(IfcSchema::Type::Enum v) const; IfcSchema::Type::Enum type() const; bool is_a(const std::string& s) const; std::string is_a() const; + + unsigned int id() const; unsigned int getArgumentCount() const; IfcUtil::ArgumentType getArgumentType(unsigned int i) const; ArgumentPtr getArgument(unsigned int i) const; diff --git a/src/ifcwrap/Interface.h b/src/ifcwrap/Interface.h index 5944c3db43..07437a0aba 100644 --- a/src/ifcwrap/Interface.h +++ b/src/ifcwrap/Interface.h @@ -17,10 +17,13 @@ namespace IfcParse { IfcSchema::Type::Enum _type; public: IfcUntypedEntity(const std::string& s); + bool is(IfcSchema::Type::Enum v) const; IfcSchema::Type::Enum type() const; bool is_a(const std::string& s) const; std::string is_a() const; + + unsigned int id() const; unsigned int getArgumentCount() const; IfcUtil::ArgumentType getArgumentType(unsigned int i) const; ArgumentPtr getArgument(unsigned int i) const; diff --git a/src/ifcwrap/ifc.py b/src/ifcwrap/ifc.py index be63a4d02b..18439632d7 100644 --- a/src/ifcwrap/ifc.py +++ b/src/ifcwrap/ifc.py @@ -43,12 +43,14 @@ class entity_instance: self.wrapped_data.set_argument(idx, entity_instance.map_value(value)) def __len__(self): return len(self.wrapped_data) def __repr__(self): return repr(self.wrapped_data) + def is_a(self, *args): return self.wrapped_data.is_a(*args) + def id(self): return self.wrapped_data.id() class file: instances = [] - def __init__(self, f): - self.wrapped_data = f + def __init__(self, f=None): + self.wrapped_data = f or ifc_wrapper.file() def create_entity(self,type,*args,**kwargs): e = entity_instance(ifc_wrapper.entity_instance(type)) attrs = list(enumerate(args)) + \ @@ -94,8 +96,8 @@ class guid: return '{%s-%s-%s-%s-%s}'%(g[:8], g[8:12], g[12:16], g[16:20], g[20:]) -def open(fn): - return file(ifc_wrapper.open(fn)) +def open(fn=None): + return file(ifc_wrapper.open(fn)) if fn else file() def create_shape(inst, settings): return ifc_wrapper.create_shape(inst.wrapped_data, settings)