Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Print all Layouts printer test

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
C.Utzinger
1299 Views, 5 Replies

Print all Layouts printer test

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)
)
5 REPLIES 5
Message 2 of 6
DannyNL
in reply to: C.Utzinger

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)
)
Message 3 of 6
C.Utzinger
in reply to: DannyNL

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

Message 4 of 6
DannyNL
in reply to: C.Utzinger

That's no problem; use this:

 

....
(alert (strcat "The layout " (vla-get-Name FPD_Layout ) " will use the following standard printer: " FPD_PlotDeviceName))
....
Message 5 of 6
C.Utzinger
in reply to: DannyNL

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!

Message 6 of 6
DannyNL
in reply to: C.Utzinger

Glad I could help Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report