Custom file handler to open more file types

What would be best way to add support for more file types with Python?

Currently I am using – argument to pass filename to Blender and Python.

drag_drop_import_files.bat:

"%~dp0\blender.exe" --python "%~dp0\import_file.py" -- '%1'

import_file.py:

import bpy
import sys
argv = sys.argv[sys.argv.index("--") + 1:]  # get all args after "--"
file = argv[0].strip("'")
ext = file.split('.')[-1].lower()

if ext == 'blend':
    bpy.ops.wm.open_mainfile(filepath = file)
elif ext =='fbx':
    bpy.ops.import_scene.fbx(filepath = file)
elif ext =='obj':
    bpy.ops.import_scene.obj(filepath = file)
1 Like

I think i found solution to passing arguments.

Blender ignores everything after -- and custom arguments can be passed there as explained in: https://blender.stackexchange.com/questions/6817/how-to-pass-command-line-arguments-to-a-blender-python-script