Please help me,
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Solved by hmsilva. Go to Solution.
Thanks for the quick link . I did exactly as mentioned in the link , I opened notepad and copied the same script saved it as "pdf.lsp"
Unfortunately after loading the lisp file in CAD and I happened to type Demo in Command Line - nothing happened 🙄 .
Something will only happen if in the drawing you have a block insert with name A1- as can be read at beginning of lisp code:
(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1-")))) (progn
😐
Can you help me with this , here is an example dwg which I am working on .
1. your drawing is a created by a Student version of AutoCAD. I suggest you no longer use this drawing since that would just spread throughout all your other drawings.
2. you could have just renamed the title block from TTL BLK 2ND SHT to A1- and then Demo lisp command would work.
3.from examining the drawing, it's set as Architectural Inches. But reading the title block info, it's supposed to be in MM.
4. there's a Shape file I'm missing so the pdf I created with Demo may look different than the actual drawing with the correct Shape file.
5. I modified the lisp code so that it will work on your title block: TTL BLK 2ND SHT, ISO A1 size sheet, Scale 1:10 & your currently set ctb file: "Screening 75%.ctb
See attached compressed zip file for documents.
@paullimapa sorry for the late reply ,it was weekend I did not have access to this PC.
Thanks a lot for the modified lisp 😋 ,I was able to convert the drawings to pdf.
Few things noted :
1) First sheet of the Example dwg is not converted to pdf (only 4 pages , starting from 2nd sheet were converted)
2) Converted pages were not in order (Attached actual requirement for your ref.)
3) Upon comparing the actual pdf with the lisp pdf - lines/fonts/blocks in the actual pdf are darker, how can I achieve something similar to this ?
4) The gap between Title block edges and page borders are more (marked in red) , is it possible to reduce these gaps ?
Can we select each title blocks and then use lisp command (vice versa) to convert pdfs ? , the reason being when there is a revision/modification the actual dwgs are copied below the orginal ones and revised (please have a look attached dwg) . By doing so the lisp command might not select the revised dwgs .
There are ways to get around to resolve your requirements without doing much more lisp coding.
But you've left out the most important information of all such as:
1. Provide the steps you take to manually create a PDF of one of these sheets that would meet your requirements ie: Sheet Size A1 or A2, name of ctb file that would make the lines match your requirements, plot scale, 1:15 or Fit, origin 0,0 or to center? All this information would need to be included in the lisp code like the way I've done it for you before.
2. What program if any do you have to modify individual pdf files such as Adobe Acrobat or Bluebeam? Acrobat for example provides the option to combine individual PDFs and re-order the pages into a single multi-page PDF file.
3. Would it be a problem for the original drawing sheets after you've copied them below to have Title blocks that are exploded so they won't be included when the Demo lisp code runs? You can also Undo the Explode after the PDFs are created.
4. Since the first sheet has a different title block name instead of the same title block name as the others, this is why Demo lisp code did not pick this up. Remember the Demo lisp code was originally written to accommodate for a single title block name A1- which I modified to accommodate only for a single title block name in your drawing. You can always make a copy of Demo and call it Demo1 and modify the code there to pick up the first sheet title block name.
1) Sheet size -ISO full bleed A4 (297 x 210), Plot style - most of the time it is "monochrome.ctb" and very rare "None", Plot scale - Fit , Origin-Center the plot
2) I use Adobe acrobat to modify pdfs , Yes this gives option to combine individual pdfs and re arrange but the automatic naming/numbering of pdf using the lisp code is from last sheet to 2nd sheet (Example-1.pdf is last sht , Example-2.pdf is 2nd last sht and so on)
3) Even I thought the same to explode the Title blocks and then use lisp code and undo the explode , but unfortunately title blocks couldn't be exploded also there might be morethan 30-40 revisions for each drawings . Is there any alternate way ?
4) I tried modifying the codes , but then when I saved and executed the command line mentions (unknown command "yes". press F1 for help)
Below is the modified demo lisp code. Now you can select objects on the screen using window, crossing or even select one at a time and it will only select the two title blocks "TTL BLK 1ST SHT" & "TTL BLK 2ND SHT" that you want to plot, then sort the selection by base insertion point of the blocks x coordinate, and generate the pdf named with the left title block as Example-1.pdf proceeding in naming sequence to the right.
(vl-load-com)
(defun c:demo (/ bas dwg file hnd i len llpt lst mn mx ss tab urpt)
; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1-"))))
; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TTL BLK 2ND SHT"))))
(if (setq ss (ssget (list (cons 0 "INSERT") (cons 2 "TTL BLK 1ST SHT,TTL BLK 2ND SHT"))))
(progn
(repeat (setq i (sslength ss))
(setq hnd (ssname ss (setq i (1- i)))
tab (cdr (assoc 410 (entget hnd)))
bas (cdr (assoc 10 (entget hnd))) ; get insert base point
lst (cons (cons tab (cons bas hnd)) lst) ; include insert base point
)
)
; (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
; sort by blocks insert base point x
(setq lst (vl-sort lst '(lambda (x y) (> (car (cadr y)) (car (cadr x))))))
(setq i 0)
(foreach x lst
(setq file (strcat (getvar 'DWGPREFIX)
(substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
"-"
(itoa (setq i (1+ i)))
".pdf"
)
)
(if (findfile file)
(vl-file-delete file)
)
; (vla-getboundingbox (vlax-ename->vla-object (cdr x)) 'mn 'mx)
(vla-getboundingbox (vlax-ename->vla-object (cddr x)) 'mn 'mx)
(setq llpt (vlax-safearray->list mn)
urpt (vlax-safearray->list mx)
len (distance llpt (list (car urpt) (cadr llpt)))
)
(command "-plot"
"yes"
(car x)
"DWG TO PDF.PC3"
; "ISO A3 (420.00 x 297.00 MM)"
; "ISO A1 (841.00 x 594.00 MM)"
"ISO full bleed A4 (297.00 x 210.00 MM)"
"Millimeters"
"Landscape"
"No"
"Window"
llpt
urpt
"Fit"
; "1:10"
"Center"
"yes"
; "grayscale.ctb"
; "Screening 75%.ctb"
"monochrome.ctb"
"yes"
""
)
(if (/= (car x) "Model")
(command "No" "No" file "no" "Yes")
(command
file
"no"
"Yes"
)
)
)
)
)
(princ)
)
@paullimapa Thanks a lot 😋 . This lisp is a life saver , very much useful .
Also can you have a look at the attached pdfs , when there are multiple pages we copy title blocks to the next row . There are dwgs in model space with more than 50 sheets , one issue which I found using the above lisp code for multiple sheet dwgs are the pdfs generated are not in order (I know this is due to "base insertion point of the blocks x coordinate, and generate the pdf named with the left title block" ). Do you have any solution for this ?
I even tried plotting the 1st row and then the 2nd row but pdfs generated from the 2nd row overwrites the pdfs generated by the 1st row . Is there any alternative way ?
One quick fix would be to just run Demo and select one row first then after those pdfs are created, combined them into a multipage pdf file. Then run Demo again on the 2nd row and repeat the same steps till you're done.
Thanks for the quick fix , well this just a temporary solution . Hope you will come up with a permanent solution asap 🙂.
" Thanking you once again for the Lisp code "
Unfortunately, I only know of a way to program the sorting method so that the x and the y coordinates both proceed in the same direction ie both positive or both negative. But I don't know of a sorting method so that one is positive and the other negative. In your case, the title block insert base x coordinate is in the positive direction (from left to right) but the y coordinate is in the negative direction (from top down). If your layout is where the y coordinate is also positive (from down upward - see attached) then the following code would work. Perhaps others monitoring this thread can jump in and save the day?
(vl-load-com)
(defun c:demo (/ bas dwg file hnd i len llpt lst mn mx ss tab urpt)
; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1-"))))
; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TTL BLK 2ND SHT"))))
(if (setq ss (ssget (list (cons 0 "INSERT") (cons 2 "TTL BLK 1ST SHT,TTL BLK 2ND SHT,TTL_BLK_1ST_SHT"))))
(progn
(repeat (setq i (sslength ss))
(setq hnd (ssname ss (setq i (1- i)))
tab (cdr (assoc 410 (entget hnd)))
bas (cdr (assoc 10 (entget hnd))) ; get insert base point
lst (cons (cons tab (cons bas hnd)) lst) ; include insert base point
)
)
; (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
; sort by blocks insert base point x
(setq lst (vl-sort lst '(lambda (x y) (< (car (cadr y)) (car (cadr x))))))
; sort by blocks insert base point y
(setq lst (vl-sort lst '(lambda (x y) (> (cadr (cadr y)) (cadr (cadr x))))))
(setq i 0)
(foreach x lst
(setq file (strcat (getvar 'DWGPREFIX)
(substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
"-"
(itoa (setq i (1+ i)))
".pdf"
)
)
(if (findfile file)
(vl-file-delete file)
)
; (vla-getboundingbox (vlax-ename->vla-object (cdr x)) 'mn 'mx)
(vla-getboundingbox (vlax-ename->vla-object (cddr x)) 'mn 'mx)
(setq llpt (vlax-safearray->list mn)
urpt (vlax-safearray->list mx)
len (distance llpt (list (car urpt) (cadr llpt)))
)
(command "-plot"
"yes"
(car x)
"DWG TO PDF.PC3"
; "ISO A3 (420.00 x 297.00 MM)"
; "ISO A1 (841.00 x 594.00 MM)"
"ISO full bleed A4 (297.00 x 210.00 MM)"
"Millimeters"
"Landscape"
"No"
"Window"
llpt
urpt
"Fit"
; "1:10"
"Center"
"yes"
; "grayscale.ctb"
; "Screening 75%.ctb"
"monochrome.ctb"
"yes"
""
)
(if (/= (car x) "Model")
(command "No" "No" file "no" "Yes") ; pspace
(command file "no" "Yes") ; model
)
)
)
)
(princ)
)
So I figured out the problem. The Title Blocks in your drawing are not perfectly aligned in the Y position. The first one on the left is actually a bit lower and the last one on the right is a lot higher causing the Demo code's sort order process to not function properly when selecting Title Blocks on the bottom rows. To resolve the issue you would have to manually move the first & last Title Blocks so that the Insertion point aligns with the other Title Blocks in between (see attached revised drawing in zip file). I've also revised the Demo code so that it will now properly generate all the Title Blocks (once they are correctly positioned) to generate the PDFs in expected order sequence.
(vl-load-com)
(defun c:demo (/ bas dwg file hnd i len llpt lst mn mx ss tab urpt)
; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1-"))))
; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TTL BLK 2ND SHT"))))
(if (setq ss (ssget (list (cons 0 "INSERT") (cons 2 "TTL BLK 1ST SHT,TTL BLK 2ND SHT,TTL_BLK_1ST_SHT"))))
(progn
(repeat (setq i (sslength ss))
(setq hnd (ssname ss (setq i (1- i)))
tab (cdr (assoc 410 (entget hnd)))
bas (cdr (assoc 10 (entget hnd))) ; get insert base point
lst (cons (cons tab (cons bas hnd)) lst) ; include insert base point
)
)
; (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
; sort by blocks insert base point x ascending = from left right
(setq lst (vl-sort lst '(lambda (x y) (> (car (cadr y)) (car (cadr x))))))
; sort by blocks insert base point y descending = from top down
(setq lst (vl-sort lst '(lambda (x y) (< (cadr (cadr y)) (cadr (cadr x))))))
(setq i 0)
(foreach x lst
(setq file (strcat (getvar 'DWGPREFIX)
(substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
"-"
(itoa (setq i (1+ i)))
".pdf"
)
)
(if (findfile file)
(vl-file-delete file)
)
; (vla-getboundingbox (vlax-ename->vla-object (cdr x)) 'mn 'mx)
(vla-getboundingbox (vlax-ename->vla-object (cddr x)) 'mn 'mx)
(setq llpt (vlax-safearray->list mn)
urpt (vlax-safearray->list mx)
len (distance llpt (list (car urpt) (cadr llpt)))
)
(command "-plot"
"yes"
(car x)
"DWG TO PDF.PC3"
; "ISO A3 (420.00 x 297.00 MM)"
; "ISO A1 (841.00 x 594.00 MM)"
"ISO full bleed A4 (297.00 x 210.00 MM)"
"Millimeters"
"Landscape"
"No"
"Window"
llpt
urpt
"Fit"
; "1:10"
"Center"
"yes"
; "grayscale.ctb"
; "Screening 75%.ctb"
"monochrome.ctb"
"yes"
""
)
(if (/= (car x) "Model")
(command "No" "No" file "no" "Yes") ; pspace
(command file "no" "Yes") ; model
)
)
)
)
(princ)
)
I tried the new code , the pdfs generated are as attached .
Am I doing anything wrong ?
That’s very strange. Did you get these results from the revised example drawing I included in the zip file? In any case the key is to make sure all the y coordinates are the same. But try moving the left (first in the row) title block a bit higher (like 10mm) in the y coordinate so the sort method will always place that first in generating the pdf for that row.
"Try moving the left (first in the row) title block a bit higher (like 10mm) in the y coordinate so the sort method will always place that first in generating the pdf for that row" - this did the trick , Thanks👍🏻 .
I tried this lisp on another dwg where the title blocks dimension are different (I know this is not the proper way , but this is how my colleagues have been preparing dwgs for years), here are the results .
Problem most likely is the same. The insert base points y coordinate on the title blocks are not lined up in each row. Hard to see until you draw a line horizontally across and zoom in really close. If you like attach the sample drawing for me to take a look.
The problem is as I've stated. The Title Blocks base insertion point on the Y coordinate is off on some of the Title Blocks from the Line drawn. Unless you zoom in really close, you won't see this. So I've added a Circle around the Title Blocks insertion point and placed it on Defpoints layer so it won't plot. Now you can zoom way out and be able to select the insertion point by using the Center object snap option to properly place the Title Blocks so they all align on the same Y coordinate to sort properly. Lisp Code can do a lot. But when it comes to errors like this, it is very hard to catch.
To automate the Title Block alignment process I went on-line and searched using the following phrase:
"autolisp to align block insert"
One of the links that came up directed me to the following discussion thread:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-align-all-blocks/td-p/5000334
; Credits to Steve Maher
(defun c:blkalign (/ OS ss albl alpt alpty ctr ename inpt inptx inpty newpt)
(setq OS (getvar "OSMODE"))
(setvar "OSMODE" 0)
(princ "\nSelect blocks or text to align horizontaly evenly: ")
; (setq ss (ssget))
(setq ss (ssget (list (cons 0 "INSERT") (cons 2 "TTL BLK 1ST SHT,TTL BLK 2ND SHT,TTL_BLK_1ST_SHT"))))
(setq albl (entsel "\nSelect text or block to align with: "))
(setq albl (car albl))
(setq alpt (cdr (assoc 10 (entget albl))))
(setq alpty (cadr alpt))
(setq ctr 0)
(while
(setq ename (ssname ss ctr))
(setq inpt (cdr (assoc 10 (entget ename))))
(setq inptx (car inpt) )
(setq inpty (cadr inpt))
(setq newpt (list inptx alpty))
(command "_.move" ename "" inpt newpt)
(setq ctr (+ ctr 1))
)
(setvar "OSMODE" OS)
)
Can't find what you're looking for? Ask the community or share your knowledge.