Author Topic: plotting lisp  (Read 21658 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
plotting lisp
« on: November 19, 2003, 12:47:25 PM »
i have this lisp for plotting all the tabs in the order they appear left to right in a drawing. it works pretty good but there's a couple things that i'd like to tweak. first off, it sometimes doesn't set the filedia and cmddia variables back to 1. the main feature i am hoping to add is the ability to do multiple sets, is this possible? thanks

dan

Code: [Select]
(Defun C:PT
     (/ PLO_LAYOUTS PLO_CNTR PLO_CNTR2 PLO_LIST PLO_LAYOUTTAB)
  (vl-load-com)
  (setvar"FILEDIA"0)
  (setvar"CMDDIA"0)
  (setq  PLO_LAYOUTS (vla-get-layouts
                   (vla-get-activedocument(vlax-get-acad-object)))
        PLO_CNTR 0 PLO_CNTR2 0)
  (repeat(vla-get-count PLO_LAYOUTS)
    (setq PLO_LIST (cons(setq PLO_CNTR (1+ PLO_CNTR)) PLO_LIST)))
  (vlax-for PLO_LAYOUT PLO_LAYOUTS
    (setq PLO_LIST (subst(vla-get-name PLO_LAYOUT)
                             (vla-get-taborder PLO_LAYOUT)PLO_LIST)))
  (setq PLO_LIST (reverse PLO_LIST))
  (while(/= PLO_CNTR2 (1- PLO_CNTR))
    (setq PLO_LAYOUTTAB (nth PLO_CNTR2 PLO_LIST))
    (command "-PLOT" "n" PLO_LAYOUTTAB "" "" "" "" "" "")
    (setq PLO_CNTR2 (1+ PLO_CNTR2)))
  (setvar"FILEDIA"1)
  (setvar"CMDDIA"1)
  (princ))

daron

  • Guest
plotting lisp
« Reply #1 on: November 19, 2003, 12:53:31 PM »
Using the code tags doesn't just make it pretty, it keeps smiley's out of your code too, so you don't end up with :P instead of :P

As far as your code problem, take out the filedia and cmddia areas and see what happens. ActiveX functions won't call up dialogs unless you specify them, so many of the setvar's aren't as necessary anymore.

ELOQUINTET

  • Guest
plotting lisp
« Reply #2 on: November 19, 2003, 03:37:52 PM »
ok so what about the multiple sets part? how would i go about incorporating that? that was my main intenetion of the post the variable issue just came to mind also. thanks

dan

daron

  • Guest
plotting lisp
« Reply #3 on: November 19, 2003, 03:44:23 PM »
Don't quote me on this. I haven't even tried it.
Code: [Select]
;;; ==========================================================================
;;; File    : PLOTALL.LSP
;;; Purpose : Provides PLOTALL and -PLOTALL commands to plot all paper space
;;;           layouts in the current drawing, thereby working around the
;;;           "Layout of order" item in January 2003 Bug Watch.
;;; Author  : Steve Johnson for Cadalyst magazine.
;;; Notes   : Expects to find PLOTALL.DCL in search path.
;;;           Uses AutoCAD 2000+ Visual LISP functions.
;;;           Only tested on AutoCAD 2002.
;;; ==========================================================================


;; ---------------------------------------------------------------------------
;; Function: C:PLOTALL
;; Purpose : Dialogue box version of command to plot all paper space layouts
;;           in the current drawing.
;; Global  : PLOTALL-DEVICE: string containing name of plot device, e.g.
;;                           "\\\\server\\plotter" or
;;                           "plotter.pc3"
;;           PLOTALL-QTY:    number of each layout to plot
;;           PLOTALL-ORDER:  order in which to plot (string)
;;           PLOTALL-REV:    reverse order? (boolean: T = reverse)
;; Local   : dclfile:        full filename of "PlotAll.dcl" file
;;           dcl#:           DCL ID number
;;           device-list:    list of available plot devices
;;           order-list:     list of order strings
;;           device#:        index number of chosen device in device-list
;;           order#:         index number of chosen order in order-list
;;           quantity:       temporary number of each layout to plot
;; ---------------------------------------------------------------------------

(defun C:PLOTALL (/ ; Functions
                   init_vars init_tiles call_ok
                    ; Variables
                   dclfile dcl# device-list order-list device# order# quantity
                 )


;; ---------------------------------------------------------------------------
;; Function: init_vars
;; Purpose : Sets up variables prior to invoking dialogue box.
;; ---------------------------------------------------------------------------

  (defun init_vars ()
    (if (not PLOTALL-DEVICE) (setq PLOTALL-DEVICE "None"))
    (if (not PLOTALL-QTY) (setq PLOTALL-QTY 1))
    (if (not PLOTALL-ORDER) (setq PLOTALL-ORDER "Alpha"))
    (setq
      device-list (plotall_device_list)
      order-list '("Alpha" "Numeric" "Tab")
      order# (- (length order-list) (length (member PLOTALL-ORDER order-list)))
      quantity PLOTALL-QTY
    )
    (if (and PLOTALL-DEVICE (member PLOTALL-DEVICE device-list))
      (setq
        device#
         (- (length device-list) (length (member PLOTALL-DEVICE device-list)))
      )
      (setq device# 0)
    )
  ) ; End init_vars


;; ---------------------------------------------------------------------------
;; Function: init_tiles
;; Purpose : Sets up dialogue box tiles prior to invoking dialogue box.
;; ---------------------------------------------------------------------------

  (defun init_tiles ()
    (action_tile "accept" "(call_ok)")
    (start_list "device_list")
    (foreach one device-list
      (add_list one)
    )
    (end_list)
    (start_list "order_list")
    (foreach one order-list
      (add_list one)
    )
    (end_list)
    (set_tile "device_list" (itoa device#))
    (set_tile "order_list" (itoa order#))
    (set_tile "reverse" (if PLOTALL-REV "1" "0"))
    (set_tile "quantity" (itoa quantity))
  ) ; End init_tiles


;; ---------------------------------------------------------------------------
;; Function: call_ok
;; Purpose : Callback function for OK button. Ensures a quantity greater than
;;           0 and a device other than "None".
;; ---------------------------------------------------------------------------

  (defun call_ok ()
    (if (> (setq quantity (atoi (get_tile "quantity"))) 0)
      (if (> (setq device# (atoi (get_tile "device_list"))) 0)
        (progn
          (setq
            PLOTALL-DEVICE (nth device# device-list)
            PLOTALL-ORDER (nth (atoi (get_tile "order_list")) order-list)
            PLOTALL-REV (= (get_tile "reverse") "1")
            PLOTALL-QTY quantity
          )
          (done_dialog 1)
        )
        (set_tile "error" "Must choose a plot device")
      )
      (set_tile "error" "Quantity must be 1 or more")
    )
  ) ; End call_ok


;; Start C:PLOTALL -----------------------------------------------------------

  (cond
    ((not (findfile (setq dclfile "PlotAll.dcl")))
      (alert "Cannot find PlotAll.dcl")
    )
    ((< (setq dcl# (load_dialog dclfile)) 0) ; Error
      (prompt (strcat "\nCannot load " dclfile "."))
    )
    ((not (new_dialog "plotall_main" dcl#)) ; Error
      (prompt (strcat "\nProblem with " dclfile "."))
    )
    (T ; No DCL problems: fire it up
      (init_vars)
      (init_tiles)
      (setq action (start_dialog))
      (unload_dialog dcl#)
      (if (= action 1)
        (plotall_layouts PLOTALL-DEVICE PLOTALL-QTY PLOTALL-ORDER PLOTALL-REV)
      )
    )
  )
  (princ)
) ; End C:PLOTALL


;; ---------------------------------------------------------------------------
;; Function: C:-PLOTALL
;; Purpose : Command line version of command to plot all paper space layouts
;;           in the current drawing.
;; Global  : PLOTALL-DEVICE: string containing name of plot device
;;           PLOTALL-QTY:    number of each layout to plot
;;           PLOTALL-ORDER:  order in which to plot (string)
;;           PLOTALL-REV:    reverse order? (boolean: T = reverse)
;; Local   : device:         temporary string containing name of plot device
;;           device-list:    list of available plot devices
;;           order:          temporary order in which to plot (string)
;;           rev:            temporary reverse order? (boolean: T = reverse)
;;           quantity:       temporary number of each layout to plot
;; ---------------------------------------------------------------------------

(defun C:-PLOTALL (/ device device-list order rev quantity)
  (if (not PLOTALL-DEVICE) (setq PLOTALL-DEVICE "None"))
  (if (not PLOTALL-QTY) (setq PLOTALL-QTY 1))
  (if (not PLOTALL-ORDER) (setq PLOTALL-ORDER "Alpha"))
  (setq device (getstring T (strcat "\nPlot device <" PLOTALL-DEVICE ">: ")))
  (if (= device "") (setq device PLOTALL-DEVICE))
  (cond
    ((= device "None")
      (prompt "\nMust specify a plot device.")
    )
    ((not
       (member
         (strcase device)
         (mapcar 'strcase (setq device-list (plotall_device_list)))
       )
     )
      (foreach one device-list
        (if (/= one "None")
          (prompt (strcat one "\n"))
        )
      )
      (prompt "Must specify one of the above plot devices.\n")
    )
    (progn
      (initget "Alpha Numeric Tab")
      (setq
        order
         (getkword
           (strcat
             "\nPlot order [Alpha/Numeric/Tab] <" PLOTALL-ORDER ">: "
           )
         )
      )
      (if order (setq PLOTALL-ORDER order))
      (initget "Yes No")
      (setq
        rev
         (getkword
           (strcat
             "\nReverse order [Yes/No] <" (if PLOTALL-REV "Yes" "No") ">: "
           )
         )
      )
      (if rev (setq PLOTALL-REV (= rev "Yes")))
      (initget 6) ; Positive integer
      (setq
        PLOTALL-DEVICE device
        quantity
         (getint (strcat "\nNumber of copies <" (itoa PLOTALL-QTY) ">: "))
      )
      (if quantity (setq PLOTALL-QTY quantity))
      (plotall_layouts PLOTALL-DEVICE PLOTALL-QTY PLOTALL-ORDER PLOTALL-REV)
    )
  )
  (princ)
) ; End C:-PLOTALL


;; ---------------------------------------------------------------------------
;; Function: plotall_device_list
;; Purpose : Returns list of strings of all available plot devices.
;; Local   : curdwg:   current drawing object
;;           pslayout: paper space layout object
;; ---------------------------------------------------------------------------

(defun plotall_device_list (/ curdwg pslayout)
  (vl-load-com)
  (setq
    curdwg (vla-get-ActiveDocument (vlax-get-Acad-Object))
    pslayout (vla-get-Layout (vla-get-PaperSpace curdwg))
  )
  ; Call RefreshPlotDeviceInfo before GetPlotDeviceNames
  (vla-RefreshPlotDeviceInfo pslayout)
  (vlax-safearray->list (vlax-variant-value (vla-GetPlotDeviceNames pslayout)))
) ; End plotall_device_list


;; ---------------------------------------------------------------------------
;; Function: plotall_layouts
;; Purpose : Plots all paper space layouts in current drawing to a specified
;;           plot device, in the specified quantity.
;; Params  : DEVICE:       string containing name of plot device
;;           QTY:          number of each layout to plot
;;           ORDER:        order in which to plot ("Alpha" "Numeric" "Tab")
;;           REV:          boolean: if T, reverse plot order
;; Local   : curdwg:       current drawing object
;;           layout-array: safearray of a single layout name string
;;           layout-list:  list of layout name strings
;;           plot:         plot object (needed to actually perform plot)
;;           errmsg:       returned object from failed plot attempt
;; ---------------------------------------------------------------------------

(defun plotall_layouts (DEVICE QTY ORDER REV /
                        ; Functions
                          delnth sortlist str_num_sort tab_sort
                        ; Variables
                         curdwg layout-array layout-list plot errmsg)


;; ---------------------------------------------------------------------------
;; Function: delnth
;; Purpose : Returns a list with the Nth item deleted
;; Params  : N:    index number of item to delete (0 is first item in list)
;;           LST:  list to delete from
;; Local   : #:    item counter
;;           tlst: temporary list
;; ---------------------------------------------------------------------------

  (defun delnth (N LST / # tlst)
    (setq # 0)
    (while (and LST (/= # N))
      (setq
        tlst (cons (car LST) tlst)
        LST (cdr LST)
        # (1+ #)
      )
    )
    (reverse (append (reverse (cdr LST)) tlst))
  ) ; End delnth


;; ---------------------------------------------------------------------------
;; Function: sortlist
;; Purpose : Sorts a list, allowing any function to be used for item comparison.
;; Params  : LST: list to sort
;;           FUN: name of function to apply to test for "lower": could be a
;;                built-in function (e.g. >) or a user defined function,
;;                possibly defined on the spot using lambda.
;; ---------------------------------------------------------------------------

  (defun sortlist (LST FUN / size # pos high item tmplst)
    (repeat (1- (setq size (length LST)))
      (setq
        #   1             ; Position of 1st item to compare with highest item
        pos 0             ; Position of initial highest item
        high (nth 0 LST)  ; Value of initial highest item
      )
      (while (< # size)   ; Walk through the whole list, finding the highest item
        (if (apply FUN (list high (setq item (nth # LST)))) ; Test for higher
          (setq           ; Found a higher item, so record its:
            high item     ;  value,
            pos  #        ;  position
          )
        )
        (setq # (1+ #))   ; Test next item
      )
      (setq
        tmplst (cons high tmplst)  ; Stick highest item at start of temp list
        LST    (delnth pos LST)    ; Delete highest item from main list,
        size   (- size 1)          ;  and reduce size of main list
      )
    )
    (cons (car LST) tmplst)        ; Add last (lowest) item to start and return
  ) ; End sortlist


;; ---------------------------------------------------------------------------
;; Function: str_num_sort
;; Purpose : Sorts a list of layouts into tab number order.
;; Params  : LST:    list of sublists to sort. Each sublist contains a tab
;;                   number index integer and a layout name string.
;; ---------------------------------------------------------------------------

  (defun str_num_sort (LST / split_str_num str_num_compare)


;; ---------------------------------------------------------------------------
;; Function: split_str_num
;; Purpose : Divides a string into 3 parts: string prefix, numeric middle and
;;           string suffix.
;; Params  : STR: string to split
;; Local   : #: loop counter/character index
;;           ch: current character
;;           slen: string length
;;           s1: string prefix
;;           s2: string containing numeric middle
;;           s3: string prefix
;; Returns : Always a list containing a string, a real and a string. If any of
;;           these elements do not exist, defaults of "", 0.0 and "" are used.
;; ---------------------------------------------------------------------------

    (defun split_str_num (STR / # ch slen s1 s2 s3)
      (setq
        # 0
        slen (strlen STR)
        s1 ""
      )
      (while (and (<= (setq # (1+ #)) slen) (not s3))
        (if (wcmatch (setq ch (substr STR # 1)) "[0123456789.]")
          (if s2
            (setq s2 (strcat s2 ch))
            (setq s2 ch)
          )
          (if s2
            (setq s3 (substr STR # 1))
            (setq s1 (strcat s1 ch))
          )
        )
      )
      (list s1 (if s2 (atof s2) 0.0) (if s3 s3 ""))
    ) ; End split_str_num


;; ---------------------------------------------------------------------------
;; Function: str_num_compare
;; Purpose : Compares 2 lists. Each list contains a tab number index integer
;;           and a layout name string. The tab number is ignored and the
;;           layout name string is divided into 3 parts: string prefix,
;;           numeric middle and string suffix. The comparison is then performed
;;           on the first then second, then third items, then on the string as
;;           a whole.
;; Params  : X, Y: lists to compare
;; Local   : xlist: list of 3 parts derived from X layout name string
;;           ylist: list of 3 parts derived from Y layout name string
;; Returns : T if X < Y, else nil.
;; ---------------------------------------------------------------------------

    (defun str_num_compare (X Y / xlist ylist)
      (setq
        xlist (split_str_num (cadr X))
        ylist (split_str_num (cadr Y))
      )
      (if (= (car xlist) (car ylist))         ; if 1st are equal
        (if (= (cadr xlist) (cadr ylist))     ;  if 2nd are equal
          (if (= (caddr xlist) (caddr ylist)) ;   if 3rd are equal
            (< (cadr X) (cadr Y))             ;    then ascending on whole string
            (< (caddr xlist) (caddr ylist))   ;    else ascending on 3rd
          )
          (< (cadr xlist) (cadr ylist))       ;    else ascending on 2nd
        )
        (< (car xlist) (car ylist))           ;  else ascending on 1st
      )
    ) ; End str_num_compare


;; Start str_num_sort --------------------------------------------------------

    (reverse (sortlist LST 'str_num_compare))
  ) ; End str_num_sort


;; ---------------------------------------------------------------------------
;; Function: tab_sort
;; Purpose : Sorts a list of layouts into tab number order.
;; Params  : LST:    list of sublists to sort. Each sublist contains a tab
;;                   number index integer and a layout name string.
;; Local   : #:      index integer counter
;;           retlst: sorted list to return
;; ---------------------------------------------------------------------------

  (defun tab_sort (LST / # retlst)
    (setq # 1)
    (while (< (length retlst) (length LST))
      (foreach one LST
        (if (= (car one) #)
          (setq
            retlst (cons one retlst)
            # (1+ #)
          )
        )
      )
    )
    retlst
  ) ; End tab_sort


;; Start plotall_layouts -----------------------------------------------------

  (vl-load-com)
  (setq
    curdwg (vla-get-ActiveDocument (vlax-get-Acad-Object))
    layout-array (vlax-make-safearray vlax-vbString '(0 . 0))
  )
  (vlax-for layout (vla-get-Layouts curdwg)
    (if (/= (vla-get-Name layout) "Model")
      (setq
        layout-list
         (cons
           (list (vla-get-TabOrder layout) (vla-get-Name layout))
           layout-list
         )
      )
    )
  )
  (cond
    ((= ORDER "Numeric")
      (setq layout-list (str_num_sort layout-list))
    )
    ((= ORDER "Tab")
      (setq layout-list (tab_sort layout-list))
    )
  )
  (if (not REV) ; Layout list to be reversed?
    (setq layout-list (reverse layout-list))
  )
  (foreach layout layout-list
    (prompt
      (strcat
        "\nPlotting layout " (itoa (car layout)) ", \""
        (cadr layout) "\"...\n"
      )
    )
    (setq
      layout-array (vlax-safearray-fill layout-array (cdr layout))
      plot (vla-get-Plot curdwg)
    )
    (vla-SetLayoutsToPlot plot layout-array)
    (vla-put-NumberOfCopies plot QTY)
    (setq errmsg (vl-catch-all-apply 'vla-PlotToDevice (list plot DEVICE)))
    (if (vl-catch-all-error-p errmsg)
      (prompt
        (strcat
          "\nERROR: Plot failed due to following condition:\n       "
          (vl-catch-all-error-message errmsg)
          "\n"
        )
      )
    )
  )
  (princ)
) ; End plotall_layouts


(princ)

;;; ==========================================================================
;;; End PLOTALL.LSP
;;; ==========================================================================

Comes with a dialog box too.
Code: [Select]
//// -------------------------------------------------------------------------
//// File     : PlotAll.dcl
//// Author   : Steve Johnson
//// Purpose  : Dialogue box definition for PLOTALL command.
//// -------------------------------------------------------------------------


/// --------------------------------------------------------------------------
/// Turn off error checking
/// --------------------------------------------------------------------------

dcl_settings : default_dcl_settings { audit_level = 0; }


/// --------------------------------------------------------------------------
/// Widget: plotall_main
/// This is the main PLOTALL dialogue box.
/// --------------------------------------------------------------------------

plotall_main : dialog {
  label = "PlotAll.lsp - Plots all layouts in current drawing";
  : popup_list {
    key = "device_list";
    label = "Device  ";
  }
  spacer;
  : row {
    : popup_list {
      key = "order_list";
      label = "Order    ";
    }
    : toggle {
      key = "reverse";
      label = "Reverse";
    }
  }
  spacer;
  : edit_box {
    key = "quantity";
    label = "Quantity";
  }
  spacer;
  ok_cancel;
  errtile;
}

/// --------------------------------------------------------------------------
/// End PlotAll.dcl
/// --------------------------------------------------------------------------

ELOQUINTET

  • Guest
plotting lisp
« Reply #4 on: November 19, 2003, 04:07:28 PM »
mmm doesn't seem to do what i want. i created a drawing with 2 layouts (1 and 2) then i tried to print 2 sets using the numeric function. it printed everything but it printed (2) #1 layouts then (2) #1 layouts. i want it for printing multiple coallated sets of shop and production drawings. any ideas?

dan

daron

  • Guest
plotting lisp
« Reply #5 on: November 19, 2003, 04:12:19 PM »
Sorry. I was told that it is supposed to plot all layouts in order. I've got a few plotting utilities I've written, but not to do that.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #6 on: November 19, 2003, 05:34:59 PM »
Wouldn't this work?  (not tested)

CAB

Code: [Select]
(Defun C:PT
   (/ PLO_LAYOUTS PLO_CNTR PLO_CNTR2 PLO_LIST PLO_LAYOUTTAB)
  (vl-load-com)
  (setvar "FILEDIA" 0)
  (setvar "CMDDIA" 0)
  (initget 3) ; disallow 0 or <0
  (setq nofc (getint "Enter number of sets: <1>"))
  (setq nofc (if nofc nofc 1 ))
  (while (> nofc 1)
    (setq PLO_LAYOUTS
  (vla-get-layouts
    (vla-get-activedocument (vlax-get-acad-object))
  )
 PLO_CNTR 0
 PLO_CNTR2 0
    )
    (repeat (vla-get-count PLO_LAYOUTS)
      (setq PLO_LIST (cons (setq PLO_CNTR (1+ PLO_CNTR)) PLO_LIST))
    )
    (vlax-for PLO_LAYOUT PLO_LAYOUTS
      (setq PLO_LIST (subst (vla-get-name PLO_LAYOUT)
   (vla-get-taborder PLO_LAYOUT)
   PLO_LIST
    )
      )
    )
    (setq PLO_LIST (reverse PLO_LIST))
    (while (/= PLO_CNTR2 (1- PLO_CNTR))
      (setq PLO_LAYOUTTAB (nth PLO_CNTR2 PLO_LIST))
      (command "-PLOT" "n" PLO_LAYOUTTAB "" "" "" "" "" "")
      (setq PLO_CNTR2 (1+ PLO_CNTR2))
    )
    (setq nofc (1- nofc))
  )

  (setvar "FILEDIA" 1)
  (setvar "CMDDIA" 1)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
plotting lisp
« Reply #7 on: November 20, 2003, 08:46:48 AM »
hey cab just tried, didn't work  :(

it just printed one set. thanks for trying

dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #8 on: November 20, 2003, 07:35:51 PM »
dan
lets try again.
changed some of your code.

Code: [Select]
(Defun C:PT
   (/ PLO_LAYOUTS PLO_CNTR PLO_LIST PLO_LAYOUTTAB)
  (vl-load-com)
  (setvar "FILEDIA" 0)
  (setvar "CMDDIA" 0)
  (initget 6) ; disallow 0 or <0
  (setq nofs (getint "Enter number of sets: <1>"))
  (setq nofs (if (or nofs (= nofs 0)) nofs  1))
  (setq PLO_LAYOUTS
(vla-get-layouts
  (vla-get-activedocument (vlax-get-acad-object))
)
  )
  (vlax-for PLO_LAYOUT PLO_LAYOUTS
    (setq plo_list (cons (vla-get-name PLO_LAYOUT) plo_list))
  )
  (setq PLO_LIST (reverse PLO_LIST))
  (while (>= nofs 1)
    (setq plo_cntr 0)
    (repeat (1- (length plo_list)) ; plot all but MODEL
      (setq PLO_LAYOUTTAB (nth PLO_CNTR PLO_LIST))
      (command "-PLOT" "n" PLO_LAYOUTTAB "" "" "" "" "" "")
      (setq PLO_CNTR (1+ PLO_CNTR))
    )
    (prompt "\nPlot Set Complete")
    (setq nofs (1- nofs))
  )

  (setvar "FILEDIA" 1)
  (setvar "CMDDIA" 1)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
plotting lisp
« Reply #9 on: November 21, 2003, 06:09:27 AM »
Not that I want to encourage the "gimme" mentality but if anyone can use it in their own effort to write code, below is an ActiveX approach to the problem. It's just a minimum solution that can be expanded to give more control.

Code: [Select]
(defun C:PLOTSETS (/ lst llst numCopies name acapp doc layouts plotobj)
  (setq acapp   (vlax-get-acad-object)
        doc     (vla-get-activeDocument acapp)
        layouts (vla-get-layouts doc)
        plotobj (vla-get-plot doc))
  (vlax-for layout layouts
    (if (/= (setq name (vla-get-name layout)) "Model")
      (setq lst (cons (list (vla-get-tabOrder layout)
                            name
                            (vla-get-configName layout)
                      ) lst))))
  (setq lst  (vl-sort lst (function (lambda (a b) (< (car a) (car b)))))
        llst (mapcar 'cadr lst))
  (cond ((> (setq numCopies (getint "\nNumber of copies: ")) 0)
         (vla-setLayoutsToPlot
           plotobj
           (vlax-make-variant
             (vlax-safearray-fill
               (vlax-make-safearray vlax-vbString (cons 0 (1- (length llst))))
               llst)))
         (vla-startBatchMode plotobj (length llst))
         (vla-put-numberOfCopies plotobj numCopies)
         (vla-plotToDevice plotobj)
         (vla-put-numberOfCopies plotobj 1))
        (T (princ "\nNo plots specified"))
  )
  (mapcar 'vlax-release-object (list plotobj layouts doc acapp))
  (princ)
)

SMadsen

  • Guest
plotting lisp
« Reply #10 on: November 21, 2003, 06:13:35 AM »
Oops, violation of the Daron Act spotted! Throw in a (vl-load-com) somewhere in the beginning of C:PLOTSETS.

Sorry, Daron!

ELOQUINTET

  • Guest
plotting lisp
« Reply #11 on: November 21, 2003, 08:41:48 AM »
cab your last post works great. just to let you know madsen i wanted the sets to be coallated. much thanks

dan

SMadsen

  • Guest
plotting lisp
« Reply #12 on: November 21, 2003, 08:58:46 AM »
Quote from: eloquintet
just to let you know madsen i wanted the sets to be coallated. much thanks

Don't know what that word means (foreigner here) but just to let you know, if it means arranged like 1-2-3, 1-2-3 etc., it would be very very easily modified with a minimum of effort.

ELOQUINTET

  • Guest
plotting lisp
« Reply #13 on: November 21, 2003, 09:10:48 AM »
yes that's what it means 1-2-3 1-2-3 but cabs lisp does just that so i'm fine just wanted to let you know why yours didn't work for me. thanks

dan

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
plotting lisp
« Reply #14 on: November 21, 2003, 09:21:17 AM »
> if anyone can use it in their own effort to write code

I think I can find a use for it. :D
thanks Mr. Madsen.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
plotting lisp
« Reply #15 on: November 21, 2003, 09:23:00 AM »
You're welcome, Mr. Thomas.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #16 on: November 21, 2003, 09:25:08 AM »
Yes, thanks Mr Madson
Allways an education :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
plotting lisp
« Reply #17 on: November 21, 2003, 10:32:33 AM »
HEY!!

Mark make me an admin!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ELOQUINTET

  • Guest
plotting lisp
« Reply #18 on: November 21, 2003, 11:27:51 AM »
we're not that foolish se7en  :lol:  :lol:  :lol:

dan

daron

  • Guest
plotting lisp
« Reply #19 on: November 21, 2003, 11:41:23 AM »
Hehehe.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #20 on: November 24, 2003, 04:03:00 PM »
I would like to expand the above routine.
So before I start changing the routine I was hoping for your thoughts.

1) the routine uses the last plot configuration. As I often plot to my HP1120C during review
and a "Plot to File" Plot Set Up for final sets, it would be a time saver to use a Plot Style
or perhaps even picking one at the start of the routine rather than hard coding a "Page Setup" name.
So the choice might be: Use last plot set up or Pick a Page Set up.


2) I often have paper space tabs that are working or preliminary that should not be included in the
Full Set version of the plot. I was thinking about prefixing those with * or ~ and test for that character
to prevent them from being included in the plot set.

 So before i charge down a dead end road let me hear your thoughts.:)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
plotting lisp
« Reply #21 on: November 24, 2003, 04:32:23 PM »
CAB, I'm going to put something up on the swamp files for you to look at. They might not be exactly what you are looking for, but you might be able to gleen some info from them. I'll let you know when they are up.





They're up. Look under a folder with your name on it.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #22 on: November 24, 2003, 06:31:43 PM »
Great, I'm sure I'll learn something.

Every little step forward ya-know. :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
plotting lisp
« Reply #23 on: November 25, 2003, 09:04:01 AM »
hey cab sorry for the delayed response i've been extremely busy trying to knock out a few jobs before vacation. ummm as far as your message goes, i think it would be great to introduce those options but...

for me that would be great but i believe i'm the only one using page setups here at this time  :roll:  and i have to work on others drawings which don't use them. i think the sketch idea is a pretty good one as far as designating non plot layouts with an asterisk in front. i noticed this sort of problem on a job that i was just working on. i had a page setup for modelspace to print out things for me to look at to the small printer. well when i printed out the full set it printed my modelspace layout which i didn't need then. these all sound like good ideas to me let me know how it goes  :wink:

dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #24 on: November 25, 2003, 09:26:57 AM »
dan

actually thoses features were for me. :D

I usually have between 6 and 10 tabs in each main drawing, just depends on the house size / complexity.

So there are others of us here with needs and wants too. 8)


Here is the revised code and will not plot Model Space or tabs with ~ in the name.

Code: [Select]
;; plot all paper space tabs, ignore Model Space
;; ignore tabs with ~ in the name
(Defun C:PT
   (/ plo_layouts plo_cntr plo_list plo_layouttab)
  (vl-load-com)
  (setvar "FILEDIA" 0)
  (setvar "CMDDIA" 0)
  (initget 6) ; disallow 0 or <0
  (setq nofs (getint "Enter number of sets: <1>"))
  (setq nofs (if (or nofs (= nofs 0))
      nofs
      1
    )
  )
  (setq plo_layouts
(vla-get-layouts
  (vla-get-activedocument (vlax-get-acad-object))
)
  )
  (vlax-for plo_layout plo_layouts
    (setq plo_list (cons (vla-get-name plo_layout) plo_list))
  )
  ; make sure to plot tabs left to right in order
  (setq plo_list (if (= (car plo_list) "Model")
  plo_list
  (reverse plo_list)
)
  )
  (while (>= nofs 1)
    (setq plo_cntr 0)
    (repeat (length plo_list)
      (setq plo_layouttab (nth plo_cntr plo_list))
      (cond
((= plo_layouttab "Model")
nil ; skip Model Space
) ; end cond 1
((> (vl-string-search "~" plo_layouttab) 0)
nil ; skip if ~ in tab name
) ; end cond 2
(T
(command "-PLOT" "n" plo_layouttab "" "" "" "" "" "")
) ; end cond 3
      ) ; end cond
      (setq plo_cntr (1+ plo_cntr))
    )
    (prompt "\nPlot Set Complete")
    (setq nofs (1- nofs))
  )

  (setvar "FILEDIA" 1)
  (setvar "CMDDIA" 1)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
plotting lisp
« Reply #25 on: November 25, 2003, 10:26:52 AM »
okie dokie i'll give it a go thanks

dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #26 on: December 05, 2003, 04:25:39 PM »
Daron,

You were going to upload some file to look at.

Just a reminder :)  Hint Hint

I had to plot a job yesterday with 14 tabs in the draiwing but could not use the routine above,
because I had previously plotted to my DJ1120C and needed to change the  plot style in each tab.

When you have time.

Thanks

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
plotting lisp
« Reply #27 on: December 08, 2003, 10:02:33 AM »
I thought you saw them. PM time.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #28 on: December 08, 2003, 10:54:25 AM »
Sorry, was looking in the Lilly pond :oops:

The file is VERY informative, Thanks

Was trying to get this to work. No Luck.
(lost in X land)  :)

Code: [Select]
(setq cfg (vlax-safearray->list
      (vlax-variant-value (vla-Get-PlotConfigurations LayoutObj))
    ))



CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
plotting lisp
« Reply #29 on: December 08, 2003, 10:56:06 AM »
What is the value of layoutObj?

ELOQUINTET

  • Guest
plotting lisp
« Reply #30 on: December 08, 2003, 11:55:55 AM »
hey guys i just encountered the problem too when printing an old job which used a different printer. :cry: keep me informed on the updates thanks

dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #31 on: December 08, 2003, 12:45:32 PM »
Daron,

In this code pslayout = LayoutObj



Code: [Select]
   (setq
      curdwg   (vla-get-ActiveDocument (vlax-get-Acad-Object))
      pslayout (vla-get-Layout (vla-get-PaperSpace curdwg))
    )
 ; Call RefreshPlotDeviceInfo before GetPlotDeviceNames
    (vla-RefreshPlotDeviceInfo pslayout)
    (setq sty (vlax-safearray->list
      (vlax-variant-value (vla-GetPlotStyleTableNames pslayout))
    ))

    (setq cfg (vlax-safearray->list
      (vlax-variant-value (vla-Get-PlotConfigurations pslayout))
    ))


Code: [Select]
LayoutObj = #<VLA-OBJECT IAcadLayout 069c7a2c>
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
plotting lisp
« Reply #32 on: December 10, 2003, 05:05:44 PM »
Well I found the answer,
Stole this code today, :D

It sets all layouts in the drawing to a "page setup" entered by the user.
I'm going to modify to allow some sort of pick list, I guess that would have to be dcl dialog box or
a numbered list displayed on the text screen to pick from.
Anyone have a "Text Screen" pick list routine?

CAB

Code: [Select]
(defun c:psetup (/ lst page res)
 (setq lst (mapcar 'strcase (getPagesetups)))
 (while (not page)
  (setq page (strcase (getstring T "\nspecify pagesetup to apply: ")))
  (if (or (= "" page) (not (member page lst)))
   (progn (princ "\npagesetup not found") (setq page nil))
   )
  )


 (initget "All Current")
 (if
  (not
   (setq
    res
    (getkword
     "\n[All/Current]apply pagesestup to which layout(s) : ")))
  (setq res "All")
  )


 (if (= "All" res)
   ; ignore Model Space
  (foreach x (vl-remove "Model" (layoutlist)) (putPagesetup x page))
  ;(foreach x (layoutlist) (putPagesetup x page)) ; Include Model Space
  (putPagesetup (getvar "ctab") page)
  )
 (princ "\nFinished")
 (princ)
 )



; Jason Piercey . May 16th, 2003
; assign a pagesetup to a layout
; [layout] - string, layout name
; [setup] - string, pagesetup to assign
; return: T or nil
(defun putPagesetup (layout setup / layouts plots)
 (defun item-p (collection item)
  (if
   (not
    (vl-catch-all-error-p
     (vl-catch-all-apply
      '(lambda () (setq item (vla-item collection item))))))
   item
   )
  )
 (and
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-activedocument *acad*)))
  (setq layouts (vla-get-layouts *doc*))
  (setq plots (vla-get-plotconfigurations *doc*))
  (setq layout (item-p layouts layout))
  (setq setup (item-p plots setup))
  (not (vla-copyfrom layout setup))
  )
 )


(defun massoc (key alist / x nlist)
 (foreach x alist
  (if (eq key (car x))
   (setq nlist (cons (cdr x) nlist))
   )
  )
 (reverse nlist)
 )

; Return: list of all pagesetups defined in the current drawing or nil
(defun getPagesetups ()
 (massoc 3 (dictsearch (namedobjdict) "Acad_PlotSettings"))
 )

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: plotting lisp
« Reply #33 on: February 28, 2006, 03:27:26 PM »
Hey CAB,

Did you ever set up this routine with a dialogue to pick the pagesetups from?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #34 on: February 28, 2006, 03:55:29 PM »
If you mean "Import Page Set Up" from another drawing,
then NO. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: plotting lisp
« Reply #35 on: February 28, 2006, 04:00:31 PM »
Not from other drawings. Just a pick list to set all tabs to a certain pagesetup. Kinda like the one in your plottabs routine minus the plotting part.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #36 on: February 28, 2006, 06:55:15 PM »
No but I threw this together.
Needs testing. :-)

Code removed, see update in another post.
« Last Edit: February 28, 2006, 10:40:41 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: plotting lisp
« Reply #37 on: February 28, 2006, 07:10:29 PM »
No but I threw this together.
Needs testing. :-)

Seemed to work on my one drawing.  Only one layout, but it copied it over.  The only problem I had was that my titles were too long to see.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: plotting lisp
« Reply #38 on: February 28, 2006, 07:13:40 PM »
No but I threw this together.
Needs testing. :-)

bloody amazing ! , your attitude.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #39 on: February 28, 2006, 07:21:42 PM »
Updated the DCL file with wider list boxes.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #40 on: February 28, 2006, 07:30:02 PM »
No but I threw this together.
Needs testing. :-)

bloody amazing ! , your attitude.
You'll have to clarify, I'm slow at times.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: plotting lisp
« Reply #41 on: February 28, 2006, 07:43:06 PM »
expressing my admiration for how helpfull you are. !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #42 on: February 28, 2006, 07:54:04 PM »
Well thank you sir.
I love to write code & play tennis.
Neither of which I do that well compared to the talent I see here & there.
But I do it for me so that's ok. So i do it every chance I get. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #43 on: February 28, 2006, 10:47:58 PM »
The updated code is Here
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: plotting lisp
« Reply #44 on: March 01, 2006, 06:07:14 PM »
Not from other drawings. Just a pick list to set all tabs to a certain pagesetup. Kinda like the one in your plottabs routine minus the plotting part.
ron
is that what you were looking for?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: plotting lisp
« Reply #45 on: March 01, 2006, 06:16:30 PM »
Exactly :). Thanks once again CAB.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC