Print a range of views - here it is

Discussion in 'AutoCAD' started by simon.weel, Aug 18, 2004.

  1. simon.weel

    simon.weel Guest

    I posted a question about printing views a couple of days ago. Got some response, but bot exactly what I was looking for. As it turned out, the routine was easier to make then I thought - with some code-borrowing from this discussiongroup.

    The purpose of the routine is to select a range of views and print them. We draw detaildrawings in a single file. Depending on the projectsize, there can be as much as 150 details in a drawing. Those details are printed on A3 format paper and put into a booklet. Handy to use. BUT... you have to use the PLOT command a 150 times to get them....

    The solution: make a view (with the command VIEW) of each detail and use the LISP routine to select the views to print. Real easy.

    Here's the code I baked. We use it with AutoCAD 2000i. I'm not a programmer, so it could probably be done easier / better / etc.

    Greetings,

    Simon Weel

    ;;;;; Start code ;;;;;
    ;printview.lsp
    ;Routine om een gekozen aantal views af te drukken. 17-08-2004.
    ;(c) 2004 Siem Weel

    ;;; Use this for a list of the views:
    ;;; (GetNames "view")
    ;;; Use this for the number of views:
    ;;; (length (GetNames "view"))

    (defun getnames (tablename / data result)
    (while (setq data (tblnext tablename (null data)))
    (setq result (cons (list (cdr (assoc 2 data))
    (cdr (assoc 40 data))
    (cdr (assoc 41 data))
    ) ;_ end of LIST
    result
    ) ;_ end of CONS
    ) ;_ end of SETQ
    ) ;_ end of WHILE
    ) ;_ end of DEFUN

    ;Start routine
    (defun c:printview (/ ocmd ocmddia oexpert
    oosmode viewlijst dianummer viewselect
    papierformaat teller item
    orientatie viewnaam hoogte breedte
    ) ;Save values of variables to change
    (setq ocmd (getvar "cmdecho")
    ocmddia (getvar "cmddia")
    oexpert (getvar "expert")
    oosmode (getvar "osmode")
    ) ;_ end of SETQ
    (command "cmdecho" 0 "cmddia" 1 "expert" 5 "osmode" 0) ;Change variables
    (setq viewlijst ;Get list of views and sort it
    (vl-sort (getnames "view")
    (function (lambda (a b) (< (nth 0 a) (nth 0 b))))
    ) ;_ end of VL-SORT
    ) ;_ end of SETQ
    (setq dianummer (load_dialog "printview")) ;Start dialog to select views
    (new_dialog "printview" dianummer)
    (start_list "viewbox")
    (setq teller 0)
    (repeat (length viewlijst)
    (add_list (car (nth teller viewlijst)))
    (setq teller (+ 1 teller))
    ) ;_ end of REPEAT
    (end_list)
    (action_tile
    "accept"
    "(setq viewselect (get_tile \"viewbox\"))(setq papierformaat (get_tile \"papierformaat\"))(done_dialog)"
    ) ;_ end of ACTION_TILE
    (action_tile "cancel" "(setq viewselect \"\")(done_dialog)")
    (start_dialog)
    (unload_dialog dianummer) ;If a view is selected, then print it
    (if (/= viewselect "")
    (progn (setq viewselect (read (strcat "(" viewselect ")"))) ;Convert string to list
    (setq teller 0)
    (repeat (length viewselect) ;Loop to process all selected views
    (setq item (nth teller viewselect)
    viewnaam (car (nth item viewlijst)) ; Name of view
    hoogte (cadr (nth item viewlijst)) ; Height of view
    breedte (car (cddr (nth item viewlijst))) ; Width of view
    ) ;_ end of SETQ
    (if (< breedte hoogte) ;Set paperorientation according to height/width
    (setq orientatie "Portrait")
    (setq orientatie "Landscape")
    ) ;_ end of IF
    ;;;For debug purpose
    ;;; (princ (strcat "\nViewnummer: "
    ;;; (itoa item)
    ;;; " Viewnaam: "
    ;;; viewnaam
    ;;; " Breedte: "
    ;;; (itoa (fix breedte))
    ;;; " Hoogte: "
    ;;; (itoa (fix hoogte))
    ;;; ) ;_ end of STRCAT
    ;;; ) ;_ end of PRINC
    ;;; (princ (strcat "\nPapierformaat: "
    ;;; papierformaat
    ;;; " Papier orientatie: "
    ;;; orientatie
    ;;; "\n"
    ;;; ) ;_ end of strcat
    ;;; ) ;_ end of PRINC
    (command "-plot" ; Print view
    "yes" ;Detailed plot configuration? [Yes/No] <No>
    "model" ;Enter a layout name or [?] <Model>
    "\\\\brt_architecten\\ir2800" ;Enter an output device name
    papierformaat ;Enter paper size:
    "m" ;Inches/milimeters
    orientatie ;Enter drawing orientation:
    "n" ;Plot upside down:
    "view" ;Enter plot area:
    viewnaam ;Enter view name:
    (strcat "1=" (itoa sch)) ;Enter plot scale
    "Center" ;Enter plot offset
    "y" ;Plot with plot styles:
    "-2 Printer.ctb" ;Enter plot style table name printer.ctb
    "y" ;Plot with lineweights:
    "n" ;Remove hidden lines
    "n" ;Write the plot to a file [Yes/No] <N>:
    "n" ;Save changes to model tab [Yes/No]? <N>
    "y" ;Proceed with plot [Yes/No] <Y>:
    ) ;_ end of COMMAND
    (setq teller (+ 1 teller))
    ) ;_ end of REPEAT
    ) ;_ end of PROGN
    (princ "\nGeen views gekozen") ; Display text if no view or cancel is selected
    ) ;_ end of IF
    (command "cmddia" ocmddia "expert" oexpert "osmode" oosmode "cmdecho" ; Reset variables
    ocmd) ;_ end of command
    (princ)
    ) ;_ end of DEFUN
    ;|«Visual LISP© Format Options»
    (72 2 1 2 T "end of " 60 9 1 1 0 T nil T T)
    ;*** DO NOT add text below the comment! ***|;
    ;;;; end routine;;;;;;;;


    ;;;;;;the DCL file
    ;printview.dcl
    printview : dialog {label = "Views afdrukken";
    : row {

    : boxed_column {
    label = "Selecteer views:";
    : list_box {
    // fixed_width_font = true;
    key = "viewbox";
    width = 25;
    height = 25;
    multiple_select = true;
    }

    } // End column

    : spacer_1 {}

    : column {
    fixed_height = true;
    alignment = top;

    : boxed_row {
    label = "Papier formaat:";

    : radio_column {
    key = "papierformaat";
    : radio_button {
    label = "A4";
    key = "A4";
    }
    : radio_button {
    label = "A3";
    key = "A3";
    value = "1";
    }

    } // End radiocolumn
    } // End row

    } // End column

    } // End row

    : spacer_1 {}

    ok_cancel;

    } // End dialog
    ;;;;;;;; dcl file end ;;;;;;
     
    simon.weel, Aug 18, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.