;;;################################ Block Processing Function ################################;;;
(defun blockproc (dwgname path pltyp plsize / ss
i hnd scl lst at ax shtno
file dest llpt urpt mn mx tb
plst shts nlst
)
(cond
((setq
ss (ssget "_X"
'((0 . "INSERT") (2 . "*A*BORD*") (410 . "MODEL"))
)
)
(repeat (setq i (sslength ss))
(setq hnd (ssname ss (setq i (1- i)))
scl (cdr (assoc 41 (entget hnd)))
)
(setq at (entnext hnd)
ax (entget at)
)
(while
(/= "SEQEND" (cdr (assoc 0 ax)))
(if
(= "SHEETNO" (cdr (assoc 2 ax)))
(progn (setq shtno (cdr (assoc 1 ax)))
)
)
(setq at (entnext at)
ax (entget at)
)
) ;_while
(setq dest
(strcat path "\\" (strcat dwgname "_SHEET_" shtno ".pdf"))
)
(vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx)
; get min and max points of block envelope and set lower left/upper right
(setq llpt (vlax-safearray->list mn)
urpt (vlax-safearray->list mx)
)
(setq lst (cons (list shtno llpt urpt dest) lst))
; construct list for sorting by sheet no
(princ "\nL")
(princ lst)
) ;_repeat
(setq shts (list "1" "3")) ; test values for selecting which pages to print
(foreach n shts
(setq
plst (vl-remove-if-not '(lambda (x) (vl-position n x)) lst) ; remove elements from [b]lst[/b] which do not match [b]shts[/b] list
)
(princ "\nP")
(princ plst)
(setq nlst (cons plst nlst)) ; construct [b]nlst[/b] from output of vl-remove-if-not
; ) ;_foreach n ; commented out to nest[b] tb[/b]
(princ "\nN")
(princ nlst)
(foreach tb
(vl-sort plst ;
'(lambda (a b) (< (atoi (car a)) (atoi (car b)))) ; sort is redundant but won't work without it
)
;(princ tb)
; (setq test (cadr tb))
; (princ test)
(mainplot pltyp
plsize
(cadr tb)
(caddr tb)
plstyle
(last tb)
scl
)
) ;_foreach tb
) ;_foreach n NEST
)
(t
(setq alrtmsgbrd
(strcat
dwgname
": No drawing borders found.\nScreenshot this message and contact: john \nCannot continue. Exiting... "
)
)
(alert
alrtmsgbrd
)
(exit)
)
) ;_cond
(princ)
) ;_blockproc
(defun mainplot
(pltyp plsize llpt urpt plstyle dest
scl / lenx leny nurpt furpt
scx
)
(setq lenx (- (cadr urpt) (cadr llpt)) ; calculate length of X
scx (/ lenx scl)
) ; convert to 1:1 scale
;;; (princ scl)
;;; (princ "\n")
;;; (princ lenx)
;;; (princ "\n")
;;; (princ scx)
;;; conditional check of block height to allow a tolerance for scaled blocks, and apply paper size multiplier to set length of Y
(cond ((and (>= scx 160)
(<= scx 235)
(setq leny (fix (* 1.482 lenx)))
)
)
((and (>= scx 250)
(<= scx 340)
(setq leny (fix (* 1.467 lenx)))
)
)
((and (>= scx 350)
(<= scx 485)
(setq leny (fix (* 1.454 lenx)))
)
)
((and (>= scx 520)
(<= scx 710)
(setq leny (fix (* 1.443 lenx)))
)
)
((and (>= scx 720)
(<= scx 1020)
(setq leny (fix (* 1.429 lenx)))
)
)
(t
(setq alrtmsgscl
(strcat
dwgname
": Scale out of bounds.\nScreenshot this message and contact: john.stewart@smd.co.uk \nCannot continue. Exiting... "
)
)
(alert
alrtmsgscl
)
(exit)
)
) ;_cond
(setq nurpt (list leny lenx) ; set local new upper right for block
furpt (mapcar '+ llpt nurpt) ; add lower left to set global final upper right for block
)
(if (= pltyp "DWG to PDF.pc3") ; If PDF. Run PDF plot. Else run paper plot
(command "-plot" "Y" "Model" pltyp plsize "M"
"L" "N" "W" llpt furpt "F" "C" "Y"
plstyle "Y" "A" dest "N" "Y"
) ;_command
;;;## Test Code ##
;;; (progn
;;; (princ "PAPER\n")
;;; (princ llpt)
;;; (princ urpt)
;;; )
(command "-plot" "Y" "Model" pltyp plsize "M"
"L" "N" "W" llpt furpt "F" "C" "Y"
plstyle "Y" "A" "N" "N" "Y"
) ;_command
) ;_if
)
setq lenx
(defun C:X-PLOT
(/ dcl_id fn fname status plsize pltyp plstyle userclick)
(vl-load-com)
(or op1 (setq op1 "r1"))
(or op2 (setq op2 ""))
(or op3 (setq op3 ""))
(setvar "CMDECHO" 0) ; Turn echo OFF
(setq dwgname (strcat (vl-filename-base (getvar "dwgname"))))
; get drawing number from filename
(vl-mkdir "C:\\PDF") ; create PDF directory
(setq path (strcat "C:\\PDF\\" dwgname))
(x-plot_dialog) ; set path using drawing number
(setq dcl_id
(load_dialog fname)
; load .DCL code GUI
)
;;;############################### DCL Dialog Box Handling ##############################;;;
(cond
((>= dcl_id 0)
(cond
((new_dialog "xplot" dcl_id)
(set_tile "rb1" "1")
(setq plstyle "standard.ctb")
(set_tile "rb5" "1")
(setq op1 "rb5")
(setq op2 "")
(setq op3 "")
(setq plsize "ISO A0 (841.00 x 1189.00 MM)")
(setq pltyp "DWG to PDF.pc3")
;;;################################ Plot Style Selection ################################;;;
(action_tile
"rb1"
"(setq plstyle \"standard.ctb\")"
)
(action_tile
"rb2"
"(setq plstyle \"hyd circuit.ctb\")"
)
(action_tile
"rb3"
"(setq plstyle \"colour assy.ctb\")"
)
;;;############################# Size and Output Selection #############################;;;
(action_tile
"op1"
"(progn
(set_tile op3 \"0\")
(setq op1 $value op3 \"\")
(set_tile op2 \"0\")
(setq op1 $value op2 \"\")
)"
)
(action_tile
"op2"
"(progn
(set_tile op1 \"0\")
(setq op2 $value op1 \"\")
(set_tile op3 \"0\")
(setq op2 $value op3 \"\")
)"
)
(action_tile
"op3"
"(progn
(set_tile op2 \"0\")
(setq op3 $value op2 \"\")
(set_tile op1 \"0\")
(setq op3 $value op1 \"\")
)"
)
(set_tile "op1" op1)
(set_tile "op2" op2)
(set_tile "op3" op3)
;;;################################ OK/Cancel Selection ################################;;;
(action_tile
"cancel"
"(done_dialog)(setq userclick nil)"
)
(action_tile
"accept"
"(done_dialog) (setq userclick T)"
)
(setq status (start_dialog))
(unload_dialog dcl_id)
)
) ;_cond
)
) ;_cond
;;;############################# Processing Print Selection #############################;;;
(if userclick
(cond
;;;#################################### A0 PDF Print ####################################;;;
((= op1 "rb5")
(setq plsize "ISO expand A0 (841.00 x 1189.00 MM)")
; set paper size
(setq pltyp "DWG to PDF.pc3") ; set plotter type
(vl-mkdir path) ; make PDF output directory based on drawing number
(blockproc dwgname path pltyp plsize)
; call blockproc function and pass variables
(startapp "explorer" path) ; open file explorer to PDF output directory
)
;;;#################################### A1 PDF Print ####################################;;;
((= op1 "rb6")
(setq plsize "ISO expand A1 (841.00 x 594.00 MM)")
(setq pltyp "DWG to PDF.pc3")
(vl-mkdir path)
(blockproc dwgname path pltyp plsize)
(startapp "explorer" path)
)
;;;#################################### A2 PDF Print ####################################;;;
((= op1 "rb7")
(setq plsize "ISO expand A2 (594.00 x 420.00 MM)")
(setq pltyp "DWG to PDF.pc3")
(vl-mkdir path)
(blockproc dwgname path pltyp plsize)
(startapp "explorer" path)
)
;;;#################################### A3 PDF Print ####################################;;;
((= op1 "rb8")
(setq plsize "ISO expand A3 (420.00 x 297.00 MM)")
(setq pltyp "DWG to PDF.pc3")
(vl-mkdir path)
(blockproc dwgname path pltyp plsize)
(startapp "explorer" path)
)
;;;#################################### A4 PDF Print ####################################;;;
((= op1 "rb9")
(setq plsize "ISO expand A4 (297.00 x 210.00 MM)")
(setq pltyp "DWG to PDF.pc3")
(vl-mkdir path)
(blockproc dwgname path pltyp plsize)
(startapp "explorer" path)
)
;;;#################################### A3 O1D Paper Print ####################################;;;
((= op2 "rb10")
(setq plsize "A3")
(setq pltyp "\\\\TW3\\Office 1 Downstairs Printer")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A4 O1D Paper Print ####################################;;;
((= op2 "rb11")
(setq plsize "A4")
(setq pltyp "\\\\TW3\\Office 1 Downstairs Printer")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A3 O1U Paper Print ####################################;;;
((= op2 "rb12")
(setq plsize "A3")
(setq pltyp "\\\\TW3\\Office 2")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A4 O1U Paper Print ####################################;;;
((= op2 "rb13")
(setq plsize "A4")
(setq pltyp "\\\\TW3\\Office 2")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A3 i19 Paper Print ####################################;;;
((= op3 "rb14")
(setq plsize "A3")
(setq pltyp "\\\\TT2\\i19DOWNSTAIRS")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A4 i19 Paper Print ####################################;;;
((= op3 "rb15")
(setq plsize "A4")
(setq pltyp "\\\\TT2\\i19DOWNSTAIRS")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A3 O3 Paper Print ####################################;;;
((= op3 "rb16")
(setq plsize "A3")
(setq pltyp "\\\\TW3\\Office 3")
(blockproc dwgname path pltyp plsize)
)
;;;#################################### A4 O3 Paper Print ####################################;;;
((= op3 "rb17")
(setq plsize "A4")
(setq pltyp "\\\\TW3\\Office 3")
(blockproc dwgname path pltyp plsize)
)
) ;_cond
) ;_if
(princ)
) ;_C:X-PLOT
;;;################################ Block Processing Function ################################;;;
(defun blockproc (dwgname path pltyp plsize / ss
i hnd scl lst at ax shtno
file dest llpt urpt mn mx tb
plst shts nlst
)
(cond
((setq
ss (ssget "_X"
'((0 . "INSERT") (2 . "*A*BORD*") (410 . "MODEL"))
)
)
(repeat (setq i (sslength ss))
(setq hnd (ssname ss (setq i (1- i)))
scl (cdr (assoc 41 (entget hnd)))
)
(setq at (entnext hnd)
ax (entget at)
)
(while
(/= "SEQEND" (cdr (assoc 0 ax)))
(if
(= "SHEETNO" (cdr (assoc 2 ax)))
(progn (setq shtno (cdr (assoc 1 ax)))
)
)
(setq at (entnext at)
ax (entget at)
)
) ;_while
(setq dest
(strcat path "\\" (strcat dwgname "_SHEET_" shtno ".pdf"))
)
(vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx)
; get min and max points of block envelope and set lower left/upper right
(setq llpt (vlax-safearray->list mn)
urpt (vlax-safearray->list mx)
)
(setq lst (cons (list shtno llpt urpt dest) lst))
; construct list for sorting by sheet no
(princ "\nL")
(princ lst)
) ;_repeat
(setq shts (list "1" "3"))
(foreach n shts
(setq
plst (vl-remove-if-not '(lambda (x) (vl-position n x)) lst)
)
(princ "\nP")
(princ plst)
; (setq nlst (cons plst nlst))
(setq nlst (list plst nlst))
; ) ;_foreach n
(princ "\nN")
(princ nlst)
(foreach tb
(vl-sort nlst
'(lambda (a b) (< (atoi (car a)) (atoi (car b))))
)
;(princ tb)
; (setq test (cadr tb))
; (princ test)
(mainplot pltyp
plsize
(cadr tb)
(caddr tb)
plstyle
(last tb)
scl
)
) ;_foreach tb
) ;_foreach n
)
(t
(setq alrtmsgbrd
(strcat
dwgname
": No SMD drawing borders found.\nScreenshot this message and contact: john.stewart@smd.co.uk \nCannot continue. Exiting... "
)
)
(alert
alrtmsgbrd
)
(exit)
)
) ;_cond
(princ)
) ;_blockproc
;;;################### Plot Function ####################;;;
(defun mainplot
(pltyp plsize llpt urpt plstyle dest
scl / lenx leny nurpt furpt
scx
)
(setq lenx (- (cadr urpt) (cadr llpt)) ; calculate length of X
scx (/ lenx scl)
) ; convert to 1:1 scale
;;; (princ scl)
;;; (princ "\n")
;;; (princ lenx)
;;; (princ "\n")
;;; (princ scx)
;;; conditional check of block height to allow a tolerance for scaled blocks, and apply paper size multiplier to set length of Y
(cond ((and (>= scx 160)
(<= scx 235)
(setq leny (fix (* 1.482 lenx)))
)
)
((and (>= scx 250)
(<= scx 340)
(setq leny (fix (* 1.467 lenx)))
)
)
((and (>= scx 350)
(<= scx 485)
(setq leny (fix (* 1.454 lenx)))
)
)
((and (>= scx 520)
(<= scx 710)
(setq leny (fix (* 1.443 lenx)))
)
)
((and (>= scx 720)
(<= scx 1020)
(setq leny (fix (* 1.429 lenx)))
)
)
(t
(setq alrtmsgscl
(strcat
dwgname
": Scale out of bounds.\nScreenshot this message and contact: john.stewart@smd.co.uk \nCannot continue. Exiting... "
)
)
(alert
alrtmsgscl
)
(exit)
)
) ;_cond
(setq nurpt (list leny lenx) ; set local new upper right for block
furpt (mapcar '+ llpt nurpt) ; add lower left to set global final upper right for block
)
(if (= pltyp "DWG to PDF.pc3") ; If PDF. Run PDF plot. Else run paper plot
(command "-plot" "Y" "Model" pltyp plsize "M"
"L" "N" "W" llpt furpt "F" "C" "Y"
plstyle "Y" "A" dest "N" "Y"
) ;_command
;;;## Test Code ##
;;; (progn
;;; (princ "PAPER\n")
;;; (princ llpt)
;;; (princ urpt)
;;; )
(command "-plot" "Y" "Model" pltyp plsize "M"
"L" "N" "W" llpt furpt "F" "C" "Y"
plstyle "Y" "A" "N" "N" "Y"
) ;_command
) ;_if
) ;_mainplot
(defun x-plot_dialog ()
(setq fname (vl-filename-mktemp "dcl.dcl"))
(setq fn (open fname "w"))
(write-line
(strcat
"xplot : dialog {
label = \"Plot a Load of Sheet - V1.0\";
: row {
: boxed_radio_column {
label = \"Plot Style :\";
: radio_button { label = \"Standard\"; key = \"rb1\";}
: radio_button { label = \"Hydraulic\"; key = \"rb2\";}
: radio_button { label = \"Colour\"; key = \"rb3\";}
}
: boxed_row {
label = \"Output Format :\";
: radio_column {
key = \"op1\";
label = \"Plot to PDF :\";
: radio_button : tile { label = \"A&0 - 1189 x 841\"; key = \"rb5\"; value = \"1\";}
: radio_button : tile { label = \"A&1 - 841 x 594\"; key = \"rb6\";}
: radio_button : tile { label = \"A&2 - 594 x 420\"; key = \"rb7\";}
: radio_button : tile { label = \"A&3 - 420 x 297\"; key = \"rb8\";}
: radio_button : tile { label = \"A&4 - 297 x 210\"; key = \"rb9\";}
}
: boxed_radio_row {
label = \"Plot to Paper :\";
: radio_column {
key = \"op2\";
: radio_button : tile { label = \"A3 - Office 1 Dn\"; key = \"rb10\"; value = \"0\";}
: radio_button : tile { label = \"A4 - Office 1 Dn\"; key = \"rb11\";}
: radio_button : tile { label = \"A3 - Office 2 Dn\"; key = \"rb12\";}
: radio_button : tile { label = \"A4 - Office 2 Dn\"; key = \"rb13\";}
}
: radio_column {
key = \"op3\";
: radio_button : tile { label = \"A3 - i19\"; key = \"rb14\"; value = \"0\";}
: radio_button : tile { label = \"A4 - i19\"; key = \"rb15\";}
: radio_button : tile { label = \"A3 - Office 3\"; key = \"rb16\";}
: radio_button : tile { label = \"A4 - Office 3\"; key = \"rb17\";}
}
}
}
}
ok_cancel ;
: paragraph {
: text_part {
label = \"Hacked and Cobbled Together in AutoLISP and DCL by John Stewart\";
}
: text_part {
label = \"For Issues and Support Contact: john.stewart@smd.co.uk\";
}
}"
)
fn
)
(write-line
(strcat
"
: row {
children_fixed_height = true;
children_alignment = bottom;
: image {
height = 2;
color = 10;
}
: image {
height = 2;
color = 20;
}
: image {
height = 2;
color = 30;
}
: image {
height = 2;
color = 40;
}
: image {
height = 2;
color = 50;
}
: image {
height = 2;
color = 60;
}
: image {
height = 2;
color = 70;
}
: image {
height = 2;
color = 80;
}
: image {
height = 2;
color = 90;
}
: image {
height = 2;
color = 100;
}
: image {
height = 2;
color = 110;
}
: image {
height = 2;
color = 120;
}
: image {
height = 2;
color = 130;
}
: image {
height = 2;
color = 140;
}
: image {
height = 2;
color = 150;
}
: image {
height = 2;
color = 160;
}
: image {
height = 2;
color = 170;
}
: image {
height = 2;
color = 180;
}
: image {
height = 2;
color = 190;
}
: image {
height = 2;
color = 200;
}
: image {
height = 2;
color = 210;
}
: image {
height = 2;
color = 220;
}
: image {
height = 2;
color = 230;
}
: image {
height = 2;
color = 240;
}
}
}"
)
fn
)
(close fn)
) ;defun
(princ)
;;;####################### Old .PC3 file code - not used ######################
;;; (setq pltyp "Office 3.pc3")
;;; (setq pltyp "i19DOWNSTAIRS.pc3")
;;; (setq pltyp "Office 1 Upstairs Printer.pc3")
;;; (setq pltyp "Office 1 Downstairs Printer Colour.pc3")
If I understand what you're asking, give this a try:Code - Auto/Visual Lisp: [Select]
;;;################################ Block Processing Function ################################;;; at ax shtno file dest llpt urpt mn mx tb plst shts nlst ) ) ) ) ) ) ;_while ; get min and max points of block envelope and set lower left/upper right ) ; construct list for sorting by sheet no ) ;_repeat ; remove elements from [b]lst[/b] which do not match [b]shts[/b] list ) ; sort is redundant but won't work without it ) ;(princ tb) ; (setq test (cadr tb)) ; (princ test) ) ;_foreach tb ;;; (foreach n shts ;;; (setq plst (vl-remove-if-not '(lambda (x) (vl-position n x)) lst) ;;; ; remove elements from [b]lst[/b] which do not match [b]shts[/b] list ;;; ) ;;; (princ "\nP") ;;; (princ plst) ;;; (setq nlst (cons plst nlst)) ; construct [b]nlst[/b] from output of vl-remove-if-not ;;; ; ) ;_foreach n ; commented out to nest[b] tb[/b] ;;; (princ "\nN") ;;; (princ nlst) ;;; (foreach tb (vl-sort plst ; ;;; '(lambda (a b) (< (atoi (car a)) (atoi (car b)))) ;;; ; sort is redundant but won't work without it ;;; ) ;(princ tb) ;;; ; (setq test (cadr tb)) ;;; ; (princ test) ;;; (mainplot pltyp plsize (cadr tb) (caddr tb) plstyle (last tb) scl) ;;; ) ;_foreach tb ;;; ) ;_foreach n NEST ) (t (setq alrtmsgbrd dwgname ": No drawing borders found.\nScreenshot this message and contact: john \nCannot continue. Exiting... " ) ) ) ) ;_cond ) ;_blockproc
I'm happy to report that, unsurprisingly, your code works! So thanks again.Glad you're getting things sorted! :)
Now embarking on building up some code to act like the MS Word print page range options :nerdystraight:
Thanks to Lee Mac I've got it parsing for the comma delimiter, and I've got an idea on how to parse for the hyphen delimiter to build page ranges.
Slowly getting my head around the complexities of lambda, mapcar etc. I'll no doubt be posting more questions/problems very soon!!
Cheers!
This is a plot layout range for pdf's includes a merge pdfs, plots to a subdirectory under dwg location.
(wcmatch "5" "[1-9],12")
The way our drawings are done is a little backward - all drawings sheets are on one modelspace page, and are defined by a block which is the drawing border titleblock.It's too bad your company operates like this, if anything that has progressed with AutoCAD ease of printing is definitely one of them ( Sheet Set Manager, Publish ).
Use wcmatch for your rangees / individual sheets. This will print pages 1 to 9 and 12. :)Code: [Select](wcmatch "5" "[1-9],12")
QuoteThe way our drawings are done is a little backward - all drawings sheets are on one modelspace page, and are defined by a block which is the drawing border titleblock.It's too bad your company operates like this, if anything that has progressed with AutoCAD ease of printing is definitely one of them ( Sheet Set Manager, Publish ).
Use wcmatch for your rangees / individual sheets. This will print pages 1 to 9 and 12. :)Code: [Select](wcmatch "5" "[1-9],12")
All characters enclosed in brackets ([ . . . ]) are read literally, so there is no need to escape them, with the following exceptions: the tilde character (~) is read literally only when it is not the first bracketed character (as in "[A~BC]"); otherwise, it is read as the negation character, meaning that wcmatch should match all characters except those following the tilde (as in "[~ABC]"). The dash character (-) is read literally only when it is the first or last bracketed character (as in "[-ABC]" or "[ABC-]") or when it follows a leading tilde (as in "[~-ABC]"). Otherwise, the dash character (-) is used within brackets to specify a range of values for a specific character. The range works only for single characters, so "STR[1-38]" matches STR1, STR2, STR3, and STR8, and "[A-Z]" matches any single uppercase letter.
You are correct it does get a bit wonky with pages that have 2 digits. If you're parsing one by one, vl-remove-if-not would work nicely for this:Code - Auto/Visual Lisp: [Select]