Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
向 ComfyUI 顶部菜单栏添加自定义命令,包括加入现有菜单、创建子菜单,以及将同一命令放在多个位置。
app.registerExtension({ name: "MyExtension", // 定义命令 commands: [ { id: "myCommand", label: "我的命令", function: () => { alert("命令已执行!"); } } ], // 将命令添加到菜单 menuCommands: [ { path: ["扩展", "我的扩展"], commands: ["myCommand"] } ] });
id
label
function
{ id: string, // 命令的唯一标识符 label: string, // 命令显示名称 function: () => void // 命令被触发时执行的函数 }
menuCommands
{ path: string[], // 表示菜单层级的数组 commands: string[] // 要添加到该位置的命令 ID 数组 }
path
["文件", "导出"]
app.registerExtension({ name: "MenuExamples", commands: [ { id: "saveAsImage", label: "另存为图片", function: () => { // 保存画布为图片的代码 } }, { id: "exportWorkflow", label: "导出工作流", function: () => { // 导出工作流的代码 } } ], menuCommands: [ // 添加到文件菜单 { path: ["文件"], commands: ["saveAsImage", "exportWorkflow"] } ] });
app.registerExtension({ name: "SubmenuExample", commands: [ { id: "option1", label: "选项 1", function: () => { console.log("选项 1"); } }, { id: "option2", label: "选项 2", function: () => { console.log("选项 2"); } }, { id: "suboption1", label: "子选项 1", function: () => { console.log("子选项 1"); } } ], menuCommands: [ // 创建嵌套菜单结构 { path: ["扩展", "我的工具"], commands: ["option1", "option2"] }, { path: ["扩展", "我的工具", "高级"], commands: ["suboption1"] } ] });
app.registerExtension({ name: "MultiLocationExample", commands: [ { id: "helpCommand", label: "获取帮助", function: () => { window.open("https://docs.example.com", "_blank"); } } ], menuCommands: [ // 添加到帮助菜单 { path: ["帮助"], commands: ["helpCommand"] }, // 也添加到扩展菜单 { path: ["扩展"], commands: ["helpCommand"] } ] });