From 543e35a3651a72b9e5c0974b57d25dc45c148825 Mon Sep 17 00:00:00 2001 From: maxwelljones14 Date: Sun, 14 Sep 2025 16:43:23 -0400 Subject: [PATCH] added solid color fill layer functionality --- mcp/ps-mcp.py | 22 ++++++++++ uxp/ps/commands/fill_layers.js | 77 ++++++++++++++++++++++++++++++++++ uxp/ps/commands/index.js | 4 +- 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 uxp/ps/commands/fill_layers.js diff --git a/mcp/ps-mcp.py b/mcp/ps-mcp.py index 1c44de3..b7e6ba9 100644 --- a/mcp/ps-mcp.py +++ b/mcp/ps-mcp.py @@ -874,6 +874,28 @@ def create_pixel_layer( return sendCommand(command) +@mcp.tool() +def create_fill_layer( + layer_name: str, + color: dict = {"red": 255, "green": 255, "blue": 255}, + opacity: int = 100 +): + """Creates a new solid color fill layer with the specified name, color, and opacity. + + Args: + layer_name (str): Name of the new fill layer being created + color (dict): RGB color values for the fill layer. Format: {"red": 0-255, "green": 0-255, "blue": 0-255} + opacity (int): Opacity of the fill layer (0-100) + """ + + command = createCommand("createFillLayer", { + "layerName": layer_name, + "color": color, + "opacity": opacity + }) + + return sendCommand(command) + @mcp.tool() def create_multi_line_text_layer( layer_name:str, diff --git a/uxp/ps/commands/fill_layers.js b/uxp/ps/commands/fill_layers.js new file mode 100644 index 0000000..14aaa09 --- /dev/null +++ b/uxp/ps/commands/fill_layers.js @@ -0,0 +1,77 @@ +/* MIT License + * + * Copyright (c) 2025 Mike Chambers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +const { action } = require("photoshop"); + +const { + execute, + parseColor +} = require("./utils") + +const createFillLayer = async (command) => { + let options = command.options; + let layerName = options.layerName; + let opacity = options.opacity || 100; + let color = options.color || {"red": 255, "green": 255, "blue": 255}; + + await execute(async () => { + let commands = [ + // Create fill layer + { + _obj: "make", + _target: [ + { + _ref: "contentLayer", + }, + ], + using: { + _obj: "contentLayer", + name: layerName, + opacity: { + _unit: "percentUnit", + _value: opacity, + }, + type: { + _obj: "solidColorLayer", + color: { + _obj: "RGBColor", + red: color.red, + grain: color.green, + blue: color.blue, + }, + }, + }, + }, + ]; + + await action.batchPlay(commands, {}); + }); +}; + +const commandHandlers = { + createFillLayer +} + +module.exports = { + commandHandlers +}; diff --git a/uxp/ps/commands/index.js b/uxp/ps/commands/index.js index 4bf7aa8..2e8388a 100644 --- a/uxp/ps/commands/index.js +++ b/uxp/ps/commands/index.js @@ -30,6 +30,7 @@ const layerStyles = require("./layer_styles") const filters = require("./filters") const selection = require("./selection") const layers = require("./layers") +const fillLayers = require("./fill_layers") const parseAndRouteCommands = async (commands) => { if (!commands.length) { @@ -76,7 +77,8 @@ const commandHandlers = { ...core.commandHandlers, ...adjustmentLayers.commandHandlers, ...layerStyles.commandHandlers, - ...layers.commandHandlers + ...layers.commandHandlers, + ...fillLayers.commandHandlers }; module.exports = {