macro to print to default printer

Gotta problem.

We are remodeling our office and people are moving but the printersaren't. The problem is Sw doesn't print to the default printer, itprints to whatever the drawing has for printer settings.

So, we have users across the buliding that are printing SWdocuments and then realize that the printer isn't next to themanymore.

So i was wondering if anyone has a macro that would print to thewindows default printer?SolidworksApi macros
Comments 7
SF
SF 2007-10-31
Hello Rob,

I believe what you are after is:

ModelDoc2:: PrintDirect

Description:

This method prints the current document to the default printer.

The macro you are after would be something in the lines:

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim modelDoc As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks
Set modelDoc = swApp.activedoc

modelDoc.printDirect

end sub

Hope it helps
--Stav.

P.S you can also use modeDoc2:: Printer to get or set the defaultprinter.



SF
SF 2007-12-20
Hi, is there a way to write into the macro which printer toselect? PrintDirect seems limited as you can't specify which sheetsto print etc. We have a macro to print our drawings however wouldlike the user running the macro to be able to specify which printerthey use.

Thanks, Ben
SF
SF 2007-12-20
Hello Ben,

Yes there is.
Have a look at

ModelDoc2::Printer.
Description

This property gets or sets the default printer for this document.


Once you set your default printer:

Remarks

ModelDoc2::PrintDirect and ModelDocExtension::PrintOut2 use thissetting if you pass an empty string to printer.


Cheers,

--Stav.

SF
SF 2007-12-21
Thanks Stav,

I've worked out how to use the PrintOut2 command, but was trying tosee if there is a way to see what the printer names are that areavailable to print to. I basically want the person running themacro to be able to select which printer their drawings will getprinted to, from a list of available printers on their computer.

Is there any way to do this?

Thanks, Ben
SF
SF 2007-12-21
For getting a list of printers, I've used enumeratingprinters API as describe by Microsoft KB 200611. (http://support.microsoft.com/kb/200611).Windows API commands are a bit complicated, but I was able to copythe sample code and modify it for my own purposes.

In VB6 there is a printer object (http://msdn2.microsoft.com/en-us/library/aa267233.aspx),it's not clear to me it's availabe in SolidWorks VBA though. I'veused this one in VB6 and it's quite a bit more straight forwardthan the one above.


As a strange side note, setting the printer in SolidWorks is casesensitve (which you will have the right case using the enumeratemethod). For some reason when different people at my company map tonetwork printers the case can vary.

MB
SF
SF 2008-01-07
Thanks Michael,

Yeah the main reason I'm needing to look into getting the list ofprinters is we have varying case for our printer names too.
SF
SF 2008-04-25
For VB2005 I'm using this:

Dim myPrinter As String

cbPrinter.Items.Clear()

For Each myPrinter InSystem.Drawing.Printing.PrinterSettings.InstalledPrinters
cbPrinter.Items.Add(myPrinter)
Next

--John