×
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

need a simple SW2009 print macro
4

need a simple SW2009 print macro

need a simple SW2009 print macro

(OP)
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?  

RE: need a simple SW2009 print macro

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

-handleman, CSWP (The new, easy test)

RE: need a simple SW2009 print macro

2
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
www.amcbridge.com

RE: need a simple SW2009 print macro

(OP)
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?  

RE: need a simple SW2009 print macro

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
www.amcbridge.com

RE: need a simple SW2009 print macro

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 sad.

refer http://www.eng-tips.com/viewthread.cfm?qid=246216

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: need a simple SW2009 print macro

(OP)
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!



 

RE: need a simple SW2009 print macro

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

RE: need a simple SW2009 print macro

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.

RE: need a simple SW2009 print macro

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

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