Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Last active November 24, 2024 21:15

Revisions

  1. CGArtPython revised this gist Nov 24, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions simple_import_fbx_op.py
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@ class SimpleImportFBXOperator(bpy.types.Operator):

    def execute(self, context):
    # WARNING: This is just an example path, please don't use hardcoded paths in production add-ons!
    # Consider this more advanced solution https://gist.github.com/CGArtPython/f2b3759e27ba1b0eca112c528ebdf1c9
    file_path = "E:\\blender_asset_lib\\man.fbx"
    bpy.ops.import_scene.fbx(filepath=file_path)
    return {'FINISHED'}
  2. CGArtPython created this gist Nov 24, 2024.
    42 changes: 42 additions & 0 deletions simple_import_fbx_op.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    import bpy


    class SimpleImportFBXOperator(bpy.types.Operator):
    bl_idname = "import_scene.custom_fbx"
    bl_label = "Import FBX Model"

    def execute(self, context):
    # WARNING: This is just an example path, please don't use hardcoded paths in production add-ons!
    file_path = "E:\\blender_asset_lib\\man.fbx"
    bpy.ops.import_scene.fbx(filepath=file_path)
    return {'FINISHED'}


    class VIEW3D_PT_my_custom_panel(bpy.types.Panel): # class naming convention ‘CATEGORY_PT_name’

    # where to add the panel in the UI
    bl_space_type = "VIEW_3D" # 3D Viewport area (find list of values here https://docs.blender.org/api/current/bpy_types_enum_items/space_type_items.html#rna-enum-space-type-items)
    bl_region_type = "UI" # Sidebar region (find list of values here https://docs.blender.org/api/current/bpy_types_enum_items/region_type_items.html#rna-enum-region-type-items)

    bl_category = "My Custom Panel category" # found in the Sidebar
    bl_label = "My Custom Panel label" # found at the top of the Panel

    def draw(self, context):
    """define the layout of the panel"""
    row = self.layout.row()
    row.operator("import_scene.custom_fbx", text="Add Man")



    def register():
    bpy.utils.register_class(SimpleImportFBXOperator)
    bpy.utils.register_class(VIEW3D_PT_my_custom_panel)


    def unregister():
    bpy.utils.unregister_class(VIEW3D_PT_my_custom_panel)
    bpy.utils.unregister_class(SimpleImportFBXOperator)


    if __name__ == "__main__":
    register()