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

问题描述

我使用autolisp在Autodesk Forge中创建了一个捆绑应用,此脚本在dwg中搜索涉及布局的折线,并将每个折线导出到单独的pdf文件中。但是,脚本在执行过程中向我返回了一个错误,该错误表明export或plot命令被拒绝。在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. 目录名称应与“活动规范”中的LocalName参数的Result同步

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

活动规范:

{
  "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","localName": "7241.lsp"
    },"Result": {
      "zip": true,"verb": "put","localName": "outputs"
    }
  },"id": "mx.plotlisplayouts+prod","engine": "Autodesk.AutoCAD+24","settings": {
    "script": {
      "value": "(load \"7241.lsp\")\nRun7241\nMovepdfToOutPuts\n"
    }
  },"version": 1
}

WorkItem规范:

{
  "activityId": "mx.plotlisplayouts+prod","arguments": {
    "HostDwg": {
      "url": "https://xyz/open-v.dwg","verb": "get"
    },"LispFile": {
      "url": "https://xyz/7241.lsp","Result": {
      "url": "https://xyz?region=US","verb": "put"
    }
  }
}

预览 asciicast