Hello, I'm back for more help as I'm starting to get myself tied in knots
I'm still tinkering with my batch plotting code from here:
http://www.theswamp.org/index.php?topic=54582.0I'm trying to add the option to select which sheets to plot, rather than just plotting the entire list (often 20+ sheets).
I haven't started coding the input side of things, as I think I'll be ok with that.
The code was working (thanks to Ron for the help), and I understood how it worked (mostly). I have tried to change a little bit at a time and use
vl-remove-if-not to process the existing list containing the variable that are passed to my plot function, and remove any element that doesn't match the sheet selection.
I can get
vl-remove-if-not to pull out the required element from the list, but I can't seem to figure out to get the results back into a format that is accepted by the plot function. I thought that using
cons looked like the way to do it, but alas no joy.
The only way I can get it to work at the moment is by nesting a couple of
foreach which looks ugly, and is doing a lot of redundant processing.
This is my code as it stands (with the nested
foreach for processing the drawing border blocks into a list containing the sheet number, print window coordinates, and PDF file path.
;;;################################ 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
Mainplot code:
(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
)
I can see that
cons is creating
nlist but with additional parentheses closing the entire list, and causes mainplot to fail at the
setq lenx
I've been trying to get my head around it all day, and I've got myself a bit tied up
Any help/advice is greatlyappreciated as always.
Cheers,
John