'Blender Addon in file menu
I have created a blender addon watching videos as I do not have knowledge of python. So I want to place that addon in Blender file menu but it is deleting all the other option in that menu. Also I want to assign shortcut to that menu but I am not able to assign shortcut to it .
This is what I found in log :
bpy.data.window_managers["WinMan"].(null) = 'THREE'
Here is my code :
bl_info = {
"name": "UV_Exporter v3.0",
"author": "Your Name Here",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "File > Import-Export",
"description": "Extract UV from Multiple Obj",
"warning": "",
"doc_url": "",
"category": "Import-Export",
}
import bpy
import os
def main(context):
# You should change this varibale in "here" to match your own directory path
# use '/' or '\\' for hirecacy
target_dir = "C:/Users/Arpit/Desktop/UV/"
selObj = []
for obj in bpy.context.selected_objects:
selObj.append(obj.name)
bpy.ops.object.select_all(action='TOGGLE')
for item in selObj:
obj = bpy.context.window.scene.objects[item]
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_all(action='TOGGLE')
# `item` instead of `selObj[i]`
full_file_name = target_dir + bpy.data.objects[ item ].name
dirname = os.path.dirname(full_file_name)
# inside `while`-loop
if not os.path.exists(dirname):
os.makedirs(dirname)
bpy.ops.uv.export_layout(filepath=full_file_name, mode='PNG', size=(1024, 1024), opacity=0.6)
bpy.ops.object.mode_set(mode="OBJECT")
class UvExporter(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.uv_exporter"
bl_label = "UV EXPORTER"
def execute(self, context):
main(context)
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(UvExporter.bl_idname, text=UvExporter.bl_label)
class LayoutDemoPanel(bpy.types.Menu):
"""Creates a Panel in the scene context of the properties editor"""
bl_idname = "TOPBAR_MT_file_import"
bl_label = "Import"
def draw(self, context):
layout = self.layout
scene = context.scene
# Big render button
row = layout.row()
row.scale_y = 1.0
row.operator("object.uv_exporter")
def register():
bpy.utils.register_class(LayoutDemoPanel)
bpy.utils.register_class(UvExporter)
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.utils.unregister_class(LayoutDemoPanel)
bpy.utils.unregister_class(UvExporter)
bpy.types.VIEW3D_MT_object.remove(menu_func)
if __name__ == "__main__":
register()
Please help me with this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

