Skip to content

Commit fbcf139

Browse files
committed
feat: error checking on menu type
1 parent ead5f94 commit fbcf139

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

compositor/operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ def _process_node_tree(self, node_tree: CompositorNodeTree):
185185
self._write(f"{nt_var} = {nt_var}_node_group()\n", self._outer)
186186

187187
def execute(self, context):
188-
self._setup_options(context.scene.ntp_options)
188+
if not self._setup_options(context.scene.ntp_options):
189+
return {'CANCELLED'}
189190

190191
#find node group to replicate
191192
if self.is_scene:

geometry/operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def _apply_modifier(self, nt: GeometryNodeTree, nt_var: str):
171171

172172

173173
def execute(self, context):
174-
self._setup_options(context.scene.ntp_options)
174+
if not self._setup_options(context.scene.ntp_options):
175+
return {'CANCELLED'}
175176

176177
#find node group to replicate
177178
nt = bpy.data.node_groups[self.geo_nodes_group_name]

ntp_operator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _write(self, string: str, indent: str = None):
113113
indent = self._inner
114114
self._file.write(f"{indent}{string}\n")
115115

116-
def _setup_options(self, options: NTPOptions) -> None:
116+
def _setup_options(self, options: NTPOptions) -> bool:
117117
# General
118118
self._mode = options.mode
119119
self._include_group_socket_values = options.include_group_socket_values
@@ -134,7 +134,12 @@ def _setup_options(self, options: NTPOptions) -> None:
134134
self._location = options.location
135135
self._category = options.category
136136
self._custom_category = options.custom_category
137-
self._menu_id = options.menu_id
137+
if options.menu_id in dir(bpy.types):
138+
self._menu_id = options.menu_id
139+
else:
140+
self.report({'ERROR'}, f"{options.menu_id} is not a valid menu")
141+
return False
142+
return True
138143

139144
def _setup_addon_directories(self, context: Context, nt_var: str) -> bool:
140145
"""

shader/operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ def _process_node_tree(self, node_tree: ShaderNodeTree) -> None:
128128

129129

130130
def execute(self, context):
131-
self._setup_options(context.scene.ntp_options)
131+
if not self._setup_options(context.scene.ntp_options):
132+
return {'CANCELLED'}
132133

133134
#find node group to replicate
134135
self._base_node_tree = bpy.data.materials[self.material_name].node_tree

0 commit comments

Comments
 (0)