Guest Posted December 3, 2021 Posted December 3, 2021 Now work !!! But i dont like the idea to give manualy the number of pages. Anyway Thanks for the time !!!! ;;Insert all pdf pages of a file ;;assumes single row at 8-1/2" spacing ;;Demo only ;;D.C. Broad, Jr. 2012 ;;Warning: Once started, cannot be escaped from till done. (defun c:atall (/ fn n pt) (setq spacing 8.5) ;; spacing between sheets in inches. Modify as required. (setq fn (getfiled "Select PDF File" "" "pdf" 8)) ;;fn: PDF File Name (setq pagecount (getint "Enter Number of Pages")) (setq n 1) (setq pt (getpoint "Insertion Point"));;prompt for insertion point here (repeat pagecount (not (vl-catch-all-error-p ;avoid error trigger (vl-catch-all-apply '(lambda () (command "-pdfattach" fn (itoa n) pt 1 0) ) nil ) ) ) (setq n (1+ n)) (setq pt (list (+ (car pt) spacing) (cadr pt) (caddr pt))) ) (command);cancel out of index pdf underlay (princ);quietly exit ) Quote
mhupp Posted December 4, 2021 Posted December 4, 2021 (edited) 6 hours ago, prodromosm said: Now work !!! But i dont like the idea to give manualy the number of pages. Anyway Thanks for the time !!!! @prodromosm Show Steven P some love for tracking down the problem by hitting a few bottom right of his posts. How about I replace all of PDFPageCount function with 3 lines of code? This will loop with the while command until LastEntity ThisEntity are equal. aka the pdfattach command didn't attach anything last loop. (defun c:atall (/ *error* fn n pt LL UR objwid LastEntity ThisEntity) (setq fn (getfiled "Select PDF File" "" "pdf" 8) n 1 pt (getpoint "Insertion Point") LastEntity T ) (setvar 'cmdecho 0) (while (not (equal LastEntity ThisEntity)) (setq LastEntity (entlast)) (command "-pdfattach" fn n "_non" pt 1 0) (setq ThisEntity (entlast)) (vla-getboundingbox (vlax-ename->vla-object ThisEntity) 'minpt 'maxpt) (setq LL (vlax-safearray->list minpt) UR (vlax-safearray->list maxpt) objwid (- (car UR) (car LL)) pt (polar LL 0 (+ objwid 1)) n (1+ n) ) ) (setvar 'cmdecho 1) (princ) ) --Edit-- Cut down the spam with cmdecho. Cant seem to suppress the error msg. When its trying to insert a page that isn't there. Edited December 4, 2021 by mhupp 2 Quote
StevJ Posted December 4, 2021 Posted December 4, 2021 55 minutes ago, mhupp said: @prodromosm Show Steven P some love for tracking down the problem by hitting a few bottom right of his posts. How about I replace all of PDFPageCount function with 3 lines of code? This will loop with the while command until LastEntity ThisEntity are equal. aka the pdfattach command didn't attach anything last loop. (defun c:atall (/ fn n pt LL UR objwid LastEntity ThisEntity) (setq fn (getfiled "Select PDF File" "" "pdf" 8) n 1 pt (getpoint "Insertion Point") LastEntity T ) (while (not (equal LastEntity ThisEntity)) (setq LastEntity (entlast)) (command "-pdfattach" fn n "_non" pt 1 0) (setq ThisEntity (entlast)) (vla-getboundingbox (vlax-ename->vla-object (entlast)) 'minpt 'maxpt) (setq LL (vlax-safearray->list minpt) UR (vlax-safearray->list maxpt) objwid (- (car UR) (car LL)) pt (polar LL 0 (+ objwid 1)) n (1+ n) ) ) (command) (princ) ) That works perfectly in Autocad 2014. Thanks to you and Steven P for your efforts. Cheers and beers all around. Steve 1 Quote
Guest Posted December 4, 2021 Posted December 4, 2021 mhupp and StevJ codes work. The loop dont stop in Autocad 2022 . Need to press esc to stop , but works better than the first code. Thanks Quote
StevJ Posted December 4, 2021 Posted December 4, 2021 (edited) Yes it's true that it wants to put down page 1 again at the end, but pressing ESC will quit the program. Because I always press ESC at the end of a lisp routine, I didn't notice this at first. But it is a minor issue, and is insignificant when compared to what this gem of a program can now do for us. Steve Edited December 4, 2021 by StevJ spellin errers Quote
mhupp Posted December 4, 2021 Posted December 4, 2021 (edited) Man Autocad is getting weirder and weirder with lisps. if i use that lisp in Bricscad with a 5 page pdf It will insert pages 1,2,3,4,5, try and input page 6 fail with error because 6 isn't there to insert. the while command will then have page 5 as LastEntity & ThisEntity and exit out of the loop. I guess if you go over the page count in Autocad it defaults back to 1 instead of failing? Can someone testing that? (command "-pdfattach" "path to pdf with //" # '(0 0 0) 1 0) Edited December 4, 2021 by mhupp Quote
Guest Posted December 4, 2021 Posted December 4, 2021 I replace this line to last code and gives me this Command: ATALL Insertion Pointpath to pdf with // not found. 1 0 Quote
mhupp Posted December 4, 2021 Posted December 4, 2021 Don't do that. Was asking someone with Autocad to manually fill in that command but use a page number greater the the pdf has to see what it does. Quote
StevJ Posted December 4, 2021 Posted December 4, 2021 (edited) Using Autocad 2014. I input the following: (command "-pdfattach" "C:/users/Steve/Desktop/MIXED.PDF" 42 '(0 0 0) 1 0) This is a 15-page PDF. The result was an empty rectangle and a prompt to specify scale factor, then rotation, then it pastes sheet 1 and exits. Same results regardless of page number specified, so long as specified page is greater than the PDF contains. Tested again with Autocad 2020. Same results. Steve Edited December 5, 2021 by StevJ Even more info. 1 Quote
Steven P Posted December 4, 2021 Posted December 4, 2021 2 hours ago, mhupp said: Man Autocad is getting weirder and weirder with lisps. if i use that lisp in Bricscad with a 5 page pdf It will insert pages 1,2,3,4,5, try and input page 6 fail with error because 6 isn't there to insert. the while command will then have page 5 as LastEntity & ThisEntity and exit out of the loop. I guess if you go over the page count in Autocad it defaults back to 1 instead of failing? Can someone testing that? (command "-pdfattach" "path to pdf with //" # '(0 0 0) 1 0) Tried just that line that in AutoCAD, it accepts the path to PDF OK, and then it gets upset at # (being larger than the number of pages) "There is no # in PDF Enter page number or [?]" so it moves on and selects the point "There is no 0,0 in PDF Enter page number or [?]" Now it selects page 1 (which is the 1 from scale, it will insert page 2 if you change 'scale' to 2) Now it selects 0 as insertion point (the last point you used?) Then it pauses asking for scale factor Then it pauses asking for rotation Then it inserts the sheet So the "default back to page 1" is actually it picking up the scale. 1 Quote
Steven P Posted December 4, 2021 Posted December 4, 2021 I am not an expert in the below, just having a random guess..... Something I just read that might be something, might not be. The pagecount LISP and another I just looked at are looking in the PDF for a text pattern 'pages' ? I think So if the OPs PDF doesn't have 'page'' it can't find it in the PDF when it searches - and the result is 'nil' (see above for what the LISPS were telling us). Just a guess though I have been looking and can't find a PDF without page numbering.. however this is assuming English language 'page' what would be the case if we used another language for the PDF? Personal question time Prodromosm - is English your first language or is your PDF created in another language? and what is the word for 'page' Just a guess...... 1 Quote
mhupp Posted December 5, 2021 Posted December 5, 2021 Sound like all educated guesses to me @Steven P So Autocad gives the user another chance to input the correct number. where Bricscad says "Error: PDF underlay page not found." and exit the command. 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.