Sunday, March 13, 2005

Lisp sample on how to change plot devices

I got a request from a user that wanted to change the plot devices on his drawings. They had been changed from lets say OLD01.PC3 to NEW01.PC3. Here is one way. This code could be run manually on a drawing or when drawings are opened by making use of acaddoc.lsp that loads whenever a drawing opens.
; ChangePlotDevices.lsp
; Sample command CPD on how to change
; plot devices on all layouts
; Changes have to be made to match
; your old and new plot devices
;
; By Jimmy Bergmark
; Copyright (C) 2005 by JTB World
; www.jtbworld.com
; 2005-01-13
;

(defun PutPlotDevice (layout PlotDeviceName)
  (vla-put-ConfigName
    layout
    PlotDeviceName)
)

(defun GetPlotDevice (layout)
  (vla-get-ConfigName
    layout)
)

(defun changePlotDevice (layout)
  (cond
    ((= (GetPlotDevice layout) "OLD01.pc3")
      (PutPlotDevice layout "NEW01.pc3"))
    ((= (GetPlotDevice layout) "OLD02.pc3")
      (PutPlotDevice layout "NEW01.pc3"))
    ((= (GetPlotDevice layout) "OLD03.pc3")
      (PutPlotDevice layout "NEW02.pc3"))
    (t (PutPlotDevice layout "None"))
  )
)

(defun c:CPD ()
  (setq layouts
    (vla-get-Layouts
      (vla-get-activedocument
        (vlax-get-acad-object))))
  (vlax-for layout layouts
    (changePlotDevice layout)
  )
  (princ)
)

No comments:

Post a Comment