Skip to content

Instantly share code, notes, and snippets.

@havchr
Last active February 9, 2023 03:01
Show Gist options
  • Save havchr/2b9b8d76161998f9a7bdace09906eeec to your computer and use it in GitHub Desktop.
Save havchr/2b9b8d76161998f9a7bdace09906eeec to your computer and use it in GitHub Desktop.
A blender export plugin that exports a collection named Export with FBX_SCALE_UNITS
import bpy
#This blender plugin will export everything in a collection named Export with fbx format with FBX scale.
#You can adjust to your needs for options - usefull for making sure you have consistent
#export settings for your FBXs and an easy way to reach them. I suggest you add it to quick shortcuts as well.
#I just press q->export and enter and then I have exported a new version.
bl_info = {
"name": "Export whitebox mesh",
"blender": (2, 80, 0),
"category": "Exporter",
}
# ExportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator
#Recursivly transverse layer_collection for a particular name
def recurLayerCollection(layerColl, collName):
found = None
if (layerColl.name == collName):
return layerColl
for layer in layerColl.children:
found = recurLayerCollection(layer, collName)
if found:
return found
class WhiteboxFbxExporter(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "export_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Whitebox fbx exporter"
# ExportHelper mixin class uses this
filename_ext = ".fbx"
filter_glob: StringProperty(
default="*.fbx",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
use_setting: BoolProperty(
name="Are you cool",
description="That is good",
default=True,
)
type: EnumProperty(
name="Checkboxes",
description="Choose between two items",
items=(
('OPT_A', "Pizza", "Does not do anything atm"),
('OPT_B', "Lutefisk", "You must eat lutefisk forever"),
),
default='OPT_A',
)
def execute(self, context):
collectionHolder = bpy.context.view_layer.active_layer_collection;
lookingForCollection = "Export"
layerCollection = bpy.context.view_layer.layer_collection
bpy.context.view_layer.active_layer_collection = recurLayerCollection(layerCollection,lookingForCollection)
print (bpy.context.view_layer.active_layer_collection.name)
val = bpy.ops.export_scene.fbx(filepath = self.filepath,use_active_collection=True,apply_scale_options='FBX_SCALE_UNITS')
bpy.context.view_layer.active_layer_collection = collectionHolder
return val
# Only needed if you want to add into a dynamic menu
def menu_func_export(self, context):
self.layout.operator(WhiteboxFbxExporter.bl_idname, text="Whitebox fbx exporter")
def register():
bpy.utils.register_class(WhiteboxFbxExporter)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(WhiteboxFbxExporter)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()
# test call
bpy.ops.export_test.some_data('INVOKE_DEFAULT')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment