首页 > 解决方案 > 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)

标签: autodesk-forgeautodesk

解决方案


该图是学生图,只是一个友好的建议,您不应该在生产环境中使用。你的脚本就像魅力一样,我只是做了一些调整。我们期待一堆 pdf,因此我们需要将其移动到某个目录,DA 服务可以为您压缩该目录。

  1. 您需要在脚本中创建一个目录
  2. 将pdf文件移动到新创建的目录。
  3. 目录名称应与活动规范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"
    }
  }
}

预览 asciiccast


推荐阅读