Skip to content

Commit

Permalink
Handle errors during fixture adding more gracefully:
Browse files Browse the repository at this point in the history
    - do not add the fixture to the fixture list
    - remove bad collection
    - show error message
  • Loading branch information
vanous committed Dec 17, 2023
1 parent e2be146 commit da6bb22
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
13 changes: 11 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from dmx.osc_utils import DMX_OSC_Templates
from dmx.osc import DMX_OSC

from dmx.util import rgb_to_cmy, xyY2rgbaa
from dmx.util import rgb_to_cmy, xyY2rgbaa, ShowMessageBox
from dmx.mvr_objects import DMX_MVR_Object

from bpy.props import (BoolProperty,
Expand Down Expand Up @@ -945,7 +945,16 @@ def addFixture(self, name, profile, universe, address, mode, gel_color, display_
dmx = bpy.context.scene.dmx
new_fixture = dmx.fixtures.add()
new_fixture.uuid = str(py_uuid.uuid4()) # ensure clean uuid
new_fixture.build(name, profile, mode, universe, address, gel_color, display_beams, add_target, position, focus_point, uuid, fixture_id, custom_id, fixture_id_numeric, unit_number)
try:
new_fixture.build(name, profile, mode, universe, address, gel_color, display_beams, add_target, position, focus_point, uuid, fixture_id, custom_id, fixture_id_numeric, unit_number)
except Exception as e:
print("Error while adding fixture", e)
dmx.fixtures.remove(len(dmx.fixtures)-1)
ShowMessageBox(
f"{e}",
"Error while adding a fixture, see console for more details",
"ERROR",
)
bpy.app.handlers.depsgraph_update_post.append(onDepsgraph)

def removeFixture(self, fixture):
Expand Down
7 changes: 5 additions & 2 deletions fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,13 @@ def select(self):
if obj.get("2d_symbol", None):
continue
obj.hide_set(False)
self.objects["Root"].object.select_set(True)

if "Root" in self.objects:
self.objects["Root"].object.select_set(True)

else:
self.objects["Root"].object.select_set(True)
if "Root" in self.objects:
self.objects["Root"].object.select_set(True)

DMX_OSC_Handlers.fixture_selection(self)
dmx.updatePreviewVolume()
Expand Down
21 changes: 13 additions & 8 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
# http://www.github.com/open-stage/BlenderDMX
#

import os.path
import bpy

from dmx.material import getEmitterMaterial
from dmx.gdtf import DMX_GDTF

class DMX_Model():

class DMX_Model:
# Return the fixture model collection by profile
# If not imported, build the collection from the GDTF profile
# This collection is then deep-copied by the Fixture class
# to create a fixture collection.
@staticmethod
def getFixtureModelCollection(profile, dmx_mode, display_beams, add_target):
collections = bpy.data.collections

# Make sure the profile was passed as an argument, otherwise return None
if (profile == None):
if profile == None:
return None

name = DMX_GDTF.getName(profile, dmx_mode, display_beams, add_target)

# If the fixture collection was already imported for this model
# just return it
if (name in bpy.data.collections):
return bpy.data.collections[name]
if name in collections:
return collections[name]

# Otherwise, build it from profile
return DMX_GDTF.buildCollection(profile, dmx_mode, display_beams, add_target)
try:
new_collection = DMX_GDTF.buildCollection(profile, dmx_mode, display_beams, add_target)
except Exception as e:
print("Error", e)
if name in collections:
collections.remove(collections[name])
return None
return new_collection
2 changes: 1 addition & 1 deletion pygdtf/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_geometry_by_name(gdtf_profile: "pygdtf.FixtureType" = None, geometry_nam
"""Recursively find a geometry of a given name"""

def iterate_geometries(collector):
if collector.name == geometry_name:
if type(collector) is not pygdtf.FixtureType and collector.name == geometry_name:
matched.append(collector)
for g in collector.geometries:
if g.name == geometry_name:
Expand Down
6 changes: 6 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ def xyY2rgba(xyz):
green = (rgb[1] - lowest) / alpha
blue = (rgb[2] - lowest) / alpha
return (int(red), int(green), int(blue), int(alpha * 100))

def ShowMessageBox(message="", title="Message Box", icon="INFO"):
def draw(self, context):
self.layout.label(text=message)

bpy.context.window_manager.popup_menu(draw, title=title, icon=icon)

0 comments on commit da6bb22

Please sign in to comment.