Created
March 13, 2025 20:16
-
-
Save promto-c/46d280a20e50e8a0b5c8a421e0e9fe5d to your computer and use it in GitHub Desktop.
SilhouetteFX's Script - Sets the selected layer (or its parent if it's a shape) as the stabilize layer, clears it if it's the active layer, and centers the selection in the viewer.
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
"""Copyright (C) 2020 promto-c | |
Permission Notice: | |
- You are free to use, copy, modify, and distribute this software for any purpose. | |
- No restrictions are imposed on the use of this software. | |
- You do not need to give credit or include this notice in your work. | |
- Use at your own risk. | |
- This software is provided "AS IS" without any warranty, either expressed or implied. | |
- This license does not cover any third-party libraries or dependencies used in this software. Those libraries are subject to their respective licenses. | |
""" | |
import fx | |
import hook | |
def set_stabilize_layer(): | |
"""Sets the selected layer as the stabilize layer. | |
If the selected layer is a shape, it will set the parent layer as the stabilize layer. | |
If the selected layer is the active layer, the stabilize layer will be set to None. | |
""" | |
# Return if no layer is selected | |
selected_layers = fx.selection() | |
if not selected_layers: | |
return | |
layer = selected_layers[0] | |
# If the selected layer is a shape, use the parent layer | |
if isinstance(layer, fx.Shape): | |
layer = layer.parent | |
# Return if the layer is not a Layer | |
if not isinstance(layer, fx.Layer): | |
return | |
# Set the layer as active if it's not already | |
if layer != fx.activeLayer(): | |
fx.setActiveLayer(layer) | |
# If the viewer layer is the same as the active layer, set it to None; otherwise, set to the current layer | |
fx.viewer.layer = None if fx.viewer.layer == layer else layer | |
# Center the selection in the viewer | |
fx.viewer.centerSelection() | |
# If the selected layer is a shape, select the parent layer | |
if layer and layer.property('pointer') and isinstance(layer.parent, fx.Layer): | |
fx.select([layer.parent]) | |
# Bind the function to the 'd' key | |
fx.bind("d", set_stabilize_layer) | |
# NOTE: If it doesn't work, uncomment the line below to bind the function to the 'd' key after startup | |
# hook.add("startupComplete", lambda: fx.bind("d", set_stabilize_layer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment