ifcsverchok: recognize sverchok-master installs and fix stale unassign API calls

Sverchok's addon-name check relied on it already having aliased itself into
sys.modules["sverchok"], which only happens once Sverchok's own registration
code has run. Depending on addon enable order, that alias may not exist yet
when IfcSverchok checks for it, so a GitHub zip install (folder name
"sverchok-master") was reported as not installed even though it was. Now we
also search bpy.context.preferences.addons for a "sverchok-*" module name.

Separately, the bundled example's IFC Add Spatial Element node called
aggregate.unassign_object() and spatial.unassign_container() with a
relating_object kwarg that no longer exists in their current signatures
(both now take only file/products), causing "unexpected keyword argument"
errors when re-running the node graph after removing an element from a
spatial element. The other API calls in ifcsverchok were audited and are
already current.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Petru Conduraru
2026-07-21 13:07:07 +03:00
parent e52e5e2e58
commit 6ec59ccf2f
2 changed files with 17 additions and 6 deletions
+17 -4
View File
@@ -30,6 +30,7 @@ bl_info = {
import importlib
import logging
import sys
import types
import bpy
@@ -40,11 +41,23 @@ logger = logging.getLogger("sverchok.ifc")
def get_blender_addon_package_by_name(addon_name: str) -> types.ModuleType:
# Check for legacy addons.
# Make an exception for sverchok as it keeps getting installed by all kind of names
# and then hacks `sverchok` into `sys.modules`.
if addon_name in bpy.context.preferences.addons or addon_name == "sverchok":
if addon_name in bpy.context.preferences.addons:
return importlib.import_module(addon_name)
elif bpy.app.version < (4, 2, 0):
# Make an exception for sverchok as it keeps getting installed by all kind of names,
# e.g. a GitHub zip download installs as "sverchok-master". Look for any enabled
# addon whose module name is a variant of it, rather than assuming it has already
# hacked itself into `sys.modules["sverchok"]`, since that only happens once
# Sverchok's own registration code has actually run (which depends on addon enable
# order and may not have happened yet).
if addon_name == "sverchok":
for package_name in bpy.context.preferences.addons.keys():
if package_name.startswith(("sverchok-", "sverchok_")):
return importlib.import_module(package_name)
if "sverchok" in sys.modules:
return sys.modules["sverchok"]
if bpy.app.version < (4, 2, 0):
raise ModuleNotFoundError
# Check for Blender extensions.
@@ -169,13 +169,11 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
ifcopenshell.api.aggregate.unassign_object(
self.file,
products=[removed_element],
relating_object=result,
)
else:
ifcopenshell.api.spatial.unassign_container(
self.file,
products=[removed_element],
relating_object=result,
)
for added_element in element_set - subelements:
if added_element.is_a("IfcSpatialElement") or added_element.is_a("IfcSpatialStructureElement"):