Skip to content

Commit 2c55da4

Browse files
committed
feat: warns user when attempting to use add-on in an unsaved .blend file
1 parent 7c2b824 commit 2c55da4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

node_to_python.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,17 @@ class NodeToPython(bpy.types.Operator):
141141
node_group_name: bpy.props.StringProperty(name="Node Group")
142142

143143
def execute(self, context):
144+
if self.node_group_name not in bpy.data.node_groups:
145+
return {'FINISHED'}
144146
ng = bpy.data.node_groups[self.node_group_name]
145147
ng_name = ng.name.lower().replace(' ', '_')
146148
class_name = ng.name.replace(" ", "")
147149
dir = bpy.path.abspath("//")
148-
150+
if not dir:
151+
self.report({'ERROR'},
152+
("NodeToPython: Save your blend file before using "
153+
"NodeToPython!"))
154+
return {'CANCELLED'}
149155
file = open(f"{dir}{ng_name}_addon.py", "w")
150156

151157
"""Sets up bl_info and imports Blender"""

0 commit comments

Comments
 (0)