autodesk-forge - Autodesk Forge 将 DWG 上的许多布局转换为 PDF
问题描述
我使用 autolisp 在 Autodesk Forge 中创建了一个捆绑应用程序,此脚本在 dwg 中搜索涉及布局的多段线,并将其中的每一条导出到单独的 pdf 文件中。但是脚本在执行过程中向我返回了一个错误,这个错误表示导出或绘图命令被拒绝。在 Forge 或其他可以将这些布局导出为 PDF 的命令中是否有任何正确的方法可以做到这一点?
在正在使用的脚本下方...
(setq sel (ssget "x"
(list (cons 0 "LWPOLYLINE")
(cons 70 1)
(cons 8 "Defpoints")
)
)
)
(if (/= sel nil)
(setq count (sslength sel))
(setq count 0)
)
(setq i 0)
(setq difx nil)
(setq pts (list 0))
(setvar "demandload" 3)
(repeat count
(setq el (ssname sel i))
(setq en (entget el))
(setq coords nil)
(foreach item en
(setq tmp (car item))
(if (= tmp 10)
(setq coords (append coords (list (cdr item))))
)
)
(setq pt1 (nth 0 coords))
(setq pt2 (nth 1 coords))
(setq pt3 (nth 2 coords))
(setq difx (distance pt1 pt3))
(setq label (ssget "_CP"
coords
(list (cons 0 "TEXT") (cons 8 "Border Text"))
)
)
(if (/= label nil)
(setq title (cdr (assoc 1 (entget (ssname label 0)))))
(setq title "NO_NAME")
)
(command "-EXPORT"
"p"
"w"
pt1
pt3
"n"
(strcat title ".pdf")
)
(setq i (+ i 1))
)
(princ)
解决方案
该图是学生图,只是一个友好的建议,您不应该在生产环境中使用。你的脚本就像魅力一样,我只是做了一些调整。我们期待一堆 pdf,因此我们需要将其移动到某个目录,DA 服务可以为您压缩该目录。
- 您需要在脚本中创建一个目录
- 将pdf文件移动到新创建的目录。
- 目录名称应与活动规范
LocalName
中的参数同步Result
语言代码:
(defun c:Run7241 ()
(setq sel (ssget "x"
(list (cons 0 "LWPOLYLINE")
(cons 70 1)
(cons 8 "Defpoints")
)
)
)
(if (/= sel nil)
(setq count (sslength sel))
(setq count 0)
)
(setq i 0)
(setq difx nil)
(setq pts (list 0))
;(setvar "demandload" 3)
(repeat count
(setq el (ssname sel i))
(setq en (entget el))
(setq coords nil)
(foreach item en
(setq tmp (car item))
(if (= tmp 10)
(setq coords (append coords (list (cdr item))))
)
)
(setq pt1 (nth 0 coords))
(setq pt2 (nth 1 coords))
(setq pt3 (nth 2 coords))
(setq difx (distance pt1 pt3))
(setq label (ssget "_CP"
coords
(list (cons 0 "TEXT") (cons 8 "Border Text"))
)
)
(if (/= label nil)
(setq title (cdr (assoc 1 (entget (ssname label 0)))))
(setq title "NO_NAME")
)
(command "-EXPORT"
"p"
"w"
pt1
pt3
"n"
(strcat title ".pdf")
)
(setq i (+ i 1))
)
(princ)
)
(defun c:MovepdfToOutPuts ()
;get current directory
(setq curDir (getvar "dwgprefix"))
;make new directory outputs, should be in sync with LocalName in activity
(setq outputs "outputs")
(vl-mkdir outputs)
;move each file to output diretory
(foreach x (vl-directory-files curDir "*.pdf")
(setq file (strcat curDir "/" x))
(setq newFile (strcat curDir "/" outputs "/" x))
(princ newFile)
(vl-file-rename file newFile)
)
)
活动规格:
{
"commandLine": [
"$(engine.path)\\accoreconsole.exe /i $(args[HostDwg].path) /s $(settings[script].path)"
],
"parameters": {
"HostDwg": {
"verb": "get",
"required": true,
"localName": "test.dwg"
},
"LispFile": {
"verb": "get",
"required": true,
"localName": "7241.lsp"
},
"Result": {
"zip": true,
"verb": "put",
"required": true,
"localName": "outputs"
}
},
"id": "mx.plotlisplayouts+prod",
"engine": "Autodesk.AutoCAD+24",
"settings": {
"script": {
"value": "(load \"7241.lsp\")\nRun7241\nMovepdfToOutPuts\n"
}
},
"version": 1
}
工作项规格:
{
"activityId": "mx.plotlisplayouts+prod",
"arguments": {
"HostDwg": {
"url": "https://xyz/open-v.dwg",
"verb": "get"
},
"LispFile": {
"url": "https://xyz/7241.lsp",
"verb": "get"
},
"Result": {
"url": "https://xyz?region=US",
"verb": "put"
}
}
}
推荐阅读
- apache-kafka - 在 Kafka Producer Java API 中使用票证缓存
- java - 在 Subclipse 中提交 Java 文件和包含包的删除
- visual-studio-2019 - Visual Studio 2019 IDE 关于 String.Format 参数的警告
- python - Python 不会写入我创建的 SQL 表,而是创建另一个
- java - 指定为非 null 的 Java 参数为 null IllegalException
- c# - 如何将 Microsoft xsd.exe 与 TrainingCenterDatabasev2 架构一起使用?
- javascript - 为什么 Intl.NumberFormat 不适用于 Safari 和 Firefox 中的单位?
- r - ggplot,对同一个图同时使用 vjust 和 hjust,如何编码?
- r - 如何在 R 中进行引导分布?
- python - Flask 应用程序 - 错误 404,在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试