diff --git a/README.md b/README.md index 861aa04..d614dfe 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,32 @@ You can learn more about why i made it and how it works at: https://youtu.be/JIN Use: Select a text strip in the VSE and, using the f3 menu, search "add text drop shadow". You can add this operator to quick favorites by right clicking on it. Zoom -Limitations: -1.If the text strip you are adding a shadow to has anything occupying tho two channels beneath it, the script will toss the new shadow strips somewhere random in your project. -2.Can't add shadows to multiple text strips at the same time. +Limitations: +1. If the text strip you are adding a shadow to has anything occupying tho two channels beneath it, the script will toss the new shadow strips somewhere random in your project. + +Installation: + +To load and use your script in Blender, you have several options, ranging from running the script directly in Blender's Text Editor to installing it as an add-on. Here's a step-by-step guide for both methods: +Running the Script Directly in Blender +1. Open Blender: Start by launching Blender. +2. Open the Text Editor: In Blender, switch one of the viewports to the Text Editor. You can do this by clicking on the editor type selection button (in the top-left corner of any viewport) and choosing "Text Editor". +3. Open or Paste Your Script: You can either paste your script directly into the Text Editor or open your script file by clicking "Open" in the Text Editor's header and navigating to your script file. +4. Run the Script: After your script is in the Text Editor, click the "Run Script" button in the Text Editor's header. This executes the script and registers your operator and panel in the UI. + +Installing the Script as an Addon +To make your script easily reusable across Blender projects, you can install it as an addon. First, ensure your script has the proper bl_info block at the top (which you have), as this is required for Blender addons. Then, follow these steps: +1. Save Your Script: Save your script to a .py file on your computer if you haven't done so already. +2. Open Blender and Go to Preferences: + - Open Blender. + - Go to "Edit" > "Preferences". +3. Install the Addon: + - In the Preferences window, switch to the "Add-ons" section. + - Click "Install..." at the top of the window. + - Navigate to where you saved your .py file, select it, and click "Install Add-on". +4. Activate the Addon: + - After installation, the addon should appear in the list. However, it might not be enabled by default. Use the search box to find your addon by the name you gave it in the bl_info block. + - Once you find your addon in the list, check the checkbox next to its name to activate it. +5. Save Preferences (Optional): + - If you want Blender to enable this addon by default in new projects, click the "Save Preferences" button at the bottom left of the Preferences window. + +After following either method, your script will be running in Blender. If you installed it as an addon, you would find your new panel in the specified category (e.g., "Tool") in the Sequencer's UI side panel, accessible by pressing 'N' in the Sequencer or clicking on the arrow on the right side of the Sequencer to expand the side panel. diff --git a/__init__.py b/__init__.py index 92993a3..ab74dd9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,9 +1,7 @@ - - bl_info = { "name": "Add Text Drop Shadow", - "version": (0, 1, 0), - "author": "Ian Letarte", + "version": (0, 1, 4), + "author": "Ian Letarte, GameDirection", "blender": (4, 0, 0), "description": "Add a nice drop shadow to your text strips in the VSE", "category": "Sequencer", @@ -11,51 +9,102 @@ import bpy +from bpy.props import IntProperty, FloatVectorProperty, EnumProperty, FloatProperty class AddTextDropShadowOperator(bpy.types.Operator): bl_idname = "vse.add_text_drop_shadow" bl_label = "Add Text Drop Shadow" - def execute(self, context): - # Check if there's a selected strip and if it's a text strip - selected_strip = context.scene.sequence_editor.active_strip - if selected_strip and selected_strip.type == 'TEXT': - # Duplicate the selected text strip and move it down two channels - bpy.ops.sequencer.duplicate_move() - bpy.ops.transform.seq_slide(value=(0, -2)) - - # Adjust the frame start and end of the duplicate text strip - duplicate_strip = context.active_sequence_strip - duplicate_strip.frame_final_start = selected_strip.frame_final_start - duplicate_strip.frame_final_end = selected_strip.frame_final_end - - # Set the color of the duplicate text strip to black - context.active_sequence_strip.color = (0, 0, 0, 1) - - #mute duplicate text - bpy.ops.sequencer.mute(unselected=False) - + blur_amount: IntProperty( + name="Blur Amount", + description="Amount of Gaussian Blur", + default=30, + min=0, + max=100 + ) + + shadow_color: FloatVectorProperty( + name="Shadow Color", + description="Color of the text shadow", + subtype='COLOR', + size=4, + min=0.0, + max=1.0, + default=(0.0, 0.0, 0.0, 1.0) + ) + + shadow_opacity: FloatProperty( + name="Shadow Opacity", + description="Opacity of the shadow", + min=0.0, + max=1.0, + default=1.0 + ) + + blend_modes = [ + ('REPLACE', "Replace", ""), + ('OVER_DROP', "Over Drop", ""), + ('ALPHA_OVER', "Alpha Over", ""), + ('ADD', "Add", ""), + ] + + blend_mode: EnumProperty( + name="Blend Mode", + description="Blend mode for the shadow", + items=blend_modes, + default='ALPHA_OVER', + ) - # Add a Gaussian blur effect strip and set its size - bpy.ops.sequencer.effect_strip_add(type='GAUSSIAN_BLUR') - context.active_sequence_strip.size_x = 30 - context.active_sequence_strip.size_y = 30 - + def execute(self, context): + sequences = context.scene.sequence_editor.sequences + selected_text_strips = [strip for strip in sequences if strip.type == 'TEXT' and strip.select] + + for strip in selected_text_strips: + blur_exists = any(s for s in sequences if s.type == 'GAUSSIAN_BLUR' and s.name == f"Blur_{strip.name}") + + if not blur_exists: + original_channel = strip.channel + target_duplicate_channel = max(1, original_channel - 2) + target_gaussian_channel = target_duplicate_channel + 1 + + bpy.ops.sequencer.select_all(action='DESELECT') + strip.select = True + context.scene.sequence_editor.active_strip = strip + bpy.ops.sequencer.duplicate() + duplicate_strip = context.scene.sequence_editor.active_strip + duplicate_strip.channel = target_duplicate_channel + + # Set color and opacity + shadow_color = self.shadow_color[:3] + (self.shadow_opacity,) + duplicate_strip.color = shadow_color + duplicate_strip.blend_type = self.blend_mode + duplicate_strip.mute = True + + bpy.ops.sequencer.select_all(action='DESELECT') + duplicate_strip.select = True + context.scene.sequence_editor.active_strip = duplicate_strip + bpy.ops.sequencer.effect_strip_add(type='GAUSSIAN_BLUR', channel=target_gaussian_channel) + blur_strip = context.scene.sequence_editor.active_strip + blur_strip.name = f"Blur_{strip.name}" + blur_strip.size_x = self.blur_amount + blur_strip.size_y = self.blur_amount + return {'FINISHED'} + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) - return {'FINISHED'} +class TEXTDROPSHADOW_PT_panel(bpy.types.Panel): + bl_label = "Text Drop Shadow" + bl_idname = "TEXTDROPSHADOW_PT_panel" + bl_space_type = 'SEQUENCE_EDITOR' + bl_region_type = 'UI' + bl_category = 'Tool' -def menu_func(self, context): - self.layout.operator("vse.add_text_drop_shadow") + def draw(self, context): + layout = self.layout + layout.operator("vse.add_text_drop_shadow") def register(): bpy.utils.register_class(AddTextDropShadowOperator) - bpy.types.SEQUENCER_MT_strip.append(menu_func) - -def unregister(): - bpy.utils.unregister_class(AddTextDropShadowOperator) - bpy.types.SEQUENCER_MT_strip.remove(menu_func) - -if __name__ == "__main__": - register() + bpy.utils.register_class(TEXTDROPSHADOW_PT_panel) \ No newline at end of file