I have this simple script for exporting meshes. It's all in one file and works fine (no errors) when executed from the scripting editor.
When I am installing it through "Preferences -> Install from file" it shows up in the list, I enable it, but it wont work untill I run it in the script editor, in blender.
The same goes after restarting Blender - it's visible in the list as enbaled but does not work. I need to run it through script editor to activate.
I checked user scripts folder for addon and it's there, so installation process went ok.
Windows 10.
How to fix it? Thanks
Code:
bl_info = {"name" : "Spike FBX Unity Export", "category": "Export", "author": "Sergiusz"}
import bpy
import os
from bpy_extras.io_utils import ExportHelper
class Spk_Object_Settings(bpy.types.PropertyGroup):
layer: bpy.props.StringProperty(default="spk_EnviroStatic")
collider: bpy.props.EnumProperty(
name = "Collider",
items = (("None", "None", ""), ("Box", "Box", ""), ("Sphere", "Sphere", ""), ("Capsule", "Capsule", ""), ("Mesh", "Mesh", "")), default = "Mesh")
#====
class Spk_PT_Object_Settings(bpy.types.Panel):
bl_idname = "spike.object_settings_panel"
bl_label = "Object Settings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Spike"
@classmethod
def poll(cls, context):
return (context.selected_objects != []) and (context.active_object.type == "MESH")
def draw(self, context):
layout = self.layout
o = bpy.context.active_object
box = layout.box()
box.prop(o.data.Spk_Object_Settings, "layer", text = "Layer")
box.prop(o.data.Spk_Object_Settings, "collider", text = "Collider")
#====
class Spk_OT_Fbx_Export(bpy.types.Operator, ExportHelper):
bl_idname = "spike.fbx_export"
bl_label = "Spike FBX Unity Export"
filename_ext = ".fbx"
filter_glob: bpy.props.StringProperty(
default="*.fbx",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
@classmethod
def poll(cls, context):
return (context.selected_objects != []) and (context.active_object.type == "MESH")
def execute(self, context):
folder_path = (os.path.dirname(self.filepath))
if folder_path == None:
self.report({'ERROR'}, "Export folder not set")
else:
objs = bpy.context.selected_objects
for o in objs:
o.select_set(False)
for o in objs:
if o.type == "MESH":
print("Exporting: " + o.name + "...")
o["spk_export_layer"] = o.data.Spk_Object_Settings.layer
o["spk_export_collider"] = o.data.Spk_Object_Settings.collider
file_path = folder_path + "/" + o.name + ".fbx"
o.select_set(True)
bpy.context.view_layer.objects.active = o
bpy.ops.export_scene.fbx(
filepath = file_path,
use_selection = True,
global_scale = 1.0,
apply_unit_scale = True,
apply_scale_options = 'FBX_SCALE_NONE',
mesh_smooth_type = 'OFF',
bake_space_transform = True,
bake_anim = False,
object_types = {'MESH'},
use_tspace = True,
use_mesh_modifiers = True,
use_custom_props = True,
axis_forward = '-Z',
axis_up = 'Y')
print("Exporting: ...done")
o.select_set(False)
# self.report({"INFO"}, "Will export: " + (context.active_object.name) + " to: " + (folder_path))
for o in objs:
o.select_set(True)
return {'FINISHED'}
classes = (Spk_OT_Fbx_Export, Spk_Object_Settings, Spk_PT_Object_Settings)
def menu_func_export(self, context):
self.layout.operator(Spk_OT_Fbx_Export.bl_idname, text="Spike FBX Unity Export")
def register():
for c in classes:
bpy.utils.register_class(c)
bpy.types.Mesh.Spk_Object_Settings = bpy.props.PointerProperty(type=Spk_Object_Settings)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_classes_factory(classes)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__": register()
un-register your classes properly
- I checked console and there are no errors? $\endgroup$