Autodesk Forge 将 DWG 上的许多布局转换为 PDF

Autodesk Forge convert many layouts on DWG to PDF

我使用 autolisp 在 Autodesk Forge 中创建了一个捆绑应用程序,此脚本在 dwg 中搜索涉及布局的折线,并将每条折线导出到单独的 pdf 文件。但是脚本 returns 在执行过程中对我来说是一个错误,这个错误表明导出或绘图命令被拒绝。在 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 服务可以为您压缩该目录。

  1. 您需要在脚本中创建一个目录
  2. 将 pdf 文件移动到新创建的目录。
  3. 目录名称应与 Activity 规范
  4. Result 参数的 LocalName 同步

Lisp 代码:

(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)
  )
)

Activity规格:

{
  "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"
    }
  }
}

预览