Skip to content

Commit ead5f94

Browse files
committed
feat: more bl_info fields, option for menu location
1 parent e560f4f commit ead5f94

File tree

2 files changed

+103
-19
lines changed

2 files changed

+103
-19
lines changed

ntp_operator.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ def __init__(self):
6767
# File (TextIO) or string (StringIO) the add-on/script is generated into
6868
self._file: TextIO = None
6969

70-
# Path to the current directory
71-
self._dir: str = None
72-
7370
# Path to the directory of the zip file
7471
self._zip_dir: str = None
7572

@@ -117,14 +114,27 @@ def _write(self, string: str, indent: str = None):
117114
self._file.write(f"{indent}{string}\n")
118115

119116
def _setup_options(self, options: NTPOptions) -> None:
117+
# General
120118
self._mode = options.mode
121-
self._include_imports = options.include_imports
122119
self._include_group_socket_values = options.include_group_socket_values
123120
self._should_set_dimensions = options.set_dimensions
124121
if bpy.app.version >= (3, 4, 0):
125122
self._set_unavailable_defaults = options.set_unavailable_defaults
126-
self._author_name = options.author_name
127-
self._version = options.version
123+
124+
#Script
125+
if options.mode == 'SCRIPT':
126+
self._include_imports = options.include_imports
127+
#Addon
128+
elif options.mode == 'ADDON':
129+
self._dir_path = bpy.path.abspath(options.dir_path)
130+
self._name_override = options.name_override
131+
self._description = options.description
132+
self._author_name = options.author_name
133+
self._version = options.version
134+
self._location = options.location
135+
self._category = options.category
136+
self._custom_category = options.custom_category
137+
self._menu_id = options.menu_id
128138

129139
def _setup_addon_directories(self, context: Context, nt_var: str) -> bool:
130140
"""
@@ -137,15 +147,13 @@ def _setup_addon_directories(self, context: Context, nt_var: str) -> bool:
137147
Returns:
138148
(bool): success of addon directory setup
139149
"""
140-
# find base directory to save new addon
141-
self._dir = bpy.path.abspath(context.scene.ntp_options.dir_path)
142-
if not self._dir or self._dir == "":
150+
if not self._dir_path or self._dir_path == "":
143151
self.report({'ERROR'},
144152
("NodeToPython: No save location found. Please select "
145153
"one in the NodeToPython Options panel"))
146154
return False
147155

148-
self._zip_dir = os.path.join(self._dir, nt_var)
156+
self._zip_dir = os.path.join(self._dir_path, nt_var)
149157
self._addon_dir = os.path.join(self._zip_dir, nt_var)
150158

151159
if not os.path.exists(self._addon_dir):
@@ -163,12 +171,19 @@ def _create_header(self, name: str) -> None:
163171
"""
164172

165173
self._write("bl_info = {", "")
174+
if self._name_override and self._name_override != "":
175+
name = self._name_override
166176
self._write(f"\t\"name\" : {str_to_py_str(name)},", "")
177+
if self._description and self._description != "":
178+
self.write(f"\t\"description\" : {str_to_py_str(self._description)}," "")
167179
self._write(f"\t\"author\" : {str_to_py_str(self._author_name)},", "")
168180
self._write(f"\t\"version\" : {vec3_to_py_str(self._version)},", "")
169181
self._write(f"\t\"blender\" : {bpy.app.version},", "")
170-
self._write("\t\"location\" : \"Object\",", "") # TODO
171-
self._write("\t\"category\" : \"Node\"", "")
182+
self._write(f"\t\"location\" : {str_to_py_str(self._location)},", "")
183+
category = self._category
184+
if category == "Custom":
185+
category = self._custom_category
186+
self._write(f"\t\"category\" : {str_to_py_str(category)},", "")
172187
self._write("}\n", "")
173188
self._write("import bpy", "")
174189
self._write("import mathutils", "")
@@ -185,8 +200,8 @@ def _init_operator(self, idname: str, label: str) -> None:
185200
label (str): appearence inside Blender
186201
"""
187202
self._write(f"class {self._class_name}(bpy.types.Operator):", "")
188-
self._write(f"\tbl_idname = \"object.{idname}\"", "")
189-
self._write(f"\tbl_label = \"{label}\"", "")
203+
self._write(f"\tbl_idname = \"node.{idname}\"", "")
204+
self._write(f"\tbl_label = {str_to_py_str(label)}", "")
190205
self._write("\tbl_options = {\'REGISTER\', \'UNDO\'}", "")
191206
self._write("")
192207

@@ -1330,7 +1345,7 @@ def _create_register_func(self) -> None:
13301345
"""
13311346
self._write("def register():", "")
13321347
self._write(f"bpy.utils.register_class({self._class_name})", "\t")
1333-
self._write("bpy.types.VIEW3D_MT_object.append(menu_func)", "\t")
1348+
self._write(f"bpy.types.{self._menu_id}.append(menu_func)", "\t")
13341349
self._write("")
13351350

13361351
def _create_unregister_func(self) -> None:
@@ -1339,7 +1354,7 @@ def _create_unregister_func(self) -> None:
13391354
"""
13401355
self._write("def unregister():", "")
13411356
self._write(f"bpy.utils.unregister_class({self._class_name})", "\t")
1342-
self._write("bpy.types.VIEW3D_MT_object.remove(menu_func)", "\t")
1357+
self._write(f"bpy.types.{self._menu_id}.remove(menu_func)", "\t")
13431358
self._write("")
13441359

13451360
def _create_main_func(self) -> None:
@@ -1375,7 +1390,7 @@ def _report_finished(self, object: str):
13751390
if self._mode == 'SCRIPT':
13761391
location = "clipboard"
13771392
else:
1378-
location = self._dir
1393+
location = self._dir_path
13791394
self.report({'INFO'}, f"NodeToPython: Saved {object} to {location}")
13801395

13811396
# ABSTRACT

options.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ class NTPOptions(bpy.types.PropertyGroup):
4242
description="Save location if generating an add-on",
4343
default = "//"
4444
)
45+
name_override : bpy.props.StringProperty(
46+
name = "Name Override",
47+
description="Name used for the add-on's, default is node group name",
48+
default = ""
49+
)
50+
description : bpy.props.StringProperty(
51+
name = "Description",
52+
description="Description used for the add-on",
53+
default=""
54+
)
4555
author_name : bpy.props.StringProperty(
4656
name = "Author",
4757
description = "Name used for the author/maintainer of the add-on",
@@ -52,7 +62,61 @@ class NTPOptions(bpy.types.PropertyGroup):
5262
description="Version of the add-on",
5363
default = (1, 0, 0)
5464
)
55-
65+
location: bpy.props.StringProperty(
66+
name = "Location",
67+
description="Location of the addon",
68+
default="Node"
69+
)
70+
menu_id: bpy.props.StringProperty(
71+
name = "Menu ID",
72+
description = "Python ID of the menu you'd like to register the add-on "
73+
"to. You can find this by enabling Python tooltips "
74+
"(Preferences > Interface > Python tooltips) and "
75+
"hovering over the desired menu",
76+
default="NODE_MT_add"
77+
)
78+
category: bpy.props.EnumProperty(
79+
name = "Category",
80+
items = [
81+
('Custom', "Custom", "Use an unofficial category"),
82+
('3D View', "3D View", ""),
83+
('Add Curve', "Add Curve", ""),
84+
('Add Mesh', "Add Mesh", ""),
85+
('Animation', "Animation", ""),
86+
('Bake', "Bake", ""),
87+
('Compositing', "Compositing", ""),
88+
('Development', "Development", ""),
89+
('Game Engine', "Game Engine", ""),
90+
('Geometry Nodes', "Geometry Nodes", ""),
91+
("Grease Pencil", "Grease Pencil", ""),
92+
('Import-Export', "Import-Export", ""),
93+
('Lighting', "Lighting", ""),
94+
('Material', "Material", ""),
95+
('Mesh', "Mesh", ""),
96+
('Modeling', "Modeling", ""),
97+
('Node', "Node", ""),
98+
('Object', "Object", ""),
99+
('Paint', "Paint", ""),
100+
('Pipeline', "Pipeline", ""),
101+
('Physics', "Physics", ""),
102+
('Render', "Render", ""),
103+
('Rigging', "Rigging", ""),
104+
('Scene', "Scene", ""),
105+
('Sculpt', "Sculpt", ""),
106+
('Sequencer', "Sequencer", ""),
107+
('System', "System", ""),
108+
('Text Editor', "Text Editor", ""),
109+
('Tracking', "Tracking", ""),
110+
('UV', "UV", ""),
111+
('User Interface', "User Interface", ""),
112+
],
113+
default = 'Node'
114+
)
115+
custom_category: bpy.props.StringProperty(
116+
name="Custom Category",
117+
description="Custom category",
118+
default = ""
119+
)
56120
class NTPOptionsPanel(bpy.types.Panel):
57121
bl_label = "Options"
58122
bl_idname = "NODE_PT_ntp_options"
@@ -86,9 +150,14 @@ def draw(self, context):
86150
addon_options = [
87151
"dir_path",
88152
"author_name",
89-
"version"
153+
"version",
154+
"location",
155+
"menu_id",
156+
"category"
90157
]
91158
option_list += addon_options
159+
if ntp_options.category == 'CUSTOM':
160+
option_list.append("custom_category")
92161

93162
for option in option_list:
94163
layout.prop(ntp_options, option)

0 commit comments

Comments
 (0)