I try to create this script but I’m newbie in python
The aim is to export a fbx in specific folder when you click Export button. If the checkbox is True, then the filename get the name of collection. Conversely, if is uncheck the the filename get the active object.
Here is my own script but i get an error message which says name ‘filename’ is not defined.
Thanks for your help.
bl_info = {
"name" : "MyTab",
"author" : "",
"version" :(0, 1),
"blender" : (2, 93, 6),
"location":"View3D > Tool",
"warning":"",
"wiki_url":"",
"category": "Custom"
}
import bpy
from bpy.props import BoolProperty
bpy.types.Scene.my_checkbox = BoolProperty(
name="is Collection",
description="is Collection ?",
default = False)
class MyPanel_PT_Panel(bpy.types.Panel):
bl_label = "MyPanel"
bl_idname = "my_panel" #id name du premier panneau
bl_space_type = 'VIEW_3D' # le type d'espace c'est à dire espace 3D
bl_region_type = 'UI' # ca agit sur quoi ? sur l'UI
bl_category = 'MyTab' # nom de l'outil qui sera affiché sur les onglets tools
def draw(self, context):
layout = self.layout
row = layout.row()
layout.prop(context.scene, "my_prop")
row = layout.row()
row.operator("fbx.exporter",text="Export")
if (bpy.types.Scene.my_checkbox == True):
fileName = bpy.context.collection.name + '.fbx'
else:
fileName = bpy.context.active_object.name + '.fbx'
class Fbx_Exporter(bpy.types.Operator):
# export in a Substance Folder for Stone project # Use this as a tooltip for menu items and buttons.
bl_idname = "fbx.exporter" # Unique identifier for buttons and menu items to reference.
bl_label = "fbx_exporter" # Display name in the interface.
bl_options = {'REGISTER', 'UNDO'} # Enable undo for the operator.
def execute(self, context): # execute() is called when running the operator.
# Get the selected objects
selectedObject = bpy.context.selected_objects
# Get the name of selected object
for obj in selectedObject:
# to define folderPath
# rajouter trjs \\ pour définir un chemin
folderPath = 'C:\\Users\\Username\\Desktop\\FbxFolder\\'
# customfilePath will be used to filepath of FPX API operator
customFilePath = folderPath + fileName
# FBX API operator
bpy.ops.export_scene.fbx(filepath= customFilePath, check_existing=True, filter_glob='*.fbx', use_selection=True, use_active_collection=False, global_scale=1.0, apply_unit_scale=True, apply_scale_options='FBX_SCALE_UNITS', bake_space_transform=False, object_types={'ARMATURE', 'CAMERA', 'EMPTY', 'LIGHT', 'MESH', 'OTHER'}, use_mesh_modifiers=True, use_mesh_modifiers_render=True, mesh_smooth_type='OFF', use_subsurf=False, use_mesh_edges=False, use_tspace=False, use_custom_props=False, add_leaf_bones=True, primary_bone_axis='Y', secondary_bone_axis='X', use_armature_deform_only=False, armature_nodetype='NULL', bake_anim=True, bake_anim_use_all_bones=True, bake_anim_use_nla_strips=True, bake_anim_use_all_actions=True, bake_anim_force_startend_keying=True, bake_anim_step=1.0, bake_anim_simplify_factor=1.0, path_mode='AUTO', embed_textures=False, batch_mode='OFF', use_batch_own_dir=True, use_metadata=True, axis_forward='-Z', axis_up='Y')
return {'FINISHED'} # Lets Blender know the operator finished successfully.
def register():
bpy.utils.register_class(MyPanel_PT_Panel)
bpy.utils.register_class(Fbx_Exporter)
def unregister ():
bpy.utils.unregister_class(MyPanel_PT_Panel)
bpy.utils.unregister_class(Fbx_Exporter)
if __name__== "__main__":
register()