Skip to content

Instantly share code, notes, and snippets.

@mio3io
Last active May 19, 2024 11:23
Show Gist options
  • Save mio3io/359de51bc89c7be6dacfa9d359af7c61 to your computer and use it in GitHub Desktop.
Save mio3io/359de51bc89c7be6dacfa9d359af7c61 to your computer and use it in GitHub Desktop.
選択しなくても可視オブジェクトを全部エクスポートするボタン
import bpy
bl_info = {
"name": "Mio3 ACT Custom Menu",
"author": "mio",
"version": (1, 0, 0),
"blender": (4, 0, 0),
"location": "3D View > Toolbox > ACT",
"description": "Asset Creation Toolset のカスタマイズメニュー",
"category": "Object",
}
def is_act_installed():
return "multi_fbx_export" in dir(bpy.ops.object)
class MIO3ACTW_OT_ExportVisible(bpy.types.Operator):
bl_idname = "mesh.mio3actw_export_visible"
bl_label = "Export Visible"
bl_description = "Export only visible objects"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return context.object is not None and is_act_installed()
def execute(self, context):
scene = bpy.context.scene
act = bpy.context.scene.act
if len(bpy.data.filepath) == 0 and not act.custom_export_path:
self.report({"INFO"}, "ACTのExportメニューでディレクトリを設定してください")
return {"CANCELLED"}
current_selection = [obj for obj in scene.objects if obj.select_get()]
active_object = bpy.context.active_object
bpy.ops.object.select_all(action="DESELECT")
for obj in scene.objects:
if obj.visible_get():
obj.select_set(True)
try:
# Export
bpy.ops.object.multi_fbx_export()
except Exception as e:
self.report({"ERROR"}, str(e))
return {"CANCELLED"}
finally:
bpy.ops.object.select_all(action="DESELECT")
for obj in current_selection:
obj.select_set(True)
bpy.context.view_layer.objects.active = active_object
return {"FINISHED"}
class MIO3ACTW_PT_main(bpy.types.Panel):
bl_label = "ACT Custom Menu"
bl_idname = "MIO3ACTW_PT_main"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "ACT"
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
if is_act_installed():
row.operator(
MIO3ACTW_OT_ExportVisible.bl_idname,
text="Export Visible",
icon="EXPORT",
)
if len(bpy.context.scene.act.export_dir) > 0:
row.operator("object.open_export_dir", text="", icon="FILEBROWSER")
else:
row.label(text="ACTがインストールされていません", icon="ERROR")
def update_panel(self, context):
is_exist = hasattr(bpy.types, "MIO3ACTW_PT_main")
category = bpy.context.preferences.addons[__package__].preferences.category
if is_exist:
try:
bpy.utils.unregister_class(MIO3ACTW_PT_main)
except:
pass
MIO3ACTW_PT_main.bl_category = category
bpy.utils.register_class(MIO3ACTW_PT_main)
class MIO3ACTW_Preferences(bpy.types.AddonPreferences):
bl_idname = __name__
category: bpy.props.StringProperty(
name="Tab Name",
description="Tab Name",
default="ACT",
update=update_panel,
)
def draw(self, context):
layout = self.layout
layout.prop(self, "category")
classes = [
MIO3ACTW_Preferences,
MIO3ACTW_OT_ExportVisible,
MIO3ACTW_PT_main,
]
def register():
for c in classes:
bpy.utils.register_class(c)
update_panel(None, bpy.context)
def unregister():
for c in reversed(classes):
bpy.utils.unregister_class(c)
if __name__ == "__main__":
register()
@mio3io
Copy link
Author

mio3io commented May 19, 2024

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment