added prefs for file zipper
1.3.1 - added: prefs for file zipper (fallback to this if env is not defined) - changed: zip operator id_name `bpy.ops.adm.export_zip` >> `bpy.opsbat.export_zip`
This commit is contained in:
		
							parent
							
								
									3c5cca81a5
								
							
						
					
					
						commit
						e2610a882e
					
				
							
								
								
									
										16
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								README.md
									
									
									
									
									
								
							| @ -2,3 +2,19 @@ | |||||||
| 
 | 
 | ||||||
| Modified version | Modified version | ||||||
| with Zip packer included | with Zip packer included | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Zip behavior | ||||||
|  | the root folder of the zip use first the environment variable `ZIP_ROOT` (used with `os.getenv('ZIP_ROOT')`) | ||||||
|  | 
 | ||||||
|  | If there is no such env variable it fallback to path specified in addon preferences. | ||||||
|  | 
 | ||||||
|  | This root can be manually changed in the settings (sidebar) of the export browser windows. | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ### Changelog | ||||||
|  | 
 | ||||||
|  | 1.3.1 | ||||||
|  | 
 | ||||||
|  | - added: prefs for file zipper (fallback to this if env is not defined) | ||||||
|  | - changed: zip operator id_name `bpy.ops.adm.export_zip` >> `bpy.opsbat.export_zip` | ||||||
							
								
								
									
										23
									
								
								__init__.py
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								__init__.py
									
									
									
									
									
								
							| @ -25,7 +25,7 @@ __version__ = '1.3' | |||||||
| bl_info = { | bl_info = { | ||||||
|     "name": "Blender Asset Tracer", |     "name": "Blender Asset Tracer", | ||||||
|     "author": "Campbell Barton, Sybren A. Stüvel, Loïc Charrière and Clément Ducarteron", |     "author": "Campbell Barton, Sybren A. Stüvel, Loïc Charrière and Clément Ducarteron", | ||||||
|     "version": (1, 3, 0), |     "version": (1, 3, 1), | ||||||
|     "blender": (2, 80, 0), |     "blender": (2, 80, 0), | ||||||
|     "location": "File > External Data > BAT", |     "location": "File > External Data > BAT", | ||||||
|     "description": "Utility for packing blend files", |     "description": "Utility for packing blend files", | ||||||
| @ -47,7 +47,7 @@ import sys | |||||||
| import subprocess | import subprocess | ||||||
| import tempfile | import tempfile | ||||||
| from blender_asset_tracer.trace import deps | from blender_asset_tracer.trace import deps | ||||||
| 
 | from . import preferences | ||||||
| 
 | 
 | ||||||
| class ExportBatPack(Operator, ExportHelper): | class ExportBatPack(Operator, ExportHelper): | ||||||
|     bl_idname = "export_bat.pack" |     bl_idname = "export_bat.pack" | ||||||
| @ -86,10 +86,10 @@ class ExportBatPack(Operator, ExportHelper): | |||||||
|         return {'FINISHED'} |         return {'FINISHED'} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ADM_OT_export_zip(Operator, ExportHelper): | class BAT_OT_export_zip(Operator, ExportHelper): | ||||||
|     """Export current blendfile as .ZIP""" |     """Export current blendfile as .ZIP""" | ||||||
|     bl_label = "Export File to .ZIP" |     bl_label = "Export File to .ZIP" | ||||||
|     bl_idname = "adm.export_zip" |     bl_idname = "bat.export_zip" | ||||||
|      |      | ||||||
|     filename_ext = '.zip' |     filename_ext = '.zip' | ||||||
|      |      | ||||||
| @ -105,6 +105,13 @@ class ADM_OT_export_zip(Operator, ExportHelper): | |||||||
|     def poll(cls, context): |     def poll(cls, context): | ||||||
|         return bpy.data.is_saved |         return bpy.data.is_saved | ||||||
| 
 | 
 | ||||||
|  |     ## ExportHelper has it's own invoke so overriding it with this one create error | ||||||
|  |     # def invoke(self, context, event): | ||||||
|  |     #     prefs = preferences.get_addon_prefs() | ||||||
|  |     #     if prefs.root_default: | ||||||
|  |     #         self.root_dir = prefs.root_default | ||||||
|  |     #     return self.execute(context) | ||||||
|  | 
 | ||||||
|     def execute(self, context): |     def execute(self, context): | ||||||
| 
 | 
 | ||||||
|         root_dir = self.root_dir |         root_dir = self.root_dir | ||||||
| @ -249,18 +256,21 @@ def menu_func(self, context): | |||||||
|     layout = self.layout |     layout = self.layout | ||||||
|     layout.separator() |     layout.separator() | ||||||
|     layout.operator(ExportBatPack.bl_idname) |     layout.operator(ExportBatPack.bl_idname) | ||||||
|     filepath = layout.operator(ADM_OT_export_zip.bl_idname) |     filepath = layout.operator(BAT_OT_export_zip.bl_idname) | ||||||
|     root_dir_env = os.getenv('ZIP_ROOT') |     root_dir_env = os.getenv('ZIP_ROOT') | ||||||
|  |     if not root_dir_env: # if no env use prefs instead | ||||||
|  |         root_dir_env = preferences.get_addon_prefs().root_default | ||||||
|     filepath.root_dir = '' if root_dir_env == None else root_dir_env #os.getenv('PROJECT_STORE') |     filepath.root_dir = '' if root_dir_env == None else root_dir_env #os.getenv('PROJECT_STORE') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| classes = ( | classes = ( | ||||||
|     ExportBatPack, |     ExportBatPack, | ||||||
|     ADM_OT_export_zip, |     BAT_OT_export_zip, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def register(): | def register(): | ||||||
|  |     preferences.register() | ||||||
|     for cls in classes: |     for cls in classes: | ||||||
|         bpy.utils.register_class(cls) |         bpy.utils.register_class(cls) | ||||||
| 
 | 
 | ||||||
| @ -271,6 +281,7 @@ def unregister(): | |||||||
|     for cls in classes: |     for cls in classes: | ||||||
|         bpy.utils.unregister_class(cls) |         bpy.utils.unregister_class(cls) | ||||||
| 
 | 
 | ||||||
|  |     preferences.unregister() | ||||||
|     bpy.types.TOPBAR_MT_file_external_data.remove(menu_func) |     bpy.types.TOPBAR_MT_file_external_data.remove(menu_func) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										46
									
								
								preferences.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								preferences.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | |||||||
|  | import bpy | ||||||
|  | from bpy.props import (FloatProperty, | ||||||
|  |                         BoolProperty, | ||||||
|  |                         EnumProperty, | ||||||
|  |                         StringProperty, | ||||||
|  |                         IntProperty, | ||||||
|  |                         PointerProperty) | ||||||
|  | 
 | ||||||
|  | def get_addon_prefs(): | ||||||
|  |     prefs = bpy.context.preferences | ||||||
|  |     return prefs.addons[__package__].preferences | ||||||
|  | 
 | ||||||
|  | class myaddonPrefs(bpy.types.AddonPreferences): | ||||||
|  |     bl_idname = __name__.split('.')[0] | ||||||
|  | 
 | ||||||
|  |     root_default : bpy.props.StringProperty( | ||||||
|  |         name='Default Root', | ||||||
|  |         description="Default root folder path when using export to Zip", | ||||||
|  |         subtype='DIR_PATH', | ||||||
|  |         default='') | ||||||
|  | 
 | ||||||
|  |     def draw(self, context): | ||||||
|  |             layout = self.layout | ||||||
|  |             col = layout.column() | ||||||
|  |             col.label(text='Export to Zip preferences:') | ||||||
|  |             col.prop(self, 'root_default') | ||||||
|  |              | ||||||
|  |             col = layout.column() | ||||||
|  |             col.label(text='If specified, will be the default root folder path when using export to Zip') | ||||||
|  |             col.label(text='Typically the root folder of the current project') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ### --- REGISTER --- | ||||||
|  | 
 | ||||||
|  | classes=( | ||||||
|  | myaddonPrefs, | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | def register():  | ||||||
|  |     for cls in classes: | ||||||
|  |         bpy.utils.register_class(cls) | ||||||
|  | 
 | ||||||
|  | def unregister(): | ||||||
|  |     for cls in reversed(classes): | ||||||
|  |         bpy.utils.unregister_class(cls) | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user