PhotoShop中创建窗口使用对应按钮创建对应图层简单示例

server/2025/2/13 6:56:13/

以前在使用Photoshop的PSD文件转换成Unity的UI Prefab工具的时候,想过是否能在PhotoShop中创建“组件”方式创建层,然后通过代码给层做重命名,不需要手动改写层的名字,可以直接创建所需数量的图层并按照层级排列,具体思路如下:

本文是尝试实现的记录:

首先生成一个对话框,并生成按钮,点击按钮会生成图层:

代码:

// 创建一个新的对话框
var dialog = new Window('dialog', '自定义生成器');// 创建Button按钮
var buttonButton = dialog.add('button', undefined, 'Button图层');
buttonButton.onClick = function () {createButtonLayer();
};// 创建Text按钮
var textButton = dialog.add('button', undefined, 'Text图层');
textButton.onClick = function () {createTextLayer();
};// 创建Image按钮
var imageButton = dialog.add('button', undefined, 'Image图层');
imageButton.onClick = function () {createImageLayer();
};// 创建列表按钮(这里假设是一个简单的按钮,点击后创建一个名为List的图层)
var listButton = dialog.add('button', undefined, 'List图层');
listButton.onClick = function () {createListLayer();
};// 创建Button图层的函数
function createButtonLayer() {var doc = app.activeDocument;var newLayer = doc.artLayers.add();newLayer.name = 'Button图层';// 设置Button图层的填充颜色为灰色var fillColor = new SolidColor();fillColor.rgb.red = 128;fillColor.rgb.green = 128;fillColor.rgb.blue = 128;newLayer.fillColor = fillColor;
}// 创建Text图层的函数
function createTextLayer() {var doc = app.activeDocument;var textLayer = doc.artLayers.add();textLayer.name = 'Text图层';// 将图层转换为文本图层var textItem = textLayer.textItem;textItem.contents = '默认文本内容';textItem.size = 12;textItem.color = new SolidColor();textItem.color.rgb.red = 0;textItem.color.rgb.green = 0;textItem.color.rgb.blue = 0;
}// 创建Image图层的函数
function createImageLayer() {var doc = app.activeDocument;var newLayer = doc.artLayers.add();newLayer.name = 'Image图层';// 这里假设你有一个名为image.jpg的图片资源在脚本同目录下var imageFile = new File(File.desktop + '/image.jpg');if (imageFile.exists) {var placedLayer = doc.importFile(imageFile, new LayerPosition(AnchorPosition.MIDDLECENTER));placedLayer.name = 'Image图层';} else {alert('指定的图片文件不存在。');}
}// 创建List图层的函数
function createListLayer() {var doc = app.activeDocument;var newLayer = doc.artLayers.add();newLayer.name = 'List图层';// 设置List图层的填充颜色为浅蓝色var fillColor = new SolidColor();fillColor.rgb.red = 173;fillColor.rgb.green = 216;fillColor.rgb.blue = 230;newLayer.fillColor = fillColor;
}// 显示对话框
dialog.show();

结果:

未完待续。。。


http://www.ppmy.cn/server/167263.html

相关文章

大模型deepseek-r1 本地快速搭建

1、安装部署ollama 详细步骤见:Ollama 下载和安装 官网下载地址:Ollama官网 2、大模型Deepseekk-r1下载 详细步骤见:大模型deepseek-r1 本地ollama部署详解 ollama run deepseek-r13、Open WebUI部署详解 详细见步骤:大模型d…

DeepSeek+图生生:电商制作商品图的高效方案,适合大众生图的AI工具

在电商红海竞争中,商品视觉呈现已成为流量争夺的核心战场。然而,传统拍摄模式面临多重瓶颈,成本高昂、效率低下等。 而DeepSeek与图生生的结合使用,正以“AI提示词智能生图”的协作模式,为商家提供零成本、分钟级、高…

蓝桥杯---N字形变换(leetcode第6题)题解

文章目录 1.问题重述2.例子分析3.思路讲解4.代码分析 1.问题重述 这个题目可以是Z字形变换,也可以叫做N字形变换: 给定我们一串字符,我们需要把这串字符按照先往下写,再往右上方去写,再往下去写,再往右上…

Python使用OpenCV图片去水印多种方案实现

1. 前言 本文为作者学习记录,使用Python结合OpenCV,总结了几种常见的水印去除方式,简单图片去水印效果良好,但是复杂图片有点一言难尽,本文部分代码仅供参考,并不能针对所有水印通用,需要根据具…

人生的转折点反而迷失了方向

就像我老婆说的,我是抽空结了一个婚。今天是上班的第三天,不知道是出于何种原因,自己反而陷入了深深的困境,没有了斗志,原因也找不出来,白天在公司没有很大量的产出,晚上回去是想学一学&#xf…

leetcode 移除元素

题目 题解 1、双指针 // 时间复杂度&#xff1a;O(n) // 空间复杂度&#xff1a;O(1) class Solution { public:int removeElement(vector<int>& nums, int val) {int slowIndex 0;for (int fastIndex 0; fastIndex < nums.size(); fastIndex) {if (val ! num…

防火墙是什么?详解网络安全的关键守护者

当今信息化时代&#xff0c;企业和个人在享受数字生活带来的便利时&#xff0c;也不可避免地面对各种潜在的风险。防火墙作为网络安全体系中的核心组件&#xff0c;就像一道牢不可破的防线&#xff0c;保护着我们的数据和隐私不受外界威胁的侵害。那么防火墙是什么&#xff1f;…

LVS 负载均衡集群(NAT模式)

一、环境准备 四台主机&#xff08;一台 LVS、两台 RS、一台客户端&#xff09; 1.1.LVS 主机 LVS 主机&#xff08;两块网卡&#xff09; 第一块&#xff1a;NAT模式&#xff08;内网&#xff09; 第二块&#xff1a;添加网卡&#xff08;仅主机模式&#xff09;&#xff0…