import numpy as np import os import math import bpy import random import math # ==================================================== createBIMproject = True if createBIMproject: bpy.ops.bim.create_project() # It creates BIM project bpy.context.scene.BIMProjectProperties.author_name = "Valerio Gianforte" # It doesn't text anything on IFC Project bpy.context.scene.BIMProjectProperties.organisation_name = "LIam" # It doesn't text anything IFC Project bpy.context.scene.BIMProjectProperties.author_email = "valerio.gianforte@graduate.univaq.it" # It doesn't text anything IFC Project # ========================================= filePathSTL = r"D:\DOTTORATO\0000_WORK\0010_BLENDER_BIM\0000_WORK\2024_02_06\STL" nameSTL = "Accropode.STL" # ========================================= Dn = 4. accropode_mesh = bpy.ops.import_mesh.stl( filepath=filePathSTL, filter_glob="*.stl", files=[{"name":nameSTL}], directory=filePathSTL) bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN') bpy.context.active_object.dimensions = (Dn,Dn,Dn) bpy.ops.object.select_all(action='DESELECT') # Deselects all objects on the scene bpy.ops.object.select_all(action='DESELECT') # Deselects all objects on the scene accropode = bpy.data.objects['Accropode'] # Create for accropode accropode.select_set(True) # Selects only the accropode accropode.name = "AccropodeFinal" bpy.context.view_layer.objects.active = accropode bpy.ops.transform.translate(value=(0, 0, 10), #orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, True), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False) xC = 10.0 Lc = 26.0 xCsup = xC + Lc yC = 15.00 yCsup = 4.5 z = 0.0 z2 = 1.0 zCsup = 8.30 verts = [(-xC, -yC, z), (-xC, yC, z), (xCsup, -yC, z), (xCsup, yC, z), (-xC, -yCsup, zCsup), (-xC, yCsup, zCsup), (xCsup, -yCsup, zCsup), (xCsup, yCsup, zCsup)] faces = [[0, 2, 3, 1], [4, 6, 7, 5], [1, 5, 7, 3], [0, 4, 6, 2], [2, 6, 7, 3], [0, 4, 5, 1]] mesh = bpy.data.meshes.new(name="New Mesh") mesh.from_pydata(verts, [], faces) const = bpy.data.objects.new('Const', mesh) scene = bpy.context.scene scene.collection.objects.link(const) # BIM properties Accropode # bpy.context.view_layer.objects.active = accropode bpy.context.scene.BIMRootProperties.ifc_product = "IfcElement" bpy.context.scene.BIMRootProperties.ifc_class = "IfcCivilElement" bpy.ops.bim.assign_class(ifc_class = "IfcCivilElement", predefined_type = "IfcCivilElementType", userdefined_type = "") accropode.select_set(False) bpy.context.view_layer.objects.active = accropode # PSET ELEMENT STATUS statusAC = bpy.context.scene.AddEditProperties.add() statusAC.pset_name = "Pset_InstallationPhasing" statusAC.property_name = "Status" statusAC.string_value = "NEW" statusAC.primary_measure_type = 'IfcGloballyUniqueId' statusAC.template_type = 'IfcPropertySingleValue' bpy.ops.bim.add_edit_custom_property() bpy.ops.bim.disable_pset_editing(obj="IfcCivilElement/AccropodeFinal", obj_type="Object") # PSET INSTALLATION PHASING phasing = bpy.context.scene.AddEditProperties.add() phasing.pset_name = "Pset_InstallationPhasing" phasing.property_name = "Work description" phasing.string_value = "Accropodes installation" phasing.primary_measure_type = 'IfcGloballyUniqueId' phasing.template_type = 'IfcPropertySingleValue' bpy.ops.bim.add_edit_custom_property() bpy.ops.bim.disable_pset_editing(obj="IfcCivilElement/AccropodeFinal", obj_type="Object") # BIM properties Core # bpy.context.view_layer.objects.active = const bpy.context.scene.BIMRootProperties.ifc_product = "IfcElement" bpy.context.scene.BIMRootProperties.ifc_class = "IfcCivilElement" bpy.ops.bim.assign_class(ifc_class = "IfcCivilElement", predefined_type = "IfcCivilElementType", userdefined_type = "") const.select_set(False) bpy.context.view_layer.objects.active = const # PSET ELEMENT STATUS statusConst = bpy.context.scene.AddEditProperties.add() statusConst.pset_name = "Pset_InstallationPhasing" statusConst.property_name = "Status" statusConst.string_value = "NEW" statusConst.primary_measure_type = 'IfcGloballyUniqueId' statusConst.template_type = 'IfcPropertySingleValue' bpy.ops.bim.add_edit_custom_property() bpy.ops.bim.disable_pset_editing(obj="IfcCivilElement/Const", obj_type="Object") # PSET INSTALLATION PHASING phasingConst = bpy.context.scene.AddEditProperties.add() phasingConst.pset_name = "Pset_InstallationPhasing" phasingConst.property_name = "Work description" phasingConst.string_value = "Accropodes installation" phasingConst.primary_measure_type = 'IfcGloballyUniqueId' phasingConst.template_type = 'IfcPropertySingleValue' bpy.ops.bim.add_edit_custom_property() bpy.ops.bim.disable_pset_editing(obj="IfcCivilElement/Const", obj_type="Object") saveIFC = True pathIFC = "D:\\DOTTORATO\\0000_WORK\\0010_BLENDER_BIM\\0000_WORK\\2024_02_06\\IFC\\accropode_4D.ifc" if saveIFC: bpy.ops.export_ifc.bim(filepath = pathIFC, should_save_as = False, save_as_invoked = True)