APS Automation API中LISP与AppBundle运行异常及字体适配问题
APS Automation API 图纸转PDF字体适配问题排查与优化方案
问题描述
尝试在APS Automation API中通过AppBundle运行LISP脚本,引入SHX/TTF字体文件解决默认API不支持的字体适配问题,实现图纸转PDF。首次尝试时TTF字体成功安装,但LISP脚本无法被找到,日志显示LOAD失败、命令未识别;多次修改配置后,当前作业在下载阶段失败,提示DasZip错误,环境配置失败。
当前配置文件与结构
1. PackageContents.xml
<?xml version="1.0" encoding="utf-8"?> <ApplicationPackage SchemaVersion="1.0" AppVersion="1.0" Name="MyPackageName" Description="MyDescriptions" Author="MyAuthorName"> <Components> <RuntimeRequirements SupportPath="./Contents" OS="Win64" Platform="AutoCAD"> </RuntimeRequirements> <ComponentEntry ModuleName="./Contents/total.lsp" AppDescription="changing fonts and plot"> </ComponentEntry> <SupportPaths> <SupportPath>Contents</SupportPath> <SupportPath>Contents/Fonts</SupportPath> <SupportPath>Contents/Support</SupportPath> <SupportPath>Contents/Scripts</SupportPath> </SupportPaths> </Components> </ApplicationPackage>
2. Bundle文件结构
MyBundle | +--PackageContents.xml | +--Contents | +--total.lsp | +--Fonts | +--ghs.shx +--ghd.shx +--gulim.ttf
3. total.lsp
(defun c:START ( / ss i ent entData) (if (not (tblsearch "style" "KOREAN_STYLE")) (progn (entmake (list (cons 0 "STYLE") (cons 2 "KOREAN_STYLE") (cons 3 "simplex.shx") (cons 4 "ghs.shx") (cons 40 0.0) (cons 50 0.8) (cons 70 0) ) ) ) ) (setq ss (ssget "_X" '((0 . "TEXT,MTEXT,ATTRIB,ATTDEF")))) (if ss (progn (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (setq entData (entget ent)) (entmod (subst (cons 7 "KOREAN_STYLE") (assoc 7 entData) entData)) (setq i (1+ i)) ) ) ) (command "_ZOOM" "E") (command "-PLOT" "Y" "AutoCAD PDF (Web and Mobile).pc3" "ISO_full_bleed_A3_(420.00_x_297.00_MM)" "M" "L" "N" "Extents" "Fit" "Center" "Y" "monochrome.ctb" "Y" "A" "input.pdf" "N" "Y") (princ "\n[Complete: KOREAN_STYLE + PDF Plot]") (princ) )
4. Activity配置
{ "commandLine": [ "$(engine.path)\\accoreconsole.exe /i \"$(args[inputFile].path)\" /al \"$(appbundles[PlotWithFonts].path)\" /s \"$(settings[script].path)\"" ], "parameters": { "inputFile": { "zip": false, "ondemand": false, "verb": "get", "description": "Input drawing file", "localName": "input.dwg" }, "outputFile":{ "zip":false, "ondemand":false, "verb":"put", "localName":"input.pdf" } }, "engine": "Autodesk.AutoCAD+25_0", "appbundles": [ "{{dasNickName}}.{{dasAppBundleName}}+{{dasAppBundleAlias}}" ], "settings": { "script": { "value": "(load \"total.lsp\")\n_START\n" } } }
问题排查与修复建议
1. DasZip错误(下载阶段失败)
- 检查AppBundle压缩包合规性:打包时不要包含根目录外的冗余文件,所有文件路径需与
PackageContents.xml映射一致;避免使用中文或特殊字符文件名,APS环境对路径字符兼容性有限。 - 验证AppBundle签名与版本:确认上传的AppBundle签名正确,版本号与Activity中
{{dasAppBundleAlias}}引用的版本匹配,版本不兼容会导致解压失败。
2. LISP脚本加载失败/命令未识别
- 修正PackageContents.xml配置:
新增LoadOnCommandInvocation="True"和CommandLine="START",让AutoCAD调用命令时自动加载LISP脚本,无需手动LOAD:<?xml version="1.0" encoding="utf-8"?> <ApplicationPackage SchemaVersion="1.0" AppVersion="1.0" Name="MyPackageName" Description="MyDescriptions" Author="MyAuthorName"> <Components> <RuntimeRequirements SupportPath="./Contents" OS="Win64" Platform="AutoCAD"> </RuntimeRequirements> <ComponentEntry ModuleName="./Contents/total.lsp" AppDescription="changing fonts and plot" LoadOnCommandInvocation="True" CommandLine="START"> </ComponentEntry> <SupportPaths> <SupportPath>Contents</SupportPath> <SupportPath>Contents/Fonts</SupportPath> </SupportPaths> </Components> </ApplicationPackage> - 调整Activity脚本逻辑:
移除手动LOAD步骤,直接调用命令:"settings": { "script": { "value": "_START\n" } } - 字体路径验证:
SupportPaths已配置Contents/Fonts,AutoCAD会自动扫描该目录,LISP中无需指定字体绝对路径。
3. 其他潜在问题
- 检查
accoreconsole.exe参数:确保/al指向的AppBundle路径与Activity中$(appbundles[PlotWithFonts].path)的别名匹配。 - 确认PDF输出一致性:LISP中
-PLOT命令的input.pdf需与Activity中outputFile的localName一致,确保文件能被正确上传。
更简便的中日韩汉图纸字体适配方案
1. 使用AutoCAD内置字体映射
在AppBundle中添加Support/fontmap.xml,将缺失字体映射到内置支持的中日韩字体,无需修改图纸样式:
<?xml version="1.0" encoding="utf-8"?> <FontMap> <Mapping OldFontName="ghs.shx" NewFontName="gulim.ttf"/> <Mapping OldFontName="ghd.shx" NewFontName="gulim.ttf"/> </FontMap>
AutoCAD打开图纸时会自动替换字体,简化流程。
2. 直接调用PDF导出命令
跳过LISP脚本,在Activity命令行中直接使用AutoCAD批处理打印参数,结合字体映射文件:
"commandLine": [ "$(engine.path)\\accoreconsole.exe /i \"$(args[inputFile].path)\" /fontmap \"$(appbundles[PlotWithFonts].path)\\Contents\\Support\\fontmap.xml\" /p \"AutoCAD PDF (Web and Mobile).pc3\" /layout \"*\" /output \"$(args[outputFile].path)\"" ]
内容的提问来源于stack exchange,提问作者myh
相关产品推荐
相关产品推荐

