@@ -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"\t bl_idname = \" object .{ idname } \" " , "" )
189- self ._write (f"\t bl_label = \" { label } \" " , "" )
203+ self ._write (f"\t bl_idname = \" node .{ idname } \" " , "" )
204+ self ._write (f"\t bl_label = { str_to_py_str ( label ) } " , "" )
190205 self ._write ("\t bl_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
0 commit comments