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

Plotting a frame as block

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
MOHIRTAN
822 Views, 15 Replies

Plotting a frame as block

Hi all,

I use a script to print all blocks with name "!MineMyA1-".

I got a file "Orginal2Print" from a post and modified it.

Then I pasted the frame named "!MineMyA1-" to my drawing "Destination2Print".

I use a script "Demo2pdf" via AP command then calling demo command to print all "!MineMyA1-" blocks:

It works perfectly in Orginal2Print file, but for my file "Destination2Print" it give three blank sheets

Please, how to make the lisp work in my file "Destination2Print".

Files and lisp are in the attachments

This is the used code:

 

 

(vl-load-com)
(defun c:demo (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "!MineMyA1-"))))
        (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 full bleed A3 (420.00 x 297.00 MM)"  ;Paper Size
                         "Millimeters" ;Paper Units
                         "Landscape" ;Orientation
                         "No" ;Plot Upside Down?
                         "Window" ;Plot Area
                         llpt ;x coordinate
                         urpt ;y coordinate
                         "Fit" ;Plot Scale
                         "Center" ;Plot Offset
                         "yes" ;Plot With Plotstyle?
                         "monochrome.ctb" ;Plot Style Name
                         "yes"
                         ""                )
                (if (/= (car x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)

 

 

 

The post is relted to this post:

batch-plot-to-pdf-in-model-space 

15 REPLIES 15
Message 2 of 16
ВeekeeCZ
in reply to: MOHIRTAN

You need to set WCS current.

Message 3 of 16
MOHIRTAN
in reply to: MOHIRTAN

Thank you very much

Message 4 of 16
Moshe-A
in reply to: MOHIRTAN

@MOHIRTAN hi,

 

that is because you switched from wcs and the DEMO command does not support other from wcs

 

replace these two lines of the code:

line 38:  (trans llpt  0 1)  ;x coordinate
line 39:  (trans urpt 0 1)  ;y coordinate

 

now it will work 🤣

 

moshe

 

 

Message 5 of 16
MOHIRTAN
in reply to: MOHIRTAN

Magnificent, thanks a lot

Message 6 of 16
MOHIRTAN
in reply to: MOHIRTAN

For reference this is the modified script for : "DWG TO PDF.PC3" profile:

 

(vl-load-com)
(defun c:Demo (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "!MineMyA1-"))))
        (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 full bleed 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)
)

 

 

Message 7 of 16
paullimapa
in reply to: MOHIRTAN

FYI, I remember modifying this code on another post to accommodate for multiple rows and columns of the block so the pdf generated are sorted in proper order. Here's the code with that modification:

 

(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)
)

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 16
MOHIRTAN
in reply to: paullimapa

Thanks a MILLION

Message 9 of 16
paullimapa
in reply to: MOHIRTAN

Glad to have helped... cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 16
MOHIRTAN
in reply to: MOHIRTAN

Please help me modify this code to work:
The problems are in line 12, 13 and 81

(vl-load-com)
(defun c:democ (/ bas dwg file hnd i len llpt lst mn mx ss tab urpt)

  (setq blk1 (entsel "Select first block: "))
  (setq blk1name (cdr (assoc 2 (entget (car blk1)))))

  (setq blk2 (entsel "Select second block: "))
  (setq blk2name (cdr (assoc 2 (entget (car blk2)))))

  (setq blk3 (entsel "Select third block: "))
  (setq blk3name (cdr (assoc 2 (entget (car blk3)))))
  (setq blocks3all (strcat "\"" blk1name "," blk2name "," blk3name "\"" ))
     (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . blocks3all))))

        (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 (cadr y))  (car (cadr x))))))
            (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 (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
                         "pdfFactory Pro"
                         "A3"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         (trans llpt  0 1)  ;x coordinate
                         (trans urpt 0 1) ;y coordinate
                         "Fit"
                         "Center"
                         "yes"
                         "monochrome.ctb"
                         "Yes"
                         "" 
                         "No"
                         "No"
                         "Yes"
                )
                (if (/= (car x) "Model") 
                    (command 
                      "No"
                      "No"
                      file
                      "no"
                      "Yes"
                    ) 
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
                
            ;; Draw red rectangle around block  
      (command "rectangle" (trans llpt 0 1) (trans urpt 0 1) 
      (setq ent (entlast))
      (entmod ent (list (cons 62 1)))



            )
        )
    )
    (princ)

)

 

Message 11 of 16
paullimapa
in reply to: MOHIRTAN

why are you surrounding the block names with "\" ?

 

 

  (setq blocks3all (strcat "\"" blk1name "," blk2name "," blk3name "\"" ))
     (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . blocks3all))))

 

and whenever you are filtering a variable in this case the block name you'll have to change the ssget function:

 

  (setq blocks3all (strcat blk1name "," blk2name "," blk3name))
     (if (setq ss (ssget "_X" (list'(0 . "INSERT") (cons 2 blocks3all))))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 16
Kent1Cooper
in reply to: MOHIRTAN

Line 13 uses the "quoted list" format [starting with an apostrophe before the opening left parenthesis] including a variable name that requires evaluation, which is not permitted within a quoted list.  When something inside the list needs to be evaluated, you must use the explicit (list) function:

     (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blocks3all))))

Note that the object type entry is a quoted list within, because everything in it is to be taken literally [no evaluation needed].

Read about both the (list) and (quote) functions in the >AutoLisp Reference<.

 

If line 81 is trying to change the color of 'ent' to red, you can't (entmod) an entity name, but an entity data list [again -- read about the function in the AutoLisp Reference].  And you can't just give it the entry for the color, but must add it to the original list [appended at the end it will overrule the earlier entry].  If that's the way you want to do it, it should be:

(entmod (append (entget ent) (list (cons 62 1))))
 -
or
 -
(entmod (append (entget ent) '((62 . 1))))

but there are easier ways, such as:

(setpropertyvalue ent "Color" 1)
Kent Cooper, AIA
Message 13 of 16
MOHIRTAN
in reply to: MOHIRTAN

@paullimapa  & @Kent1Cooper Thank you very much:

This the modified code:

(vl-load-com)
(defun c:democ (/ bas dwg file hnd i len llpt lst mn mx ss tab urpt)

  (setq blk1 (entsel "Select first block: "))
  (setq blk1name (cdr (assoc 2 (entget (car blk1)))))

  (setq blk2 (entsel "Select second block: "))
  (setq blk2name (cdr (assoc 2 (entget (car blk2)))))

  (setq blk3 (entsel "Select third block: "))
  (setq blk3name (cdr (assoc 2 (entget (car blk3)))))
  (setq blocks3all (strcat blk1name "," blk2name "," blk3name))
     (if (setq ss (ssget "_X" (list'(0 . "INSERT") (cons 2 blocks3all))))
        (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 (cadr y))  (car (cadr x))))))
            (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 (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
                         "pdfFactory Pro"
                         "A3"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         (trans llpt  0 1)  ;x coordinate
                         (trans urpt 0 1) ;y coordinate
                         "Fit"
                         "Center"
                         "yes"
                         "monochrome.ctb"
                         "Yes"
                         "" 
                         "No"
                         "No"
                         "Yes"
                )
                (if (/= (car x) "Model") 
                    (command 
                      "No"
                      "No"
                      file
                      "no"
                      "Yes"
                    ) 
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
                
            ;; Draw red rectangle around block  
      (command "rectangle" (trans llpt 0 1) (trans urpt 0 1) )
      (setq ent (entlast))
        (entmod (append (entget ent) '((62 . 1))))
         (command "_.draworder" ent "" "_front")
            )
        )
    )
    (princ)

)

 

Message 14 of 16
Sea-Haven
in reply to: MOHIRTAN

Is there a reason you are not using layouts makes this task so much easier, you can do stuff like pick a point on objects enter a scale and a layout with viewport is made. Then just plot range of layouts a lisp.

Message 15 of 16
MOHIRTAN
in reply to: MOHIRTAN

@Sea-HavenThanks for your hint, I am happy with this script. Later, I will try to learn layouts stuff again.

Message 16 of 16
harikus
in reply to: MOHIRTAN

(foreach x lst
                (setq file (strcat (getvar 'DWGPREFIX)
                                   (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
                                   "-"
                                   (itoa (setq i (1+ i)))
                                   ".pdf"
                           )

Hello,
I was going through this pattern. But can we integrate pdf naming into attribute tag names ?

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