remCAD Posted Tuesday at 09:11 AM Posted Tuesday at 09:11 AM I'm trying to write an Autolisp code to underlay images. It's built around the "-attach" command. When attaching a PDF you're asked for a page number (even if there's only one). I want my code to skip this step if there's only one page, default to 1 if there's more than one page & then default to 2, 3 etc. for multiple pages until there are no more (when it will go back to the select file dialogue). Problem is I cannot find how to check how many pages there are on the PDF. If, within AutoCAD, you type ? for page number then *, it lists all the pages, so AutoCAD can definitely check this before inserting the PDF, but I can't find any way of accessing this info. Any ideas? Quote
pkenewell Posted Tuesday at 06:56 PM Posted Tuesday at 06:56 PM (edited) Getting the pages is the tricky part. Give this a try: EDIT - Oh - this might not work since you have AutoCAD LT - no com access - sorry! I don't know if someone else has another method of getting the number of pages without accessing the windows shell? (defun c:pdfQatt (/ f pg) (if (setq f (getfiled "Select a PDF file to Attach" "" "pdf" 4)) (progn (if (/= (setq pg (cdr (assoc "Pages" (GetFileInfo f)))) "1") (setq pg (getint (strcat "Enter Page # (Total Pages: " pg ")"))) (setq pg 1) ) (command "._-attach" f pg pause 1.0 0.0) ) ) ) ;; Get a file's extended properties (Title, Subject, Category ...) ;; returning the result as a list of cons pairs: ;; Example: ;; ( ("Name" . "Drawing.dwg") ;; ("Size" . "42 KB") ;; ("Type" . "DWG File") ;; ("Date Modified" . "2011/03/21 10:57 AM") ;; ... ;; ) ;; Original Author: Michael Pucket ;; https://www.theswamp.org/index.php?topic=38072.0 (defun GetFileInfo ( file / result shell name_space items item ) (vl-load-com) (vl-catch-all-apply (function (lambda ( / folder_name file_name i count ) (setq folder_name (vl-filename-directory file) file_name (strcat (vl-filename-base file) (vl-filename-extension file)) shell (vlax-create-object "Shell.Application") name_space (vlax-invoke shell 'NameSpace folder_name) items (vlax-invoke name_space 'Items) item (vlax-invoke name_space 'ParseName file_name) i (setq count 300) ) (if item (repeat count (setq result (cons (cons (vlax-invoke name_space 'GetDetailsOf items (setq i (1- i))) (vlax-invoke name_space 'GetDetailsOf item i) ) result ) ) ) ) ) ) ) (vl-catch-all-apply 'vlax-release-object (list item)) (vl-catch-all-apply 'vlax-release-object (list items)) (vl-catch-all-apply 'vlax-release-object (list name_space)) (vl-catch-all-apply 'vlax-release-object (list shell)) (vl-remove-if (function (lambda (item) (eq "" (car item)))) result ) ) Edited Wednesday at 12:53 PM by pkenewell Quote
Lee Mac Posted Tuesday at 10:44 PM Posted Tuesday at 10:44 PM Here's an old function to determine the number of pages in a PDF file - https://www.theswamp.org/index.php?topic=39001.msg441632#msg441632 Quote
Lee Mac Posted Tuesday at 10:45 PM Posted Tuesday at 10:45 PM On 3/25/2025 at 6:56 PM, pkenewell said: (defun GetFileInfo ( file / result shell name_space items item ) (vl-load-com) (vl-catch-all-apply (function (lambda ( / folder_name file_name i count ) (setq folder_name (vl-filename-directory file) file_name (strcat (vl-filename-base file) (vl-filename-extension file)) shell (vlax-create-object "Shell.Application") name_space (vlax-invoke shell 'NameSpace folder_name) items (vlax-invoke name_space 'Items) item (vlax-invoke name_space 'ParseName file_name) i (setq count 300) ) (if item (repeat count (setq result (cons (cons (vlax-invoke name_space 'GetDetailsOf items (setq i (1- i))) (vlax-invoke name_space 'GetDetailsOf item i) ) result ) ) ) ) ) ) ) (vl-catch-all-apply 'vlax-release-object (list item)) (vl-catch-all-apply 'vlax-release-object (list items)) (vl-catch-all-apply 'vlax-release-object (list name_space)) (vl-catch-all-apply 'vlax-release-object (list shell)) (vl-remove-if (function (lambda (item) (eq "" (car item)))) result ) ) Expand This function was originally written by the late great Michael Puckett - https://www.theswamp.org/index.php?topic=38072.0 2 Quote
pkenewell Posted Wednesday at 12:54 PM Posted Wednesday at 12:54 PM On 3/25/2025 at 10:45 PM, Lee Mac said: This function was originally written by the late great Michael Puckett - https://www.theswamp.org/index.php?topic=38072.0 Expand Good Call Lee. I had lost the original author information on that code. Updated above and in my own stash to give him proper credit. Quote
pkenewell Posted Wednesday at 01:06 PM Posted Wednesday at 01:06 PM On 3/25/2025 at 10:44 PM, Lee Mac said: Here's an old function to determine the number of pages in a PDF file - https://www.theswamp.org/index.php?topic=39001.msg441632#msg441632 Expand Unfortunately. The OP is using AutoCAD LT 2025; I don't think this would work for him either since it makes a call to (vlax-create-object). I realized the same problem with the code I provided, as I stated in my original post. Quote
ronjonp Posted Wednesday at 08:43 PM Posted Wednesday at 08:43 PM (edited) On 3/25/2025 at 10:45 PM, Lee Mac said: This function was originally written by the late great Michael Puckett - https://www.theswamp.org/index.php?topic=38072.0 Expand I really miss that guy. ;/ He was such a witty kind person and one of the most talented lisp programmers I knew. Edited Wednesday at 09:12 PM by ronjonp 1 1 Quote
Lee Mac Posted Wednesday at 11:26 PM Posted Wednesday at 11:26 PM On 3/26/2025 at 8:43 PM, ronjonp said: I really miss that guy. ;/ He was such a witty kind person and one of the most talented lisp programmers I knew. Expand Ditto. I never knew it was possible to genuinely grieve the loss of someone you'd never met in person, but when I see an old post of his I'm reminded of just how much he contributed to the community and how much I miss our conversations. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.