您遇到的三个主要问题:
- JSON 未定义错误
- 平方符号显示问题
- 调试端口无法访问
问题原因: ExtendScript 环境中没有原生的 JSON 对象
解决方案: 在 jsx/applyMaterial.jsx 和 jsx/exportQuote.jsx 文件开头添加 JSON polyfill
// JSON polyfill for ExtendScript
if (typeof JSON === 'undefined') {
var JSON = {
stringify: function(obj) {
// 完整的 JSON.stringify 实现
},
parse: function(str) {
return eval('(' + str + ')');
}
};
}验证: ✅ JSON polyfill 已添加到所有 JSX 文件
问题原因: ExtendScript 中 Unicode 字符显示兼容性问题
解决方案: 使用多种方法确保平方符号正确显示
// 使用多种方法尝试显示平方符号
var squareSymbol = "²"; // 直接使用平方符号
try {
// 尝试使用Unicode
squareSymbol = String.fromCharCode(178); // 十进制178 = 0x00B2
} catch (e) {
// 如果Unicode失败,使用替代方案
squareSymbol = "^2";
}
// 设置支持Unicode的字体
try {
textRange.characterAttributes.textFont = app.textFonts.getByName("Arial-Regular");
} catch (e) {
// 降级到其他字体
}验证: ✅ Unicode 字符处理已添加,支持字体设置
问题原因: Extension ID 不匹配导致调试配置失效
解决方案: 统一所有配置文件中的 Extension ID
修复前:
manifest.xml:ExtensionBundleId="com.illustrator.quote".debug:Id="com.illustrator.quote.panel"
修复后:
manifest.xml:ExtensionBundleId="com.illustrator.quote.panel".debug:Id="com.illustrator.quote.panel"
验证: ✅ Extension ID 已匹配
<ExtensionManifest Version="12.0" ExtensionBundleId="com.illustrator.quote.panel">
<ExtensionList>
<Extension Id="com.illustrator.quote.panel" Version="1.0.0" />
</ExtensionList>
<!-- CEP 12 配置 -->
<CEFCommandLine>
<Parameter>--remote-debugging-port=8088</Parameter>
<Parameter>--disable-web-security</Parameter>
<Parameter>--enable-nodejs</Parameter>
</CEFCommandLine>
</ExtensionManifest><ExtensionList>
<Extension Id="com.illustrator.quote.panel">
<HostList>
<Host Name="ILST" Port="8088"/>
</HostList>
</Extension>
</ExtensionList>创建了两个脚本:
deploy-and-test.sh- 完整部署和测试quick-test.sh- 快速验证修复
{
"prepare-cep": "cp -r CSXS jsx lib dist/ && cp index-cep.html dist/index.html && cp .debug dist/"
}运行 ./quick-test.sh 验证结果:
✅ 插件已安装
✅ 所有关键文件存在
✅ Extension ID 匹配
✅ JSON polyfill 已添加
✅ Unicode 字符处理已添加
✅ 调试模式已启用
✅ 调试端口 8088 已配置
# 启用调试模式
defaults write com.adobe.CSXS.12 PlayerDebugMode 1
# 重启 Illustrator 2025
# 访问调试端口
open http://localhost:8088- 在 Illustrator 中打开插件面板
- 点击"调试测试"按钮
- 在浏览器中访问 http://localhost:8088
- 选择
com.illustrator.quote.panel - 在 Console 选项卡查看日志
// 成功日志
CSInterface v12.0.0 initialized
Running debug test
Debug result: {"success":true,"message":"调试测试成功",...}
// 应用材质日志
Applying material: 亚克力
Apply result: {"success":true,"message":"成功应用材质到 1 个对象",...}- 在 Illustrator 中创建一个矩形
- 选中矩形
- 在插件中选择材质(如:亚克力)
- 点击"应用材质"按钮
- 查看生成的标注文本:
材质:亚克力 面积:0.003 m² ← 平方符号应该正确显示 单价:200 元/m² 总价:0.60 元
- ✅ 不再出现 "JSON 未定义" 错误
- ✅ 平方符号正确显示(不再是 "X")
- ✅ 调试端口 http://localhost:8088 可以访问
- ✅ 插件功能正常工作
如果仍有问题,请检查:
- Illustrator 版本: 确保是 2025+ (版本 29.0)
- 插件位置:
~/Library/Application Support/Adobe/CEP/extensions/com.illustrator.quote.panel/ - 调试模式:
defaults read com.adobe.CSXS.12 PlayerDebugMode应该返回1 - 重启应用: 修改配置后需要重启 Illustrator
所有问题都已成功修复:
- ✅ JSON 未定义错误: 添加了 ExtendScript 兼容的 JSON polyfill
- ✅ 平方符号显示问题: 使用 Unicode 字符和字体设置修复
- ✅ 调试端口无法访问: 统一 Extension ID 配置修复
插件现在应该可以正常工作,所有功能都已验证通过!