If you're reading this, we've just migrated servers! If anything looks broken please email dion@thinkmoult.com :)
Ifcopenshell-Python beginner
I am a beginner and want to know related quick getting started articles about Ifcopenshell-Python, thx
Tagged:
Comments
Hey @shanmama - did you see some of the links and source code posted here?
Is there a particular type of data you are trying to extract? Is it geometry? Is it an attribute? Is it a property set? If you're interested, in an online meeting I can do a screenshare and teach a bit about IfcOpenShell-python. Would you participate?
Dear all,
Please Help....
I am a beginner in using python, IFC and BlenderBim add on. I am trying to do the following;
1. extract the quantities, material type of walls and floors and place them into a dictionary
2. extract the quantities of external walls and group them based on their cardinal orientation (south, north, west, etc) of each wall. I do not know if it's workable.
For the quantities I tried the sample code on https://thinkmoult.com/using-ifcopenshell-parse-ifc-files-python.html but I get an attribute error (as shown below). I just hope I am doing the right thing.
@polsonmila at first glance it looks as if you're getting an AttributeError because you're attempting to access quantity.lengthValue instead of quantity.LengthValue -- > the properties all use CamelCase
Also, you need to loop through each Wall in your Walls list before you try to access .isDefinedBy.
something like:
@vpajic Thank you for the response. I will try to do that and give you an update.
BTW: if you post code do not use a screen shot but copy the code and use code tags instead. It looks like in the post of vpajic. If you post a screen shot noone can copy and test your code.
cheers bernd
am grateful for the help
After reading through the https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples
I was able to at least use the sample code to extract the wall pset as dictionary.
NOTE: I am trying to extract the quantities of Walls and Slabs and place them in a dataframe.
I want these to have their GUID.
I would also like to group all the Walls external walls based on their Cardinal points (south, north, etc)
once again thank you for your anticipated responses.
NOTE: I am trying to extract the quantities of Walls and Slabs and place them in a dataframe.
I want these to have their GUID.
I would also like to group all the Walls external walls based on their Cardinal points (south, north, etc)
once again thank you for your anticipated responses.
@vpajic Thank you. I am relatively new to both Python and IfcOpenshell. I am now exploring my way through (as I go through the Wiki.osarch.org tutorials. I was able use the get_info and loop through (as shown below). But I as you suggested, I also observed that I could loop through the wall list from the wall.by_type function call. I will work on it so that I can try accessing the IsDefinedBy.
Well this is how far I have gone.
@vpajic Thank you for your comment I still need help...
@Moult and @bernd kindly assist.
I am relatively new to both Python and IfcOpenshell. I am now exploring my way through (as I go through the Wiki.osarch.org tutorials. I was able use the get_info and loop through (as shown below). But I as @vpajic suggested, I also observed that I could loop through the wall list from the wall.by_type function call. I will work on it so that I can try accessing the IsDefinedBy.
Well, this is how far I have gone.
I have been able to have the loop through to get the property set of one wall using the IsDefinedBy procedure. But I could not access the Quantities. Please, can someone help me to identify where I am getting things wrong?
@polsonmila - i would heartily recommend having a look at . Using the console in blender will allow you to explore the commands and structure of ifcopenshell more intuitively.
In your last example, it seems to me you are trying to access
property.is_a('IfcElementQuantity'):
without having first defined 'property'@polsonmila
How has progress been? :-)
@Coen thank you for your follow-up question. I followed the YouTube video tutorial specified by @vpajic it has been helpful. Though, I will still need help.
@polsonmila have you considered using the util module? To get properties and quantities you can just do it in one line of code:
I want to extract the data from the IFC 2x3 format and place them in a data frame.
1. I used the util.get_psets() function to get the property sets of all the walls in a particular building but I could not loop through the walls and place them into a data frame. I could only do that for one wall (as shown in the code below).
2. I want to extract the external walls within an IFC 2x3 specifying the cardinal orientation of the external faces of the walls with respect to the Project North (e.g. North-west, North-south, North). If you have any idea on how to extract these details, I will be grateful.
Code for question 1
`#The IFC 2x3 model
model_name = 'Duplex_A.ifc'
model = ifcopenshell.open(model_name)
The walls by_type
walls = model.by_type('IfcWall')
count = 0
Iterating through the walls
for wall in walls:
wall_sets_dict = {}
#count += 1
The util.get_psets function
`
Question 2
????
NOTE: I added a note pad for further details and the IFC 2x3 file.
I've never seen a dataframe before, what's the structure you need in the end? Is is a dictionary? List? What should it look like?
@Moult please pardon my miscommunication (I am a beginner). I meant a pandas data frame. I was able to use the util.get_psets for only one wall and derived a multi-index data frame (as shown in the code below)
Looks like you're overwriting your dictionary for each wall, maybe you want to create a list of dictionaries and flatten it at the end ? or a dict of dicts with the guid as a key ?
@Gorgious I will try your suggestion. Though I tried making a list and or dict of dict (but I got error!)....may be due to beginner level in python & ifcopenshell. I think flattening might change its default structure from the util.get_pset function output.
@polsonmila if you manually type out a list / dict with sample data of the structure you're after for your data frame, perhaps we can help :)
@Moult and @Gorgious I have been able to create a list of dictionaries (nested dictionaries) from the util.get_pset(). But I still get a runtime error if I iterate through the list.
`
I have the following as a list of nested dictionaries. I want to loop through it and create a multi index data frame. But I always get a runtime error.
Here is the sample list of nested dictionaies and the code I used.
`
Here is the code I used to iterate only the first index item into a dataframe. But I could not iterate for all.
I quickly skimmed through the Pandas documentation and perhaps
pd.DataFrame.from_records(sample_list_of_nestdict)
might be what you're after.Thank you all. @Moult , @Gorgious, @vpajic and @Coen. I have been able to solve the problem. I extracted the wall property set and I am working on them in pandas.
I am still trying to extract external walls coordinates in relation to the project north. If you have any suggestion, I will appreciate it.
Thanks.