inverse attributes

This forum section is only for IFC-related issues
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

inverse attributes

Post by yorik »

...

You know, something I've been thinking... This big series of if ... if ...if ... if at the beginning of IFC import, that builds many lists and dictionaries. I had done that at the very beginnings of IfcOpenShell. Now, IfcOpenShell has the "reverse" attributes specified in IFC docs implemented too. So we would be able to simplify this block a lot, no more need to build all these tables, you can, from an object get quite easily to its properties, attributes, materials, etc...

Thoughts for later!
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

great! Do you have some example code?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: inverse attributes

Post by yorik »

Not really but if you look for ex. at the bottom of http://www.buildingsmart-tech.org/ifc/I ... fcwall.htm
you can now use all the inverse attributes too. So for ex:

Code: Select all

f = ifcopenshell.open("somefile.ifc")
wall = f[54] # let's say this is a wall
print(wall.OwnerHistory) # this worked before already
print(wall.HasOpenings) # this now works too
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

got the point! :)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

yorik wrote: Wed Mar 06, 2019 5:40 pm Not really but if you look for ex. at the bottom of http://www.buildingsmart-tech.org/ifc/I ... fcwall.htm
you can now use all the inverse attributes too. So for ex:

Code: Select all

f = ifcopenshell.open("somefile.ifc")
wall = f[54] # let's say this is a wall
print(wall.OwnerHistory) # this worked before already
print(wall.HasOpenings) # this now works too
https://standards.buildingsmart.org/IFC ... fcwall.htm


screen.PNG
screen.PNG (98.4 KiB) Viewed 2910 times
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

https://forum.freecadweb.org/viewtopic. ... 22#p321124

Basically at the moment we have many for...in... loops that scan the whole IFC file contents to extract relationships. However, IFC object can inform themselves of their relationships, thanks to inverse attributes. So the idea would be to, for example, for each of the relationships dictionaries created at file opening, find each place where they are used in the code, and replace with the appropriate relationship attribute.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

seams the property sets are not listed in the inverse attributes. Means there is no inverse attribute in ifcslab or ifcwall which gives the property sets of this object. Seams I took a bad example to start with ... :(
User avatar
hlg
Posts: 39
Joined: Fri Jul 12, 2019 10:11 am

Re: inverse attributes

Post by hlg »

bernd wrote: Wed Jul 24, 2019 1:49 pm seams the property sets are not listed in the inverse attributes. Means there is no inverse attribute in ifcslab or ifcwall which gives the property sets of this object. Seams I took a bad example to start with ... :(
Indeed, there is the inverse attribute for property sets. Property Sets are related to Products via IfcRelDefines. So you can access the property sets via IfcProduct.IsDefinedBy.RelatingPropertyDefinition. In IFC2x3 You need a type check before accessing the property definition, because the relation can be of type IfcRelDefinesByProperties or IfcRelDefinesByType. In IFC4 the type check is not necessary anymore, because there is a new inverse IsTypedBy and thus IsDefinedBy is reserved exclusively for property definitions.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

very cool :D

get file gruen_new.ifc from here https://forum.freecadweb.org/viewtopic. ... 60#p280947

Code: Select all

import ifcopenshell
myfile = '/home/hugo/Desktop/gruen_new.ifc'
ifcfile = ifcopenshell.open(myfile)
ifcfile.by_type("IfcColumn")[0].IsDefinedBy[0].RelatingPropertyDefinition
will give

Code: Select all

>>> 
>>> import ifcopenshell
>>> myfile = '/home/hugo/Desktop/gruen_new.ifc'
>>> ifcfile = ifcopenshell.open(myfile)
>>> ifcfile.by_type("IfcColumn")[0].IsDefinedBy[0].RelatingPropertyDefinition
#264=IfcPropertySet('0_dPGJz$zDLuqGzu62$ZMQ',#11,'Allplan Attributes',$,(#255,#256,#257,#258,#260,#261,#262,#263))
>>> 
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: inverse attributes

Post by bernd »

just found something very very cool ... same ifc file

Code: Select all

import ifcopenshell
myfile = '/home/hugo/Desktop/gruen_new.ifc'
ifcfile = ifcopenshell.open(myfile)
print(ifcfile[264] == ifcfile['0_dPGJz$zDLuqGzu62$ZMQ'] == ifcfile.by_id(264))

Code: Select all

>>> 
>>> import ifcopenshell
>>> myfile = '/home/hugo/Desktop/gruen_new.ifc'
>>> ifcfile = ifcopenshell.open(myfile)
>>> print(ifcfile[264] == ifcfile['0_dPGJz$zDLuqGzu62$ZMQ'] == ifcfile.by_id(264))
True
>>> 
AFAIK importIFC only uses ifcfile.by_id(xxx) but ifcfile[xxx] works too
Post Reply