2021-01-05 21:15:52 +11:00
|
|
|
import bpy
|
2021-01-20 16:53:34 +11:00
|
|
|
import logging
|
2021-01-05 21:15:52 +11:00
|
|
|
import ifcopenshell
|
2021-03-27 22:52:52 +11:00
|
|
|
import ifcopenshell.api
|
2021-01-05 21:15:52 +11:00
|
|
|
import bpy
|
|
|
|
|
from blenderbim.bim.ifc import IfcStore
|
|
|
|
|
|
2021-03-25 10:48:31 +11:00
|
|
|
# from ifcopenshell.api.project.data import Data
|
2021-01-05 21:15:52 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CreateProject(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.create_project"
|
|
|
|
|
bl_label = "Create Project"
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
if self.file:
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-03-27 22:52:52 +11:00
|
|
|
IfcStore.file = ifcopenshell.api.run(
|
|
|
|
|
"project.create_file", **{"version": bpy.context.scene.BIMProperties.export_schema}
|
|
|
|
|
)
|
2021-01-05 21:15:52 +11:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
|
2021-01-26 13:56:38 +11:00
|
|
|
bpy.ops.bim.add_person()
|
|
|
|
|
bpy.ops.bim.add_organisation()
|
|
|
|
|
|
2021-01-06 15:19:55 +11:00
|
|
|
project = bpy.data.objects.new("My Project", None)
|
|
|
|
|
site = bpy.data.objects.new("My Site", None)
|
|
|
|
|
building = bpy.data.objects.new("My Building", None)
|
|
|
|
|
building_storey = bpy.data.objects.new("Ground Floor", None)
|
2021-01-05 21:15:52 +11:00
|
|
|
|
2021-01-06 15:19:55 +11:00
|
|
|
bpy.ops.bim.assign_class(obj=project.name, ifc_class="IfcProject")
|
2021-01-05 21:15:52 +11:00
|
|
|
bpy.ops.bim.assign_unit()
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Model")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Model", subcontext="Body", target_view="MODEL_VIEW")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Model", subcontext="Box", target_view="MODEL_VIEW")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Plan")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Plan", subcontext="Annotation", target_view="PLAN_VIEW")
|
2021-01-06 15:19:55 +11:00
|
|
|
|
|
|
|
|
for subcontext in self.file.by_type("IfcGeometricRepresentationSubContext"):
|
|
|
|
|
if subcontext.ContextIdentifier == "Body":
|
|
|
|
|
bpy.context.scene.BIMProperties.contexts = str(subcontext.id())
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
bpy.ops.bim.assign_class(obj=site.name, ifc_class="IfcSite")
|
|
|
|
|
bpy.ops.bim.assign_class(obj=building.name, ifc_class="IfcBuilding")
|
|
|
|
|
bpy.ops.bim.assign_class(obj=building_storey.name, ifc_class="IfcBuildingStorey")
|
|
|
|
|
bpy.ops.bim.assign_object(related_object=site.name, relating_object=project.name)
|
|
|
|
|
bpy.ops.bim.assign_object(related_object=building.name, relating_object=site.name)
|
|
|
|
|
bpy.ops.bim.assign_object(related_object=building_storey.name, relating_object=building.name)
|
2021-01-05 21:15:52 +11:00
|
|
|
# Data.load()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-01-20 16:53:34 +11:00
|
|
|
|
2021-04-11 21:56:45 +10:00
|
|
|
class CreateProjectLibrary(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.create_project_library"
|
|
|
|
|
bl_label = "Create Project Library"
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
if self.file:
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
IfcStore.file = ifcopenshell.api.run(
|
|
|
|
|
"project.create_file", **{"version": bpy.context.scene.BIMProperties.export_schema}
|
|
|
|
|
)
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
|
|
|
|
|
if self.file.schema == "IFC2X3":
|
|
|
|
|
bpy.ops.bim.add_person()
|
|
|
|
|
bpy.ops.bim.add_organisation()
|
|
|
|
|
|
|
|
|
|
project_library = bpy.data.objects.new("My Project Library", None)
|
|
|
|
|
bpy.ops.bim.assign_class(obj=project_library.name, ifc_class="IfcProjectLibrary")
|
|
|
|
|
bpy.ops.bim.assign_unit()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 16:53:34 +11:00
|
|
|
class ValidateIfcFile(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.validate_ifc_file"
|
|
|
|
|
bl_label = "Validate IFC File"
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
import ifcopenshell.validate
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("validate")
|
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
ifcopenshell.validate.validate(IfcStore.get_file(), logger)
|
|
|
|
|
return {"FINISHED"}
|