OSArch Community

Write Pset and Qset via python code

  1. V

    Hi everyone,

    I'm trying to write custom pset and qto set via python code. For now I've tried to follow this instruction https://wiki.osarch.org/index.php?title=BlenderBIM_Add-on/BlenderBIM_Add-on_code_examples but it doesn't work and I don't know why. Would someone be able to help me with this issue? I really appreciate any help you can provide.

    Below there is the code I texted:

    ====================================================

    import bpy

    import numpy as np

    import os

    import ifcopenshell

    from ifcopenshell.api import run

    import ifcopenshell.api.owner.settings

    =====================================================

    Create BIM project

    createProject = True

    if createProject:

    bpy.ops.bim.create_project()
    
    bpy.context.scene.BIMProjectProperties.author_name = "Valerio Gianforte"
    
    bpy.context.scene.BIMProjectProperties.organisation_name = "LIam"

    Create Object

    addCube = True

    if addCube:

    cube = bpy.ops.mesh.primitive_cube_add()
    
    bpy.context.scene.BIMProjectProperties.ifc_product = "IfcElement"
    
    bpy.context.scene.BIMProjectProperties.ifc_class = "IfcCivilElement"
    
    bpy.ops.bim.assign_class(ifc_class = "IfcCivilElement", 
    
                            predefined_type = "IfcCivilElementType", 
    
                            userdefined_type = "")
    
    bpy.data.objects["IfcCivilElement/Cube"].BIMTypeProperties.relating_type_class = "IfcCivilElementType"
    
    pset = bpy.context.active_object.BIMObjectProperties.psets.add()
    
    pset.name = "Pset_PackingInstruction"
    
    prop = pset.properties.add()
    
    prop.name = "AC_Pset_RenovationAndPhasing"
    
    prop.string_value = "Costo della struttura"    

    I'd like to obtain a situation like the following image:

  2. M
  3. V

    Hi @Massimo thank you for the tip but I think that API doesn't work for my aims because if I don't understand badly, the API is applied to parse IFC file. In this case, I have not an IFC file but I would like to give my object custom properties as shown in the image above via Python. Another question could be if it is possible to import via Python a pset template written as a CSV file.

  4. M
  5. M

    @valgianf well, you can use API for many things, also for create a new model for example (look at https://blenderbim.org/docs-python/ifcopenshell-python/code_examples.html#create-a-simple-model-from-scratch).

    For your aims i think you can use this

    https://blenderbim.org/docs-python/autoapi/ifcopenshell/api/pset/add_pset/index.html

    The API works directly to the ifc file (simple speaking) instead of work thought the blender application (sorry for maybe not precise technical language ...)

    For your second question the answer is yes but you need to "work a little" :-) ... you can look at this video btw

    It is not explained directly how to do your job, but you could first export the pset, modify the .csv file and then reimport ...

  6. V

    Very well, thank you so much for your support. Cheers!

Login or Register to reply.