How to plot all drawing (only layout) with current open drawing with tab with setting?

How to plot all drawing (only layout) with current open drawing with tab with setting?

skchui6159
Advocate Advocate
1,008 Views
15 Replies
Message 1 of 16

How to plot all drawing (only layout) with current open drawing with tab with setting?

skchui6159
Advocate
Advocate

I have write the autolisp for plot all layout, but I want to plot all opening drawing in AUTOCAD, anyone help?

 

(defun c:PRA(/ cmd)
(setq proc (substr (getvar "dwgname") 1 27))
(setq p1 (getpoint "\nPoint Left Coner"))
;;;(setq p1_x (car p1))
;;;(setq p1_y (cadr p1))
(setq p2 (getpoint "\nPoint Right Coner"))
;;;(setq p2_x (car p2))
;;;(setq p2_y (cadr p2))
;;;(setq p1final_x (rtos (p1_x) 2 2))
(foreach Layout (layoutlist)
(command "_plot"
"Y"; Detail Pot
Layout
"A1_ PDF.pc3" ; outputdevice name
"ISO A1 (841.00 x 594.00 MM)" ; Size
"M"; Milemeter
"L"; Landscape
"No"; Plot upside down
"W"; Plot area (Layout) W-by window
(strcat (rtos (car p1) 2 2) "," (rtos (cadr p1) 2 2)); Left Corner Coordinate
(strcat (rtos (car p2) 2 2) "," (rtos (cadr p2) 2 2)); Right Corner Coordinate
"1=1"; Plot scale "Fit <1=1>"
"" ; Plot offset (-5,10) ""="Centre to plot"
"Y"; Plot Style
"NR12NR-01_FP.ctb";Plot style name/"NR12NR-01 - Colour.ctb"
"Y"; Plot with lineweights
"Y" ;Scale lineweights with plot scale
"N"; Plot Paper space first
"N"; Hide paperspace object
(strcat (getvar "DWGPREFIX") proc "-" Layout ".pdf"); actually "" also ok
"N"; save change to page setup
"Y"; prcoeed with plot
);command end
); foreach end
);defun end

0 Likes
Accepted solutions (3)
1,009 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor
Accepted solution

@skchui6159 wrote:

I have write the autolisp for plot all layout, but I want to plot all opening drawing in AUTOCAD, anyone help?


Have you considered using Named Page Setups and publish for plotting?

0 Likes
Message 3 of 16

skchui6159
Advocate
Advocate

Thanks , but any method can I try to do the captioned action(Action on current opening drawing)?

0 Likes
Message 4 of 16

pbejse
Mentor
Mentor
Accepted solution

@skchui6159 wrote:

Thanks , but any method can I try to do the captioned action(Action on current opening drawing)?


Not sure what that means. @skchui6159, is it because you wanted to print/publish even though the file(s) are not saved yet?

 

Was referring to publish and named page setups

pbejse_0-1721737928293.png

 

or even Autopublishing, as long as you assign the correct page setup

 

pbejse_1-1721738200979.png

HTH

Message 5 of 16

skchui6159
Advocate
Advocate

Thank you very much

0 Likes
Message 6 of 16

pbejse
Mentor
Mentor

@skchui6159 wrote:

Thank you very much


You are welcome, Happy to help 

0 Likes
Message 7 of 16

skchui6159
Advocate
Advocate

A further question, how can I get the left corner and right corner coordinate of the drawing title block for automatically printing out?

0 Likes
Message 8 of 16

skchui6159
Advocate
Advocate

skchui6159_0-1730080194395.png

skchui6159_1-1730080206304.png

Block in layout.

0 Likes
Message 9 of 16

skchui6159
Advocate
Advocate

Or can I get the pick point of the block using lisp?

0 Likes
Message 10 of 16

skchui6159
Advocate
Advocate

(defun c:PRAA (/ cmd proc blknam ss1 i ent obj blkdata Tmatrix blk_pt) (vl-load-com) ;; Get the first 27 characters of the current drawing name (setq proc (substr (getvar "dwgname") 1 27)) ;; Set the block name to search for (setq blknam "-TITLE_A1_DETAIL") ;; Iterate through all layouts (foreach Layout (layoutlist) ;; Find the specified block name (if (setq ss1 (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat blknam ",`*U*")) '(66 . 1)))) (progn (setq i 0) ;; Iterate through all found blocks (repeat (sslength ss1) (setq ent (ssname ss1 i) obj (vlax-ename->vla-object ent)) ;; Confirm that the block name matches (if (eq blknam (vla-get-effectivename obj)) (progn ;; Get block data and transformation matrix (setq blkdata (ssname ss1 i)) (setq Tmatrix (nth 2 blkdata)) (setq blk_pt (nth 3 Tmatrix)) ;; Draw the base point (command "_point" blk_pt) (princ "\nBase point = ") (princ blk_pt) ) ; End if ) ; End if ;; Move to the next block (setq i (1+ i)) ) ; End repeat ;; Start print settings (command "_plot" "Y" ; Detail Pot Layout ; Current layout "A1_ PDF.pc3" ; Output device name "ISO A1 (841.00 x 594.00 MM)" ; Size "M" ; Millimeter "L" ; Landscape "No" ; Do not plot upside down "W" ; Plot area (layout) Window '(-165.1913 466.24828 0) ; Left corner coordinates '(675.80807 -127.75172 0) ; Right corner coordinates "1=1" ; Plot scale "" ; Plot offset "Y" ; Plot style "NR12NR-01_FP.ctb" ; Plot style name "Y" ; Plot with lineweights "Y" ; Scale lineweights with plot scale "N" ; Plot paper space first "N" ; Hide paper space objects (strcat (getvar "DWGPREFIX") proc "-" Layout ".pdf") ; Output file name "N" ; Save changes to page setup "Y" ; Proceed with plot ) ; End command ) ; End progn ) ; End if ) ; End foreach ;; Clean up and close command (command "pdfshx" 0 "" "") (command "_close" "N") (princ) ;; End function ) ; defun end

 

How to improve the about lisp to find the left corner coordinate and right corner coordinate using pick point of block.

0 Likes
Message 11 of 16

skchui6159
Advocate
Advocate

(defun c:PRAA (/ cmd proc blknam ss1 i ent obj blkdata Tmatrix blk_pt)
(vl-load-com)

;; Get the first 27 characters of the current drawing name
(setq proc (substr (getvar "dwgname") 1 27))

;; Set the block name to search for
(setq blknam "-TITLE_A1_DETAIL")

;; Iterate through all layouts
(foreach Layout (layoutlist)
;; Find the specified block name
(if (setq ss1 (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat blknam ",`*U*")) '(66 . 1))))
(progn
(setq i 0)
;; Iterate through all found blocks
(repeat (sslength ss1)
(setq ent (ssname ss1 i)
obj (vlax-ename->vla-object ent))

;; Confirm that the block name matches
(if (eq blknam (vla-get-effectivename obj))
(progn
;; Get block data and transformation matrix
(setq blkdata (ssname ss1 i))
(setq Tmatrix (nth 2 blkdata))
(setq blk_pt (nth 3 Tmatrix))

;; Draw the base point
(command "_point" blk_pt)
(princ "\nBase point = ")
(princ blk_pt)
) ; End if
) ; End if

;; Move to the next block
(setq i (1+ i))
) ; End repeat

;; Start print settings
(command "_plot"
"Y" ; Detail Pot
Layout ; Current layout
"A1_ PDF.pc3" ; Output device name
"ISO A1 (841.00 x 594.00 MM)" ; Size
"M" ; Millimeter
"L" ; Landscape
"No" ; Do not plot upside down
"W" ; Plot area (layout) Window
'(-165.1913 466.24828 0) ; Left corner coordinates
'(675.80807 -127.75172 0) ; Right corner coordinates
"1=1" ; Plot scale
"" ; Plot offset
"Y" ; Plot style
"NR12NR-01_FP.ctb" ; Plot style name
"Y" ; Plot with lineweights
"Y" ; Scale lineweights with plot scale
"N" ; Plot paper space first
"N" ; Hide paper space objects
(strcat (getvar "DWGPREFIX") proc "-" Layout ".pdf") ; Output file name
"N" ; Save changes to page setup
"Y" ; Proceed with plot
) ; End command
) ; End progn
) ; End if
) ; End foreach

;; Clean up and close command
(command "pdfshx" 0 "" "")
(command "_close" "N")
(princ) ;; End function
) ; defun end

0 Likes
Message 12 of 16

Sea-Haven
Mentor
Mentor

One of the standards we used was to make sure our title block was always at 0,0 and true size ie 1=1 so a A1 sheet in a layout was 841x594. Had a lisp to check or move title blocks in all layouts to 0,0 for consistency. Then you always know the 2 corner points, so hard coded in a lisp. You can use different title blocks but again be at 1=1 scale and at 0,0 so the lisp can reset the 2 corners.

0 Likes
Message 13 of 16

skchui6159
Advocate
Advocate
(defun c:PRAA2(/ cmd)
  (vl-load-com) 
  (setq proc (substr (getvar "dwgname") 1 27))
  (setq blockName "-TITLE_A1_DETAIL")
  
  ;; Use ssget to locate block name
  (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blockName))))
  
  ;; check block
  (if ss
    (progn
      ;; For loop block
      (setq i 0)
      (repeat (sslength ss)
        (setq ent (ssname ss i)
              obj (vlax-ename->vla-object ent))
        
        ;; get block pick point
        (setq blkPt (vlax-get obj 'InsertionPoint))
        
        ;; cal left and right corner pointy
        (setq leftCorner (list (car blkPt) (+ (cadr blkPt) 594) 0))
         (setq rightCorner (list (+ (car blkPt) 841) (cadr blkPt) 0))
        
        ;; Outpoint x y
        (princ (strcat "\nblock " blockName " pick point: "
                       "X = " (rtos (car blkPt) 2 2) ", "
                       "Y = " (rtos (cadr blkPt) 2 2)))
        
        ;; output coordinate
        (princ (strcat "\n左下角座標: "
                       "X = " (rtos (car leftCorner) 2 2) ", "
                       "Y = " (rtos (cadr leftCorner) 2 2)))
        
        (princ (strcat "\n右上角座標: "
                       "X = " (rtos (car rightCorner) 2 2) ", "
                       "Y = " (rtos (cadr rightCorner) 2 2)))
        
        ;; move next block
        (setq i (1+ i))
      ) ; End repeat
      ); End of progn
    );End if
 
(foreach Layout (layoutlist)
;IS20-'(-198.53405336 399.86818108 0.00000000) '(642.46594664 -194.13181892 0.00000000)
(command "_plot"
"Y"; Detail Pot
Layout
"A1_ PDF.pc3" ; outputdevice name
"ISO A1 (841.00 x 594.00 MM)" ; Size
"M"; Milemeter
"L"; Landscape
"No"; Plot upside down
"W"; Plot area (Layout) W-by window
(strcat (rtos (car leftCorner) 2 2) "," (rtos (cadr leftCorner) 2 2)); Left Corner Coordinate
;'(0 594 0);Left Corner Coordinate
 
(strcat (rtos (car rightCorner) 2 2) "," (rtos (cadr rightCorner) 2 2)); Right Corner Coordinate
;'(841 0 0);Left Corner Coordinate
 
"1=1"; Plot scale "Fit <1=1>"
"" ; Plot offset (-5,10) ""="Centre to plot"
"Y"; Plot Style
"NR12NR-01_FP.ctb";Plot style name/"NR12NR-01 - Colour.ctb"
"Y"; Plot with lineweights
"Y" ;Scale lineweights with plot scale
"N"; Plot Paper space first
"N"; Hide paperspace object
(strcat (getvar "DWGPREFIX") proc "-" Layout ".pdf"); actually "" also ok
"N"; save change to page setup
"Y"; prcoeed with plot
);command end
); foreach end
(command "pdfshx" 0 "" "")
;(command "_close" "N")
);defun end
 
Solved the problem, however if the block of each layout is difference pick point, this lisp dont work! 
0 Likes
Message 14 of 16

skchui6159
Advocate
Advocate

Sir, Can I get each layout pick point in the drawing of block independently? To cal the corner?

0 Likes
Message 15 of 16

Sea-Haven
Mentor
Mentor
Accepted solution

If you set up your title blocks correctly then you always know where they are, its not rocket science rather good CAD management.

 

An example code for plot layouts by range.

SeaHaven_0-1730174665660.png

 

 

 

0 Likes
Message 16 of 16

skchui6159
Advocate
Advocate

THANKS FOR SHARING

0 Likes