ifcopenshell scripting on IFC file loaded in BlenderBIM

I just started exploring BlenderBIM and I was looking if I could directly access the IFC project loaded in Blender through BlenderBIM, to be able to combine the UI from BlenderBIM and scripting whenever needed.
In particular, I want to assign ifc class to 3d objects already loaded in blender through scripting instead of UI. The UI looks like this:

Comments

  • Sure, pull up a Python console or text editor, then you can get the active session's model by doing:

    import blenderbim.tool as tool
    model = tool.Ifc.get()
    
    steverugi
  • @Moult said:
    Sure, pull up a Python console or text editor, then you can get the active session's model by doing:

    import blenderbim.tool as tool
    model = tool.Ifc.get()
    

    When you say model, you mean the IFC project that i created ? This one for instance :
    Also, now that I got the model (or project), let's say that I have a terrain mesh in my .blend project to which I want to assign the class "IfcGeographicElement" and put it into my ifc project, how do I proceed? I saw that the blenderbim.tool module contains a lot of useful classes and methods, but I'm at loss at how to use them.

  • asaik IFCProject is a space class instance, not the IFC model
    when you read ifcopenshell 'model' is the one you use in the APIs

    import ifcopenshell
    # model = ifcopenshell.open("/path/to/model.ifc") one way to assign the IFC to the variable model
    import blenderbim.tool as tool
    model = tool.Ifc.get() # what indicated above
    walls = model.by_type("IfcWall") # a method to select all IfcWall class elements into one variable
    

    etc..
    the same 'model' (at times 'file' in the example), is the one used in most of the API
    sorry I am not too much of an expert, I only use the cost APIs from time to time, hope it helps

    aogino
  • @steverugi said:
    asaik IFCProject is a space class instance, not the IFC model
    when you read ifcopenshell 'model' is the one you use in the APIs

    import ifcopenshell
    # model = ifcopenshell.open("/path/to/model.ifc") one way to assign the IFC to the variable model
    import blenderbim.tool as tool
    model = tool.Ifc.get() # what indicated above
    walls = model.by_type("IfcWall") # a method to select all IfcWall class elements into one variable
    

    etc..
    the same 'model' (at times 'file' in the example), is the one used in most of the API
    sorry I am not too much of an expert, I only use the cost APIs from time to time, hope it helps

    yes, I understand!
    I found a very interesting comment of @Moult in this thread https://community.osarch.org/discussion/2201/documentation-on-blenderbim-python-library#latest and I'm trying to work accordingly. I used blenderbim.tool to get the model then ifcopenshell calls for model processing. However I'm finding it hard to pinpoint the methods and classes I need. Is there a solid documentation of the ifcopenshell python API ?

  • https://docs.ifcopenshell.org/ifcopenshell-python.html includes code examples and a short tutorial. https://docs.ifcopenshell.org/autoapi/ifcopenshell/index.html contains extensive documentation. Also see the API and util submodule.

    aoginosteverugi
Sign In or Register to comment.