LISP for attaching PDFs

LISP for attaching PDFs

Anonymous
Not applicable
1,514 Views
3 Replies
Message 1 of 4

LISP for attaching PDFs

Anonymous
Not applicable

I have a directory with hundreds of TIF and PDF files - all need some AutoCad work done and it would take very long to create a dwg for each of them manually.

 

I have found a lisp routine to attach all .tif files from a folder, but I'm not sure how to make it work for pdfs.

Source of the lisp routine: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-program-for-placing-tiff-images...

 

{code}
(defun c:MakeDrawingsFromImages (/ FullPath DirPath ImList dbxApp oVer dbxMs dbxDictCol dbxIm dbxImDict *error*)

(vl-load-com)
(defun *error* (msg) (vl-bt))
(if
(and
(setq FullPath (getfiled "Select image file in directory to use." "" "tif" 4))
(setq DirPath (vl-filename-directory FullPath))
(setq ImList (vl-directory-files DirPath "*.tif" 1))
(setq dbxApp
(if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
(vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
(vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
)
)
(setq dbxMs (vla-get-ModelSpace dbxApp))
(setq dbxDictCol (vla-get-Dictionaries dbxApp))
)
(foreach name ImList
(setq dbxIm (vlax-invoke dbxMs 'AddRaster (strcat DirPath "\\" name) '(0.0 0.0 0.0) 1.0 0.0))
(vla-put-Name dbxIm (vl-filename-base name))
(vla-put-ScaleFactor dbxIm 1.0)
(vla-SaveAs dbxApp (strcat DirPath "\\" (vl-filename-base name) ".dwg"))
(setq dbxImDict (vla-Item dbxDictCol "ACAD_IMAGE_DICT"))
(vla-Delete dbxIm)
(vla-Delete (vla-Item dbxImDict 0))
(vla-Delete dbxImDict)
)
)
(mapcar
'(lambda (x)
(vl-catch-all-apply 'vlax-release-object x)
)
'(dbxImDict dbxIm dbxDictCol dbxMs dbxApp)
)
(princ)
)
{code}
0 Likes
1,515 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Have not yet been able to figure this out

0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

Can be done simply using pdfattach pretty sure it was like (command "-pdfattach" name etc

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/insert-all-pdfs/td-p/3404837

0 Likes
Message 4 of 4

Anonymous
Not applicable

Have this so far

{code}
(defun c:MakeDwg(/ FullPath DirPath ImList dbxApp oVer dbxMs dbxIm *error*)

(vl-load-com)
(defun *error* (msg) (vl-bt))
(if
(and
(setq FullPath (getfiled "Select image file in directory to use." "" "pdf" 4))
(setq DirPath (vl-filename-directory FullPath))
(setq ImList (vl-directory-files DirPath "*.pdf" 1))
(setq dbxApp
(if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
(vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
(vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
)
)
(setq dbxMs (vla-get-ModelSpace dbxApp))
)
(foreach name ImList
(setq dbxIm (vlax-invoke dbxMs (command "-pdfattach" (strcat DirPath "\\" name) "1" "0, 0, 0" "1" "0")))
(vla-put-Name dbxIm (vl-filename-base name))
(vla-SaveAs dbxApp (strcat DirPath "\\" (vl-filename-base name) ".dwg"))
(vla-Delete dbxIm)
)
)
(mapcar
'(lambda (x)
(vl-catch-all-apply 'vlax-release-object x)
)
'(dbxIm dbxMs dbxApp)
)
(princ)
)
{code}

Gives the following error:

Command: Backtrace:
[0.55] (VL-BT)
[1.51] (*ERROR* "bad argument type: (or stringp symbolp): nil")
[2.46] (_call-err-hook #<SUBR @000001f0aa9ab7a0 *ERROR*> "bad argument type: (or stringp symbolp): nil")
[3.40] (sys-error "bad argument type: (or stringp symbolp): nil")
:ERROR-BREAK.35 nil
[4.32] (IDispatch.Invoke #<VLA-OBJECT IAcadModelSpace 000001f0e01a1a38> nil 1)
[5.25] (vlax-invoke #<VLA-OBJECT IAcadModelSpace 000001f0e01a1a38> nil)
[6.19] (C:MAKEDWG)
[7.15] (#<SUBR @000001f0aa9ab9d0 -rts_top->)
[8.12] (#<SUBR @000001f0aa888700 veval-str-body> "(c:makedwg)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
0 Likes