doakey3 / Subsimport

Blender 3d addon for importing and editing subtitle and lyric files.
GNU General Public License v3.0
61 stars 15 forks source link

How to import a srt file in bpy API code? #11

Open cyberpsyche opened 2 years ago

cyberpsyche commented 2 years ago

I want to use a background style bpy code to handle blender VSE. As Subsimport is a good subtitles process addon in blender. I hope to use import_subtitles() function in my code.

I do it like:

addon_utils.enable("Subsimport")
bpy.ops.sequencerextra.import_subtitles("/Users/sam/Projects/Blender/Study/test.srt")

but I got:

TypeError: Calling operator "bpy.ops.sequencerextra.import_subtitles" error, expected a string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN')

Can anybody help me to solve this problem ? I don't know how to analog a import file action in the bpy code. Thanks a lot !

cyberpsyche commented 2 years ago

After reading the docs of bpy, I found how to do it :)

bpy.ops.sequencerextra.import_subtitles('INVOKE_DEFAULT', filepath="/Users/sam/Projects/Blender/Study/test.srt")

thanks @doakey3 provided such a nice tool.