You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:修复After Effects可停靠Script UI面板问题(功能正常)

解决After Effects脚本面板无法停靠的问题

问题说明

我是视频剪辑从业者,编程知识有限。之前通过ChatGPT获取了一款After Effects脚本UI面板,图层创建功能正常,但面板无法嵌入软件界面停靠。我尝试自行修改代码未果,希望将其改为可停靠面板,原代码如下:

// Function to create an adjustment layer
function createAdjustmentLayer() {
  var comp = app.project.activeItem; // Get the active composition
  if (comp && comp instanceof CompItem) {
    var adjustmentLayer = comp.layers.addSolid([1, 1, 1], "Adjustment Layer", comp.width, comp.height, 1);
    adjustmentLayer.adjustmentLayer = true;
  } else {
    alert("Please open or select a composition.");
  }
}

// Function to create a null layer
function createNullLayer() {
  var comp = app.project.activeItem; // Get the active composition
  if (comp && comp instanceof CompItem) {
    comp.layers.addNull();
  } else {
    alert("Please open or select a composition.");
  }
}

// Function to create a solid layer
function createSolidLayer() {
  var comp = app.project.activeItem; // Get the active composition
  if (comp && comp instanceof CompItem) {
    var solidLayer = comp.layers.addSolid([90, 31, 37], "Solid Layer", comp.width, comp.height, 1);
  } else {
    alert("Please open or select a composition.");
  }
}

// Create a dockable UI panel
var myPanel = new Window("palette", "LAYER CREATOR SIMPLE", undefined, { resizeable: true });
myPanel.orientation = "column";

var createAdjustmentButton = myPanel.add("button", undefined, "Adjustment Layer");
createAdjustmentButton.onClick = createAdjustmentLayer;

var createNullButton = myPanel.add("button", undefined, "Null Layer");
createNullButton.onClick = createNullLayer;

var createSolidButton = myPanel.add("button", undefined, "Solid Layer");
createSolidButton.onClick = createSolidLayer;

// Show the panel
myPanel.center();
myPanel.show();

修改后的可停靠面板代码

// 注册可停靠面板(唯一ID需确保不重复)
var panelID = "com.yourname.layerCreatorSimple";
var myPanel = app.registerScriptPanel(panelID, "LAYER CREATOR SIMPLE", true);

// 如果面板已存在,直接获取实例
if (!myPanel) {
  myPanel = app.getScriptPanel(panelID);
}

// 设置面板布局
myPanel.orientation = "column";
myPanel.alignChildren = ["fill", "top"];
myPanel.spacing = 10;
myPanel.margins = 10;

// 创建按钮并绑定事件
var createAdjustmentButton = myPanel.add("button", undefined, "调整图层");
createAdjustmentButton.onClick = function() {
  var comp = app.project.activeItem;
  if (comp && comp instanceof CompItem) {
    var adjustmentLayer = comp.layers.addSolid([1, 1, 1], "调整图层", comp.width, comp.height, 1);
    adjustmentLayer.adjustmentLayer = true;
  } else {
    alert("请打开或选中一个合成");
  }
};

var createNullButton = myPanel.add("button", undefined, "空对象图层");
createNullButton.onClick = function() {
  var comp = app.project.activeItem;
  if (comp && comp instanceof CompItem) {
    comp.layers.addNull();
  } else {
    alert("请打开或选中一个合成");
  }
};

var createSolidButton = myPanel.add("button", undefined, "纯色图层");
createSolidButton.onClick = function() {
  var comp = app.project.activeItem;
  if (comp && comp instanceof CompItem) {
    var solidLayer = comp.layers.addSolid([90, 31, 37], "纯色图层", comp.width, comp.height, 1);
  } else {
    alert("请打开或选中一个合成");
  }
};

// 显示面板
myPanel.show();

修改要点说明

  • 使用app.registerScriptPanel()注册面板:这是让AE识别并允许面板停靠的核心,需要传入唯一的面板ID、面板名称和是否允许停靠的参数。
  • 兼容面板已存在的情况:通过app.getScriptPanel()避免重复创建面板实例。
  • 优化布局设置:添加alignChildren、spacing和margins让面板布局更美观。
  • 中文按钮文本:根据需求替换为中文,也可保留英文。

内容的提问来源于stack exchange,提问作者simple editor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 08:54:53