Created
October 26, 2024 14:33
-
-
Save qtaped/4315b9ea4868f9824f440b87677d9e67 to your computer and use it in GitHub Desktop.
This file contains 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
// Create a new window for the UI | |
var myWindow = new Window("palette", "applyScale"); | |
// Add a checkbox for resizing stroke width | |
var resizeStrokeCheckbox = myWindow.add("checkbox", undefined, "Resize Stroke Width"); | |
var mathRoundText = myWindow.add("checkbox", undefined, "Math Round Text Size"); | |
resizeStrokeCheckbox.value = true; | |
// Add a button to the window | |
var myButton = myWindow.add("button", undefined, "Adjust Scale"); | |
// Define the button's onClick function | |
myButton.onClick = function() { | |
// Get the selected layers | |
var selectedLayers = app.project.activeItem.selectedLayers; | |
// Begin an undo group | |
app.beginUndoGroup("Adjust Scale"); | |
// Loop through each selected layer | |
for (var i = 0; i < selectedLayers.length; i++) { | |
var layer = selectedLayers[i]; | |
// Check if the layer is a text layer | |
if (layer instanceof TextLayer) { | |
// Get the current scale and font size | |
var currentScale = layer.transform.scale.value[0]; // Assuming uniform scale | |
var currentFontSize = layer.text.sourceText.value.fontSize; | |
// Calculate the new font size | |
var newFontSize = currentFontSize * currentScale / 100; | |
if (mathRoundText.value) { | |
newFontSize = Math.round(newFontSize) | |
} | |
// Set the scale to 100% | |
layer.transform.scale.setValue([100, 100, 100]); | |
// Create a new TextDocument with the updated font size | |
var textDoc = layer.text.sourceText.value; | |
textDoc.fontSize = newFontSize; // Update the font size | |
// Check if the checkbox is selected before updating stroke width | |
if (resizeStrokeCheckbox.value) { | |
var currentStrokeWidth = layer.text.sourceText.value.strokeWidth; | |
var newStrokeWidth = currentStrokeWidth * (currentScale / 100); | |
if (mathRoundText.value) { | |
newStrokeWidth = Math.round(newStrokeWidth) | |
} | |
textDoc.strokeWidth = newStrokeWidth; | |
} | |
// Set the new TextDocument back to the layer | |
layer.text.sourceText.setValue(textDoc); | |
} else if (layer instanceof AVLayer && layer.source instanceof FootageItem && !layer.source.file) { | |
// Get the current scale | |
var currentXScale = layer.transform.scale.value[0]; | |
var currentYScale = layer.transform.scale.value[1]; | |
// Calculate the new size based on the scale | |
var newWidth = Math.round(layer.source.width * (currentXScale / 100)); | |
var newHeight = Math.round(layer.source.height * (currentYScale / 100)); | |
// Reset scale to 100% | |
layer.transform.scale.setValue([100, 100, 100]); | |
// Update the solid source dimensions | |
layer.source.width = newWidth; | |
layer.source.height = newHeight; | |
} else if (layer instanceof AVLayer && layer.source instanceof CompItem) { | |
// Get the current scale | |
var currentXScale = layer.transform.scale.value[0]; | |
var currentYScale = layer.transform.scale.value[1]; | |
// Calculate the new size based on the scale | |
var newWidth = Math.round(layer.source.width * (currentXScale / 100)); | |
var newHeight = Math.round(layer.source.height * (currentYScale / 100)); | |
// Reset scale to 100% | |
layer.transform.scale.setValue([100, 100, 100]); | |
// Update the solid source dimensions | |
layer.source.width = newWidth; | |
layer.source.height = newHeight; | |
alert(layer.name + " is a comp.") | |
} else { | |
// Set the scale to 100% for non-text layers | |
alert(layer.name + " is not a solid or a text layer.") | |
} | |
} | |
// End the undo group | |
app.endUndoGroup(); | |
}; | |
// Show the window | |
myWindow.center(); | |
myWindow.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment