support sun position addon on blender 4.2

This commit is contained in:
Andrej730
2024-07-17 15:21:06 +05:00
parent 7c606fea9b
commit 6fbb1a286c
4 changed files with 34 additions and 17 deletions
@@ -21,12 +21,6 @@ import blf
import gpu
import bmesh
import blenderbim.tool as tool
try:
import sun_position.sun_calc
except ImportError:
sun_position = None
from bpy.types import SpaceView3D
from math import radians
from mathutils import Vector, Matrix
@@ -34,6 +28,8 @@ from gpu_extras.batch import batch_for_shader
from bpy_extras.view3d_utils import location_3d_to_region_2d
from blenderbim.bim.module.light.data import SolarData
sun_position = tool.Blender.get_sun_position_addon()
class SolarDecorator:
is_installed = False
@@ -20,12 +20,6 @@ import bpy
import pytz
import tzfpy
import datetime
try:
import sun_position.sun_calc
except ImportError:
sun_position = None
import blenderbim.tool as tool
from math import radians, pi
from mathutils import Euler, Vector, Matrix, Quaternion
@@ -34,6 +28,8 @@ from bpy.types import PropertyGroup
from blenderbim.bim.module.light.data import SolarData
from blenderbim.bim.module.light.decorator import SolarDecorator
sun_position = tool.Blender.get_sun_position_addon()
def get_sites(self, context):
if not SolarData.is_loaded:
@@ -17,13 +17,11 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.tool as tool
from blenderbim.bim.module.light.data import SolarData
try:
import sun_position
from sun_position.sun_calc import format_time, format_hms, sun
except ImportError:
sun_position = None
sun_position = tool.Blender.get_sun_position_addon()
class BIM_PT_radiance_exporter(bpy.types.Panel):
+27
View File
@@ -27,6 +27,7 @@ import blenderbim.core.tool
import blenderbim.tool as tool
import blenderbim.bim
import addon_utils
import types
from mathutils import Vector
from pathlib import Path
from blenderbim.bim.ifc import IFC_CONNECTED_TYPE
@@ -1116,3 +1117,29 @@ class Blender(blenderbim.core.tool.Blender):
def get_addon_preferences(cls) -> blenderbim.bim.ui.BIM_ADDON_preferences:
blender_package_name = cls.get_blender_addon_package_name()
return bpy.context.preferences.addons[blender_package_name].preferences
@classmethod
def get_sun_position_addon(cls) -> Union[types.ModuleType, None]:
# Check if it's installed as legacy Blender addon.
try:
import sun_position
except ImportError:
sun_position = None
if sun_position:
return
# No extensions prior to 4.2.
if bpy.app.version < (4, 2, 0):
return sun_position
if sun_position:
return sun_position
import importlib
for package_name in bpy.context.preferences.addons.keys():
if package_name.endswith(".sun_position"):
sun_position = importlib.import_module(package_name)
return sun_position