I created a bundle app in Autodesk Forge using an autolisp, this script searches the dwg for polylines that involve layouts and exports each of these to a separate pdf file. However the script returns an error to me during execution, this error says that the export or plot command was rejected. Is there any correct way to do this in Forge or some other command that I can export these layouts to PDF?
Below the script in use ...
(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)
The drawing is a Student drawing, just a friendly suggestion, you shouldn't be using in production environments. Your script works like charm, I just made some tweaks. We are expecting a bunch of pdfs, so we need to move it some directory, DA service can zip that directory for you.
LocalName
of Result
parameter in Activity specLisp code:
(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 Spec:
{
"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
}
WorkItem Spec:
{
"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"
}
}
}