Print all Layouts printer test

C.Utzinger
Collaborator
Collaborator

Print all Layouts printer test

C.Utzinger
Collaborator
Collaborator

HI

 

I hace the follow simple Routine for printing all Layouts.

 

But if you open a dwg file with definied printers you dont't have installed, then AutoCAD crashes.

 

Is there a possibility to check if the printer is available?

 

 

(defun c:<Test5 ( / layouts)

  (setq layouts (LAYOUTLIST))
 
  (foreach e layouts
     (command "_.-plot" "_n" e "" "" "" "" pause)
  )

  (alert "Alle Layouts gedruckt.")

  (prin1)
)
0 Likes
Reply
Accepted solutions (1)
1,326 Views
5 Replies
Replies (5)

DannyNL
Advisor
Advisor
Accepted solution

I've found something from several year ago that would do the trick more or less.

 

Just add (FixPlotDevice [YourDefaultPrinter] nil) as your first line of code. It will change the current printer on the active layout only if the current one is invalid. If you want to force a new printer for all layouts just change the nil into T.

 

 

(defun FixPlotDevice (FPD_PlotDeviceName FPD_Force / FPD_ActiveDocument FPD_ActiveLayout FPD_ActivePlotDevice FPD_Layouts FPD_PlotDeviceList)
   (setq FPD_ActiveDocument (vla-get-Activedocument (vlax-get-acad-object)))   
   (setq FPD_ActiveLayout   (vla-get-ActiveLayout   FPD_ActiveDocument))      
   (setq FPD_PlotDeviceList (vlax-safearray->list  (vlax-variant-value (vla-GetPlotDeviceNames FPD_ActiveLayout))))
   (if
      (or
         (member FPD_PlotDeviceName FPD_PlotDeviceList)
         (and
            (= (strcase FPD_PlotDeviceName) "DEFAULT")
            (member "Default Windows System Printer.pc3" FPD_PlotDeviceList)
         )
      )
      (progn
         (if
            (= (strcase FPD_PlotDeviceName) "DEFAULT")
            (setq FPD_PlotDeviceName "Default Windows System Printer.pc3")
         )
         (setq FPD_Layouts (vla-get-Layouts FPD_ActiveDocument))
         (vlax-for FPD_Layout FPD_Layouts
            (setq FPD_ActivePlotDevice (vla-get-ConfigName FPD_Layout))
            (if
               (or
                  (not (member FPD_ActivePlotDevice FPD_PlotDeviceList))
                  FPD_Force
               )              
               (vla-put-ConfigName FPD_Layout FPD_PlotDeviceName)             
            )
         )
         (vlax-release-object FPD_Layouts)   
      )
   )
   (vlax-release-object FPD_ActiveDocument)
   (vlax-release-object FPD_ActiveLayout)
)

C.Utzinger
Collaborator
Collaborator

HI

 

I have it now like this. Just a question. Do you now how I can get the Layoutname where it happens?

 

(defun c:<Test7 ()

(defun FixPlotDevice (FPD_PlotDeviceName FPD_Force / FPD_ActiveDocument FPD_ActiveLayout FPD_ActivePlotDevice FPD_Layouts FPD_PlotDeviceList)
   (setq FPD_ActiveDocument (vla-get-Activedocument (vlax-get-acad-object)))   
   (setq FPD_ActiveLayout   (vla-get-ActiveLayout   FPD_ActiveDocument))      
   (setq FPD_PlotDeviceList (vlax-safearray->list  (vlax-variant-value (vla-GetPlotDeviceNames FPD_ActiveLayout))))
   (if
      (or
         (member FPD_PlotDeviceName FPD_PlotDeviceList)
         (and
            (= (strcase FPD_PlotDeviceName) "DEFAULT")
            (member "Default Windows System Printer.pc3" FPD_PlotDeviceList)
         )
      )
      (progn
         (if
            (= (strcase FPD_PlotDeviceName) "DEFAULT")
            (setq FPD_PlotDeviceName "Default Windows System Printer.pc3")
         )
         (setq FPD_Layouts (vla-get-Layouts FPD_ActiveDocument))
         (vlax-for FPD_Layout FPD_Layouts
            (setq FPD_ActivePlotDevice (vla-get-ConfigName FPD_Layout))
            (if
               (or
                  (not (member FPD_ActivePlotDevice FPD_PlotDeviceList))
                  FPD_Force
               )
               (progn              
                 (vla-put-ConfigName FPD_Layout FPD_PlotDeviceName)
                 (alert (strcat "This Layout will use the following standard printer: " FPD_PlotDeviceName))
               )
            )
         )
         (vlax-release-object FPD_Layouts)   
      )
   )
   (vlax-release-object FPD_ActiveDocument)
   (vlax-release-object FPD_ActiveLayout)
)

  (setq prn "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
        prn (vl-registry-read prn "Device")
        prn (substr prn 1 (vl-string-search "," prn))
        layouts (LAYOUTLIST))
 
  (FixPlotDevice prn nil)

  (foreach e layouts
     (command "_.-plot" "_n" e "" "" "" "" pause)
  )

  (alert "Alle Layouts gedruckt.")

(prin1)
)

 

 

Kind regards

0 Likes

DannyNL
Advisor
Advisor

That's no problem; use this:

 

....
(alert (strcat "The layout " (vla-get-Name FPD_Layout ) " will use the following standard printer: " FPD_PlotDeviceName))
....

C.Utzinger
Collaborator
Collaborator

I just had it Smiley LOL

 

 

(defun c:<Test7 ()

(defun FixPlotDevice (FPD_PlotDeviceName FPD_Force / FPD_ActiveDocument FPD_ActiveLayout FPD_ActivePlotDevice FPD_Layouts FPD_PlotDeviceList plist)
   (setq FPD_ActiveDocument (vla-get-Activedocument (vlax-get-acad-object)))   
   (setq FPD_ActiveLayout   (vla-get-ActiveLayout   FPD_ActiveDocument))      
   (setq FPD_PlotDeviceList (vlax-safearray->list  (vlax-variant-value (vla-GetPlotDeviceNames FPD_ActiveLayout))))
   (if
      (or
         (member FPD_PlotDeviceName FPD_PlotDeviceList)
         (and
            (= (strcase FPD_PlotDeviceName) "DEFAULT")
            (member "Default Windows System Printer.pc3" FPD_PlotDeviceList)
         )
      )
      (progn
         (if
            (= (strcase FPD_PlotDeviceName) "DEFAULT")
            (setq FPD_PlotDeviceName "Default Windows System Printer.pc3")
         )
         (setq FPD_Layouts (vla-get-Layouts FPD_ActiveDocument))
         (vlax-for FPD_Layout FPD_Layouts
            (setq FPD_ActivePlotDevice (vla-get-ConfigName FPD_Layout))
            (if
               (or
                  (not (member FPD_ActivePlotDevice FPD_PlotDeviceList))
                  FPD_Force
               )
               (progn              
                 (vla-put-ConfigName FPD_Layout FPD_PlotDeviceName)
                 (setq plist (if plist (strcat plist "\n" (vla-get-Name FPD_Layout)) (vla-get-Name FPD_Layout)))
               )
            )
         )
         (vlax-release-object FPD_Layouts)   
      )
   )
   (vlax-release-object FPD_ActiveDocument)
   (vlax-release-object FPD_ActiveLayout)
   (if plist (alert (strcat "Die folgenden Layouts: \n\n" plist "\n\nwerden mit dem Standarddrucker gedruckt:\n\n" FPD_PlotDeviceName )))
)

  (setq prn "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
        prn (vl-registry-read prn "Device")
        prn (substr prn 1 (vl-string-search "," prn))
        layouts (LAYOUTLIST))
 
  (FixPlotDevice prn nil)

  (foreach e layouts
     (command "_.-plot" "_n" e "" "" "" "" pause)
  )

  (alert "Alle Layouts gedruckt.")

(prin1)
)

 

Thank you anyway!

DannyNL
Advisor
Advisor

Glad I could help Smiley Happy

0 Likes