Last active
November 24, 2024 21:15
-
-
Save CGArtPython/36d3ec1dc2d4b1d2ec08503133ea5de2 to your computer and use it in GitHub Desktop.
[Blender Python] Import a FBX model into the scene (vidoe explination https://www.skool.com/cgpython/make-a-button-to-add-a-model?p=abc92a32)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
# 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'} | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment