Skip pyradiance import if it fails #6633

This commit is contained in:
Andrej730
2025-07-09 14:20:54 +05:00
parent 6ea7ee84a6
commit 41e64781d8
3 changed files with 35 additions and 8 deletions
+23 -7
View File
@@ -24,7 +24,21 @@ from pathlib import Path
import importlib import importlib
import importlib.util import importlib.util
import pyradiance import traceback
# There are unresolved problems with pyradiance import that we couldn't narrow down.
# So import is optional not to make it a showstopper for random users,
# who don't even need pyradiance.
# See #6633.
try:
import pyradiance
except ImportError as e:
print(traceback.format_exc())
print(
"PyRadiance is not available. Pyradiance Rendering functionality will be disabled. "
"See above for more detailed import traceback."
)
pyradiance = None
def get_pyradiance_path(): def get_pyradiance_path():
@@ -58,12 +72,14 @@ classes = (
def register(): def register():
bpy.types.Scene.BIMRadianceExporeterProperies = bpy.props.PointerProperty(type=prop.RadianceExporterProperties) bpy.types.Scene.BIMRadianceExporeterProperies = bpy.props.PointerProperty(type=prop.RadianceExporterProperties)
bpy.types.Scene.BIMSolarProperties = bpy.props.PointerProperty(type=prop.BIMSolarProperties) bpy.types.Scene.BIMSolarProperties = bpy.props.PointerProperty(type=prop.BIMSolarProperties)
pyradiance_path = Path(get_pyradiance_path())
bin_path = pyradiance_path / "bin" if pyradiance:
if bin_path.exists(): pyradiance_path = Path(get_pyradiance_path())
for file in bin_path.iterdir(): bin_path = pyradiance_path / "bin"
if file.is_file(): if bin_path.exists():
file.chmod(file.stat().st_mode | stat.S_IEXEC) for file in bin_path.iterdir():
if file.is_file():
file.chmod(file.stat().st_mode | stat.S_IEXEC)
def unregister(): def unregister():
@@ -21,7 +21,6 @@ import os
try: try:
import pyradiance as pr import pyradiance as pr
except ImportError: except ImportError:
print("PyRadiance is not available. Rendering functionality will be disabled.")
pr = None pr = None
from datetime import datetime from datetime import datetime
+12
View File
@@ -21,6 +21,11 @@ import bonsai.tool as tool
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from bonsai.bim.module.light.data import SolarData from bonsai.bim.module.light.data import SolarData
try:
import pyradiance
except ImportError:
pyradiance = None
class BIM_PT_radiance_exporter(bpy.types.Panel): class BIM_PT_radiance_exporter(bpy.types.Panel):
"""Creates a Panel in the render properties window""" """Creates a Panel in the render properties window"""
@@ -38,6 +43,13 @@ class BIM_PT_radiance_exporter(bpy.types.Panel):
layout = self.layout layout = self.layout
props = tool.Blender.get_radiance_exporter_props() props = tool.Blender.get_radiance_exporter_props()
if pyradiance is None:
box = layout.box()
box.label(text="There was a problem importing Pyradiance", icon="ERROR")
box.label(text="and it's functionality is not available.")
box.label(text="See system console logs at Bonsai startup.")
return
if tool.Ifc.get(): if tool.Ifc.get():
row = self.layout.row() row = self.layout.row()
row.prop(props, "should_load_from_memory") row.prop(props, "should_load_from_memory")