inverse attributes

This forum section is only for IFC-related issues
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

inverse attributes

Postby yorik » Fri Mar 01, 2019 1:29 am

...

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
Posts: 8244
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: inverse attributes

Postby bernd » Sun Mar 03, 2019 8:43 pm

great! Do you have some example code?
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: inverse attributes

Postby yorik » 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
User avatar
bernd
Posts: 8244
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: inverse attributes

Postby bernd » Thu Mar 07, 2019 7:47 pm

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

Re: inverse attributes

Postby bernd » Mon Jul 15, 2019 3:16 pm

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 401 times
User avatar
bernd
Posts: 8244
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: inverse attributes

Postby bernd » Sun Jul 21, 2019 10:10 pm

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
Posts: 8244
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: inverse attributes

Postby bernd » 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 ... :(
hlg
Posts: 8
Joined: Fri Jul 12, 2019 10:11 am

Re: inverse attributes

Postby hlg » Wed Jul 24, 2019 4:44 pm

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
Posts: 8244
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: inverse attributes

Postby bernd » Sat Jul 27, 2019 7:50 pm

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
Posts: 8244
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: inverse attributes

Postby bernd » Sat Jul 27, 2019 8:03 pm

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