Simple prototype integration to run an OpenLCA analysis from Blender

This commit is contained in:
Dion Moult
2021-08-23 16:34:19 +10:00
parent 869d067c94
commit d27d0acbc0
8 changed files with 192 additions and 3 deletions
+7
View File
@@ -402,6 +402,13 @@ endif
cp -r dist/working/IFC2JSON_python-master/file_converters/ifcjson dist/blenderbim/libs/site/packages/
rm -rf dist/working
# Provides OpenLCA fucntionality
mkdir dist/working
cd dist/working && wget https://files.pythonhosted.org/packages/85/33/f91b96e9e8608ff65a003b692e8a9cdd60f2178f60617e5b1d21334c009c/olca-ipc-0.0.10.tar.gz
cd dist/working && tar -xzvf olca-ipc*
cd dist/working/olca-ipc-0.0.10/ && cp -r olca ../../blenderbim/libs/site/packages/
rm -rf dist/working
cd dist/blenderbim && sed -i "s/999999/$(VERSION)/" __init__.py
cd dist && zip -r blenderbim-$(VERSION)-$(PYVERSION)-$(PLATFORM).zip ./*
rm -rf dist/blenderbim
@@ -63,6 +63,7 @@ if bpy is not None:
"document": None,
"pset_template": None,
"clash": None,
"lca": None,
"csv": None,
"bimtester": None,
"diff": None,
@@ -0,0 +1,34 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
from . import ui, prop, operator
classes = (
operator.CalculateLCA,
prop.BIMLCAProperties,
ui.BIM_PT_lca,
)
def register():
bpy.types.Scene.BIMLCAProperties = bpy.props.PointerProperty(type=prop.BIMLCAProperties)
def unregister():
del bpy.types.Scene.BIMLCAProperties
@@ -0,0 +1,45 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import olca
import ifcopenshell
class CalculateLCA(bpy.types.Operator):
bl_idname = "bim.calculate_lca"
bl_label = "Calculate LCA"
bl_options = {"REGISTER", "UNDO"}
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filter_glob: bpy.props.StringProperty(default="*.xlsx", options={"HIDDEN"})
def execute(self, context):
props = context.scene.BIMLCAProperties
client = olca.Client(context.preferences.addons["blenderbim"].preferences.openlca_port)
setup = olca.CalculationSetup()
setup.calculation_type = olca.CalculationType.SIMPLE_CALCULATION
setup.impact_method = client.find(olca.ImpactMethod, "CML-IA baseline")
setup.product_system = client.find(olca.ProductSystem, props.product_systems)
setup.amount = props.amount
result = client.calculate(setup)
client.excel_export(result, self.filepath)
return {"FINISHED"}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
@@ -0,0 +1,58 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import olca
from blenderbim.bim.prop import StrProperty, Attribute
from bpy.types import PropertyGroup
from bpy.props import (
PointerProperty,
StringProperty,
EnumProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
CollectionProperty,
)
productsystems_enum = []
def purge():
global productsystems_enum
productsystems_enum = []
def get_product_systems(self, context):
global productsystems_enum
if not len(productsystems_enum):
client = olca.Client(context.preferences.addons["blenderbim"].preferences.openlca_port)
try:
productsystems_enum = [
(ps.name, ps.name, "") for ps in client.get_all(olca.ProductSystem)
]
except:
pass
return productsystems_enum
class BIMLCAProperties(PropertyGroup):
amount: FloatProperty(name="Amount")
product_systems: EnumProperty(items=get_product_systems, name="Product Systems")
@@ -0,0 +1,38 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.types import Panel
class BIM_PT_lca(Panel):
bl_label = "BIM Life Cycle Assessment"
bl_idname = "BIM_PT_lca"
bl_options = {"DEFAULT_CLOSED"}
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "scene"
def draw(self, context):
props = context.scene.BIMLCAProperties
row = self.layout.row()
row.prop(props, "product_systems", text="")
row = self.layout.row()
row.prop(props, "amount", text="")
row = self.layout.row()
row.operator("bim.calculate_lca")
@@ -213,10 +213,11 @@ class ChangeLibraryElement(bpy.types.Operator):
[ifc_classes.add(e.is_a()) for e in elements]
self.props.library_elements.clear()
if len(ifc_classes) == 1 and list(ifc_classes)[0] == self.element_name:
for name, element in sorted([(self.get_name(e), e) for e in elements]):
for name, ifc_definition_id in sorted([(self.get_name(e), e.id()) for e in elements]):
new = self.props.library_elements.add()
new.name = name
new.ifc_definition_id = element.id()
new.ifc_definition_id = ifc_definition_id
element = IfcStore.library_file.by_id(ifc_definition_id)
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
new.is_declared = False
elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a(
+6 -1
View File
@@ -21,7 +21,7 @@ import os
import bpy
from . import ifc
from bpy.types import Panel
from bpy.props import StringProperty, BoolProperty
from bpy.props import StringProperty, IntProperty, BoolProperty
class BIM_PT_section_plane(Panel):
@@ -73,6 +73,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
)
svg_command: StringProperty(name="SVG Command", description="E.g. [['firefox-bin', path]]")
pdf_command: StringProperty(name="PDF Command", description="E.g. [['firefox-bin', path]]")
openlca_port: IntProperty(name="OpenLCA IPC Port", default=8080)
should_hide_empty_props: BoolProperty(name="Should Hide Empty Properties", default=True)
should_play_chaching_sound: BoolProperty(
name="Should Make A Cha-Ching Sound When Project Costs Updates", default=False
@@ -105,7 +106,11 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
row = layout.row()
row.prop(self, "pdf_command")
row = layout.row()
row.prop(self, "openlca_port")
row = layout.row()
row.prop(self, "should_hide_empty_props")
row = layout.row()
row.prop(self, "should_play_chaching_sound")
def ifc_units(self, context):