×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Can you batch lisp change plotter names on multiple layer drawings?

Can you batch lisp change plotter names on multiple layer drawings?

Can you batch lisp change plotter names on multiple layer drawings?

(OP)
I have about 900 drawings with multiple layers.  Unfortunately when the template was created it was using a plotter name that has now become obsolete.  I want to know if a batch lisp program could open the drawing and change all the layers to default windows plotter, apply the setting, save, exit and open the next drawing in the batch?  

Thanks in advance

RE: Can you batch lisp change plotter names on multiple layer drawings?

Would you be concerned about having to do this in the future when you change printers again?

Another option is it use a reactor lisp that when the print command is called the reactor checks what printer the drawing thinks it will use vs what printer is valid.

CODE

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Command Reactors to set entities on the appropiate layer
; without user intervention.
;
; Programmed by: Kevin Petursson
; Date: October 6, 2006
; Revisions: 1 - October 16, 2006.  Added 'defun setLayerCurrent' to
;              check for layer prior to setting layer. If the layer
;              does not exist, it will be created.
;              Added Printer Checking routines
;
; Big thanks to Lee Ambrosius and his article in July 2006
; AUGIWorld magazine on Command Reactors
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Load the Visual LISP library
(vl-load-com)

; Check to see if our custom command reactors
; have been loaded into the current drawing
(if (= hyp-rctCmds nil)
  ; Add the command reactors and the custom callbacks
  (setq hyp-rctCmds (vlr-command-reactor nil '((:vlr-commandCancelled . hyp-cmdAbort)
                           (:vlr-commandEnded . hyp-cmdAbort)
                           (:vlr-commandCancelled . hyp-cmdAbort)
                           (:vlr-commandWillStart . hyp-cmdStart)
                          )
            )
  )
)

; Callback used when the user presses ECSape
; or when the command ends by itself or due to
; a problem
(defun hyp-cmdAbort (param1 param2)
  ; Check to see if our global variable has a value
  ; if it does the set the current layer
  (if (and (/= hyp-gClayer nil)(/= (strcase (getvar "clayer")) (strcase hyp-gClayer)))
    (setvar "clayer" hyp-gClayer)
  )
  ; Clear the global variable
  (setq hyp-gClayer nil)
)

; Callbackused when a command is started
(defun hyp-cmdStart (param1 param2 / currentlayer)
  ; Store the current layer in a global variable
  (setq hyp-gClayer (getvar "clayer"))
  ;check to see what command has been started, the
  ; command name is stored in the param2 variable
  (cond
    ; If either the QDIM command
    ; is active the set the current layer to Dimensions
    ( (or
    (= (car param2) "DIMALIGNED")
    (= (car param2) "DIMANGULAR")
    (= (car param2) "DIMBASELINE")
    (= (car param2) "DIMCONTINUE")
    (= (car param2) "DIMDIAMETER")
    (= (car param2) "DIMLINEAR")
    (= (car param2) "DIMORDINATE")
    (= (car param2) "DIMRADIUS")
    (= (car param2) "QDIM")
      )
      (setLayerCurrent "Dimensions")
    )
    ; If either the HATCH, BHATCH or GRADIENT command
    ; is active the set the current layer to Hatching
    ( (or
    (= (car param2) "HATCH")
    (= (car param2) "BHATCH")
    (= (car param2) "GRADIENT")
      )
      (setLayerCurrent "Hatching")
    )
    ; If either the MTEXT, DTEXT, QLEADER, LEADER command
    ; is active the set the current layer to Text
    ( (or
    (= (car param2) "TTEXT")
    (= (car param2) "DTEXT")
    (= (car param2) "MTEXT")
    (= (car param2) "LEADER")
    (= (car param2) "QLEADER")
      )
      (setLayerCurrent "Text")
    )
    ; If either the LAYER command
    ; is active the clear global variable for the current layer
    ( (or
    (= (car param2) "LAYER")
    (= (car param2) "-LAYER")
      )
      (setq hyp-gClayer nil);Clear the global variable to allow the layer command to change the current layer
    )
    ; If either the Plot command
    ; is active the clear global variable for the current layer
    ( (or
    (= (car param2) "PLOT")
    (= (car param2) "-PLOT")
      )
      (progn
        (setq hyp-gClayer nil);Clear the global variable to allow the layer command to change the current layer
    (SwitchDefaultPrinter);confim the printer being asked for is a current device
      )
    )
  )
)

;Set the current layer.  If the layer specified does not exist, it will be created.
;Thank to Lee Ambrosius for his help with this code.
(defun setLayerCurrent (layname / acadObj docObj layColl layObj colour)
  (if (= (tblobjname "layer" layname) nil)
    (progn
      (setq acadObj (vlax-get-acad-object))
      (setq docObj (vla-get-activedocument acadObj))
      (setq layColl (vla-get-layers docObj))
      (setq layObj (vla-add layColl layname))
      (setq colour 0)
      (if (= layname "Dimensions")(setq colour 4))
      (if (= layname "Hatching")(setq colour 8))
      (if (= layname "Text")(setq colour 4))
      (vla-put-color layObj colour)
      (setvar "clayer" layname)
    )
    (setvar "clayer" layname)
  )
)

;;;
; Check if the plotter last saved with the file is in a list of
; current devices.  If it is not, change  the plot device to a current
; device, If it is, leave things alone.
;;;
(defun SwitchDefaultPrinter (/ Default ad OldPlotDevicee PlotDevices NonCurrentDevice)
  (setq Default "\\\\bdn01ps001\\drafting_lj8000");Set default printer
  ;create list of current plot devices
  (setq PlotDevices (list "Bluebeam PDF Printer"
        "\\\\bdn01ps001\\black_laser"
        "\\\\bdn01ps001\\ccc_colorlaser"
        "\\\\bdn01ps001\\ccc_lj8150"
        "\\\\bdn01ps001\\color_laser"
        "\\\\bdn01ps001\\drafting_lj8000"
        "\\\\bdn01ps001\\drafting_plotter"
        "Black_Laser_D_to_B_Batch.pc3"
        "Color_Laser_A_to_A.pc3"
        "Color_Laser_A_to_B.pc3"
        "Color_Laser_B_to_B.pc3"
        "Color_Laser_C_to_B.pc3"
        "Color_Laser_D_to_B.pc3"
        "Color_Laser_D_to_B_PID_Batch.pc3"
        "Color_Laser_D_to_D_PID_Batch.pc3"
        "Drafting_Plotter.pc3"
        "Drafting_Plotter_Batch.pc3"
        "Drafting_Plotter_BW.pc3"
        "Drafting_Plotter_D_to_D_BW_Batch.pc3"
  ))
  (setq ad (vla-get-activedocument (vlax-get-acad-object)));Set variable to hold reference to the active document

  (setq OldPlotDevice (GetActivePlotDevice ad));Set variable to hold reference to current plot device
  ;comapre the old plot device to a list of current devices
  (if (= nil (vl-position OldPlotDevice PlotDevices))
    (setq NonCurrentDevice 0);Device not found in list
    (setq NonCurrentDevice 1);Device found in list
  )
  (if (= 0 NonCurrentDevice);if the current device is not in the current list of active devices.
    (progn
      (vla-put-ConfigName (vla-get-ActiveLayout ad) Default);Change the plotter name to be used by the active layout
      (setq PrinterSwitched 1)
    )
    ;other wise leave it alone.
  )
  (if (= nil (vl-position (vlax-get-property (vla-get-ActiveLayout ad) "StyleSheet") (GetPlotStyleTableNames ad)));check the list of CTB files for the current requested CTB
    (vlax-put-property (vla-get-ActiveLayout ad) "StyleSheet" "Black_Laser Dark.ctb");Current CTB Not found, set CTB file to "Black_Laser Dark.ctb"
    ;Curerent CTB found, don't worry about it
  )
  (if (= 1 PrinterSwitched)
    (progn
      (if (/= nil (vl-position "11x17" (GetCanonicalMediaNames ad)));check list of paper sizes for 11X17
        (vlax-put-property (vla-get-ActiveLayout ad) "CanonicalMediaName" "11x17");11X17 found in the list of paper sizes, set paper size to 11x17
        ;11x17 is not in the list, don't worry about it
      )
      (vlax-put-property (vla-get-ActiveLayout ad) "CenterPlot" -1);Set to center the plot on the paper
      (vlax-put-property (vla-get-ActiveLayout ad) "StandardScale" 0);Set to "Scale to Fit
      (vlax-put-property (vla-get-ActiveLayout ad) "PlotType" 1);Set to plot extents
      (vlax-put-property (vla-get-ActiveLayout ad) "PlotRotation" 1);Set to print Landscape
    )
  )
  (princ)
)

(defun GetActivePlotDevice (ad)
  (vla-get-ConfigName
    (vla-get-ActiveLayout ad))
)

(defun GetCanonicalMediaNames (ad)
  (vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad))
  (vlax-safearray->list
    (vlax-variant-value
      (vla-GetCanonicalMediaNames
        (vla-item (vla-get-layouts ad) "Model"))))
)

(defun GetPlotStyleTableNames (ad)
  (vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad))
  (vlax-safearray->list
    (vlax-variant-value
      (vla-getplotstyletablenames
        (vla-item (vla-get-layouts ad) "Model"))))
)

If however you simply wish to change the printer name and save, I'm sure it can be done.  I don't know how to open and save the drawings, but this bit of code will help with the resettring of the printer name

CODE



(defun c:SwitchDefaultPrinter (/ Default ad OldPlotDevicee PlotDevices NonCurrentDevice)

  (setq Default "\\\\bdn01ps001\\drafting_lj8000");Set default printer
  ;create list of current plot devices
  (setq PlotDevices (list
            "Bluebeam PDF Printer"
        "\\\\bdn01ps001\\black_laser"
        "\\\\bdn01ps001\\ccc_colorlaser"
        "\\\\bdn01ps001\\ccc_lj8150"
        "\\\\bdn01ps001\\color_laser"
        "\\\\bdn01ps001\\drafting_lj8000"
        "\\\\bdn01ps001\\drafting_plotter"
        "Black_Laser_D_to_B_Batch.pc3"
        "Color_Laser_A_to_A.pc3"
        "Color_Laser_A_to_B.pc3"
        "Color_Laser_B_to_B.pc3"
        "Color_Laser_C_to_B.pc3"
        "Color_Laser_D_to_B.pc3"
        "Color_Laser_D_to_B_PID_Batch.pc3"
        "Color_Laser_D_to_D_PID_Batch.pc3"
        "Drafting_Plotter.pc3"
        "Drafting_Plotter_Batch.pc3"
        "Drafting_Plotter_BW.pc3"
        "Drafting_Plotter_D_to_D_BW_Batch.pc3"
  ))
  (setq ad (vla-get-activedocument (vlax-get-acad-object)));Set variable to hold reference to the active document

  (setq OldPlotDevice (GetActivePlotDevice ad));Set variable to hold reference to current plot device
  ;comapre the old plot device to a list of current devices
  (if (= nil (vl-position OldPlotDevice PlotDevices))
    (setq NonCurrentDevice 0);Device not found in list
    (setq NonCurrentDevice 1);Device found in list
  )
  (if (= 0 NonCurrentDevice);if the current device is not in the current list of active devices.
    (vla-put-ConfigName (vla-get-ActiveLayout ad) Default);Change the plotter name to be used by the active layout
    ;other wise leave it alone.
  )
    
  (if (/= nil (vl-position "11x17" (GetCanonicalMediaNames ad)));check list of paper sizes for 11X17
    (vlax-put-property (vla-get-ActiveLayout ad) "CanonicalMediaName" "11x17");11X17 found in the list of paper sizes, set paper size to 11x17
    ;11x17 is not in the list, don't worry about it
  )
  (if (/= nil (vl-position "11x17" (GetPlotStyleTableNames ad)));check the list of CTB files for "Black_Laser Dark.ctb"
    (vlax-put-property (vla-get-ActiveLayout ad) "StyleSheet" "Black_Laser Dark.ctb");set CTB file to "Black_Laser Dark.ctb"
    ;"Black_Laser Dark.ctb" not found, don't worry about it
  )
  (vlax-put-property (vla-get-ActiveLayout ad) "CenterPlot" -1);Set to center the plot on the paper
  (vlax-put-property (vla-get-ActiveLayout ad) "StandardScale" 0);Set to "Scale to Fit
  (vlax-put-property (vla-get-ActiveLayout ad) "PlotType" 1);Set to plot extents
  (vlax-put-property (vla-get-ActiveLayout ad) "PlotRotation" 1);Set to print Landscape
  (princ)
  
)

(defun GetActivePlotDevice (ad)
  (vla-get-ConfigName
    (vla-get-ActiveLayout ad))
)

(defun GetCanonicalMediaNames (ad)
  (vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad))
  (vlax-safearray->list
    (vlax-variant-value
      (vla-GetCanonicalMediaNames
        (vla-item (vla-get-layouts ad) "Model"))))
)

(defun GetPlotStyleTableNames (ad)
  (vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad))
  (vlax-safearray->list
    (vlax-variant-value
      (vla-getplotstyletablenames
        (vla-item (vla-get-layouts ad) "Model"))))
)

And in both of the above LISP's you will need to make a few changes.  ie. the printer names

I hope this helps.

RE: Can you batch lisp change plotter names on multiple layer drawings?

(OP)
Thalon,  

The idea of switching the printer to current default windows printer is that no matter what the name is, it will always print to the default windows plotter.

Thanks for the post.  I will check it out.

RE: Can you batch lisp change plotter names on multiple layer drawings?

Autocad does have a setting to select a default printer, but for whatever reason it doesn't seen to use it at all.

I agree it would be nice if autocad could simply default to the system printer, but I'm not sure how to make that happen.  Perhapse my LISP could be modified to read the value of the system default, and then apply the to the drawing file??

good luck.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources