Look into using FrameState if that helps to resize the SW window size.
Here are codes from API help files.
Option Explicit Dim swApp As SldWorks.SldWorks Sub main() Set swApp = Application.SldWorks ' Set the SOLIDWORKS window the specified height, width, state, and location swApp.FrameHeight = 500 swApp.FrameLeft = 100 swApp.FrameState = swWindowNormal swApp.FrameTop = 100 swApp.FrameWidth = 500 End Sub
That is definitely a step in the right direction but that resizes the Application window, not the Document window. I might be able to make it work but I think I will get a cleaner result if I control the Document window. I will dig into the FrameState stuff and see what I can figure out.
Check IModelWindow if see if you can use that to get/set size.
How do I insert a code block like this? I searched the forums assuming this question has been asked and answered before but apparently I used ineffective search terms.
Here is what I came up with. The macro hides the FeatureManager and the Heads-up View Toolbar. Then it sets the window location and size, then switches the window to normal mode, and finally zooms the image to fit. If I trigger my Save as PDF or Save as JPG macros at this point, I get a 450 x 300 image. Now all I need to do is merge the macros and add a couple lines to unhide the FeatureManger and Heads-up View Toolbar, and Maximize the model window again. This is going to help me and my ERP people tremendously.
Dim swApp As Object
Dim swDoc As ModelDoc2
Dim swDocExt As ModelDocExtension
Dim swDocView As ModelView
Dim PDFWidth As Integer
Dim PDFHeight As Integer
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swDocExt = swDoc.Extension
Set swDocView = swDoc.ActiveView
' Hide FeatureManager
' Hide Heads-up View Toolbar
swDocView.VisibilityViewTools = False
' Set Document Window Postion
swDocView.FrameTop = 100
swDocView.FrameLeft = 100
' Set Document Window Size
PDFWidth = 450
PDFHeight = 300
swDocView.FrameWidth = PDFWidth + 15 'Window frame subtracts 15 pixels from graphic width
swDocView.FrameHeight = PDFHeight + 53 'Window frame subtracts 53 pixels from graphic hight
' Set Document Window to Normal
swDocView.FrameState = swWindowNormal
' Zoom Model to Fit
Thanks for sharing, might come in handy some day.
I merged this macro with my SaveAs JPG macro and then converted it to a #Task script. Friday night, after I went home, my computer created thumbnails of all the parts in my design library and placed them in the folder my ERP system looks in for part images. What a major time saver.
For newly designed parts I would love to tag the macro onto the normal file save routine. Is that possible? With this, every part or assembly created or modified would automagically create and maintain its own thumbnail. Can I have a macro that is triggered by file save events?