Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

need a simple SW2009 print macro 4

Status
Not open for further replies.

SUEDE

Mechanical
Sep 9, 2004
5
I am looking for a *.swp file that I can add to my SolidWorks 2009 toolbar that allows me to print the current drawing file on the screen to a specific printer and at a specific size.

My issue is that I have 5 printers on the premises. I am tired of fumbling through the print options. I would like to hit a print button and go pick the print up. I would like to set up a toolbar button to say print a B-size to HP 5200 BW printer. Then another toolbar button to print A-size to HP 9500 color printer. ETC.

Does anyone have the VBA skills to provide such an invaluable macro?
 
Replies continue below

Recommended for you

Would it be possible? Yes. Free? Probably not at this time.

-handleman, CSWP (The new, easy test)
 
I believe you are looking for something like this:

Note the Paper Size and printer names depends of printer settings.

If you aren't sure what are the correct values. I'm proposing to do the following:

Set the first printer as default and choose required papper size on "Page Setup" Dialog. Uncomment
'Debug.Print swPageSetup.PrinterPaperSize
'Debug.Print swModel.Printer lines and copy-paste the values from output window.

Reply these actions for every printer and paper size you would like the macro being created.

Do you know how to add the macro to custom button? If no - please let me know I explain how to do this.


- - - - - - - - - - -
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPageSetup As SldWorks.PageSetup

Const Printer As String = "Microsoft XPS Document Writer"

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swPageSetup = swModel.PageSetup

'Debug.Print swPageSetup.PrinterPaperSize
'Debug.Print swModel.Printer

'A4 = 9, A3 = 8
swPageSetup.PrinterPaperSize = 8

swPageSetup.Orientation = 2 ' 1=Portrait '2 = Landscape

swModel.Extension.PrintOut2 Empty, 1, False, Printer, ""

End Sub
- - - - - - - - - - -

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
 
This is amazing, ArtemTat! This code will save me easily 1 hour a week. I am very happy. I already programmed 3 custom buttons and they work great!

one more thing. Is there a way to 'scale to fit'? For instance, if I want to print an A3 drawing on my screen to an A4 piece of paper, is there a simple code to add to the code you already gave me?
 
I think the appropriate method is PageSetup::ScaleToFit.

Add the following line to your code:

...
swPageSetup.ScaleToFit = True
...

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
 
I think this is a good idea, Deepak.

BTW. The option buttons can also be used. Or for example a combination of option buttons for printer types and paper sizes. And the checkbox for "Scale to Fit" option.

But this can return us to initial SW dialogs which SUEDE would like to avoid.

SUEDE, you can also create a separate toolbar for your buttons. Some time ago I've attached a simple addin for doing this. by some reason not all users have been able to make it work :-(.

refer
Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
 
Great! The scaleToFit code did the trick. I am very grateful.

In the future, I may begin to play with the "single macro" or "separate toolbar" ideas as well

Thanks for making my week!



 
Uncommenting the two debug lines isn't doing anything for me. Should it give me some type of dialog when I run it that way? I'm unable to set the paper size in the macro.

Joe
SW Office 2008 SP5.0
P4 3.0Ghz 3GB
ATI FireGL X1
 
Joe,

The debug commands output to the Immediate window in the VBA IDE/Editor. Click the icon of a window with an exclamation point to hide/show the Immediate window.
 
Ah... OK. My "Immediate Window" wasn't set to be visible. Thanks.

Joe
SW Office 2008 SP5.0
P4 3.0Ghz 3GB
ATI FireGL X1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor