Skip to content

Commit

Permalink
added create folder to unity exporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonNordon4 committed Aug 6, 2024
1 parent c994fb4 commit 286a346
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<td>~</td>
<td>4.2.0 - ~</td>
<td>all</td>
<td>16.5KB</td>
<td>16.7KB</td>
</tr>
</table>

<center><p>Built 2024-08-06, 11:30</p></center>
<center><p>Built 2024-08-06, 22:51</p></center>
</body>
</html>
4 changes: 2 additions & 2 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"Object"
],
"archive_url": "./unity_exporter.zip",
"archive_size": 16892,
"archive_hash": "sha256:379ff50e4e45fefc3afc0908d546f141b91e6b80ff55d01d5126b8fb5d826900"
"archive_size": 17092,
"archive_hash": "sha256:fb84fde6a1c66a9c712560710ab1e2f831988faecf85061959112817154398c9"
}
]
}
Binary file modified unity_exporter.zip
Binary file not shown.
34 changes: 33 additions & 1 deletion unity_exporter/unity_exporter_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def draw(self, context):
scene = context.scene
layout = self.layout
layout.prop(scene, "directory_path")


layout.operator("unity_exporter.create_folder")
row = layout.row()
row.operator("unity_exporter.clean_image_names")
row.operator("unity_exporter.clean_mesh_names")


layout.operator("unity_exporter.export_images")
layout.operator("unity_exporter.export_selected")
Expand Down Expand Up @@ -116,6 +118,34 @@ def execute(self, context):

self.report({'INFO'}, 'Images exported successfully.')
return {'FINISHED'}

class UnityExporterCreateFolder(bpy.types.Operator):
bl_idname = "unity_exporter.create_folder"
bl_label = "Create Folder"
bl_description = "Create a folder in the specified directory"

def execute(self, context):
# Create a new folder with the same name as the blender file in the directory_path, then set the directory_path to that new folder
blend_file_name = bpy.path.basename(bpy.data.filepath)
directory_path = bpy.context.scene.directory_path

if not directory_path:
self.report({'WARNING'}, 'Please specify a directory path.')
return {'CANCELLED'}

if not os.path.exists(directory_path):
self.report({'WARNING'}, 'The specified directory path does not exist.')
return {'CANCELLED'}

new_directory_path = os.path.join(directory_path, blend_file_name)
try:
os.makedirs(new_directory_path)
bpy.context.scene.directory_path = new_directory_path
self.report({'INFO'}, f"Created folder: {new_directory_path}")
except Exception as e:
self.report({'ERROR'}, f"Failed to create folder: {str(e)}")
return {'CANCELLED'}
return {'FINISHED'}

class UnityExporterExportSelected(bpy.types.Operator):
bl_idname = "unity_exporter.export_selected"
Expand Down Expand Up @@ -170,6 +200,7 @@ def execute(self, context):
def register():
print("Registering unity_exporter_panel")
bpy.utils.register_class(UnityExporterPanel)
bpy.utils.register_class(UnityExporterCreateFolder)
bpy.utils.register_class(UnityExporterCleanMeshNames)
bpy.utils.register_class(UnityExporterCleanImageNames)
bpy.utils.register_class(UnityExporterExportImages)
Expand All @@ -185,6 +216,7 @@ def register():

def unregister():
bpy.utils.unregister_class(UnityExporterPanel)
bpy.utils.unregister_class(UnityExporterCreateFolder)
bpy.utils.unregister_class(UnityExporterCleanMeshNames)
bpy.utils.unregister_class(UnityExporterCleanImageNames)
bpy.utils.unregister_class(UnityExporterExportImages)
Expand Down

0 comments on commit 286a346

Please sign in to comment.