Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sorting batch plotting blocks

1 REPLY 1
SOLVED
Reply
Message 1 of 2
MOHIRTAN
251 Views, 1 Reply

Sorting batch plotting blocks

hi ALL,

I use this script to plot all blocks named "!MineMyA". However, I do not know the order the script plot the blocks.

Please can you modify the script to plot in the y direction (from top to bottom) without caring for x direction.

For example, in the attached drawing it polts the blocks in the order of its creation or insertation as I noticed.

This is the used script ( it is attached as well)

(vl-load-com)
(defun c:Demoy (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "!MineMyA"))))
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      lst (cons (cons tab hnd) lst)
                )
            )
            (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
            (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)
                (setq llpt (vlax-safearray->list mn)
                      urpt (vlax-safearray->list mx)
                      len  (distance llpt (list (car urpt) (cadr llpt)))
                )
                (command "-plot"
                         "yes" ;Detailed Plot Configuration?
                         (car x) ;layout
                         "DWG TO PDF.PC3" ;Printer Name
                         "ISO expand A3 (420.00 x 297.00 MM)"  ;Paper Size
                         "Millimeters" ;Paper Units
                         "Landscape" ;Orientation
                         "No" ;Plot Upside Down?
                         "Window" ;Plot Area
                         (trans llpt  0 1) ;x coordinate
                         (trans urpt 0 1) ;y coordinate
                         "Fit" ;Plot Scale
                         "Center" ;Plot Offset
                         "yes" ;Plot With Plotstyle?
                         "monochrome.ctb" ;Plot Style Name
                         "Yes" ;Plot Lineweights?
                         "" ;Enter shade plot setting ["As displayed"/"Wireframe"/"Hidden"/"Visual styles"/"Rendered"]
                )
                (if (/= (car x) "Model") ;Automatic pdf file name
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no" ;Save changes to page setup
                        "Yes" ;Proceed with plot
                    )
                )
            )
        )
    )
    (princ)
)

Thank you

 

1 REPLY 1
Message 2 of 2
MOHIRTAN
in reply to: MOHIRTAN

Thank you @paullimapa for your solution it worked very well

This topic is solved after renaming my block from '!MineMyA" to "!MineMyA1-"

THIS TOPIC IS SOLVED

I am sorry for any inconvenience.

This the solution script'

 

(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 . "!MineMyA1-"))))
;    (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"  ;Detailed Plot Configuration?
                         (car x) ;layout
                         "DWG TO PDF.PC3" ;Printer Name
;                         "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)"  ;Paper Size
                         "Millimeters" ;Paper Units
                         "Landscape"  ;Orientation
                         "No"     ;Plot Upside Down?
                         "Window"  ;Plot Area
                         (trans llpt  0 1)  ;x coordinate
                         (trans urpt 0 1)   ;y coordinate
                         "Fit" ;Plot Scale
;                         "1:10"
                         "Center" ;Plot Offset
                         "yes" ;Plot With Plotstyle?
;                         "grayscale.ctb"
;                         "Screening 75%.ctb"
                         "monochrome.ctb" ;Plot Style Name
                         "yes" ;Plot Lineweights?
                         "" ;Enter shade plot setting ["As displayed"/"Wireframe"/"Hidden"/"Visual styles"/"Rendered"]
                )
                (if (/= (car x) "Model") 
                    ; layout tab
                    (command 
                      "No" ;Plot paper space first? 
                      "No" ;Hide paperspace objects?
                      file ;Automatic pdf file name
                      "no"  ;Save changes to page setup
                      "Yes" ;Proceed with plot
                    ) 
                    ; model tab
                    (command
                        file ;Automatic pdf file name
                        "no" ;Save changes to page setup
                        "Yes" ;Proceed with plot
                    )
                )
            )
        )
    )
    (princ)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report