Insert multi page PDF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to create a function to automatically insert multi-page pdf documents into AutoCAD.
Should be simple, but I can't get AutoCAD to recognize that it has reached the last page of the pdf document or set a variable to the total number of pages in the pdf document. It works as is but you have to escape out of it's failure to insert the non-existant page after the last page. Would like an elegent automatic way out before distributing this to other users.
Here's what I've got:
(defun c:PDF ()
(setq fname (getfiled "Select PDF to Insert" (getvar 'dwgprefix) "pdf" 0))
(setq ipoint (getpoint "select insertion point"))
(setq pagenum 1)
(setq pagetotal 15) ; is there a system variable that can give me the actual number?
(while (< pagenum pagetotal)
(setq catchit (vl-catch-all-apply '(lambda () (command "-pdfattach" fname pagenum ipoint 1 0 ))))
(if (vl-catch-all-error-p catchit) (setq pagenum pagetotal) (setq pagenum (+ pagenum 1))) ; apparently no more pages is not an error
(setq ipoint (list (car ipoint) (- (cadr ipoint) 8.5)))
) ;while
) ;PDF