Capture active window

Capture active window

Anonymous
Not applicable
699 Views
4 Replies
Message 1 of 5

Capture active window

Anonymous
Not applicable

Hello guys,

I`m looking for the code which will capture the active window similar to iProperties-->Save--> Capture

 

Any help appreciated,

Thank you,

Alex.

0 Likes
Accepted solutions (1)
700 Views
4 Replies
Replies (4)
Message 2 of 5

ekinsb
Alumni
Alumni

To capture the current window you can use the following VBA code.

 

Public Sub SaveCurrentWindow()
    Dim window As View
    Set window = ThisApplication.ActiveView
    
    Call window.SaveAsBitmap("C:\Temp\IVWindow.png", 0, 0)
End Sub

 The type of image file created depends on the file extension of the filename provided.  The last two arguments are the width and height of the image in pixels.  In this example I used zero for both wich indicates it should use the current window size for both the height and width.  I can also do something like this (filename, 0, 3000).  This indicates that the width of the image will be 3000 pixels and the height will be whatever is required to maintain the same aspect ratio as the window your using to create the image.  If you specifiy full values, for example (filename, 2000, 3000) then you'll get an image that specific size.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 5

Anonymous
Not applicable

Brian, thank you.

 

I want something a little different. Basically I`m talking about the preview picture. I`d like this captured image stay with the part, so next time I open it I see what it is.

I can go to iProperties--> Save --> Active Window--> Capture to do this, but I want this to be done automatically.

 

 

Is this possible?

 

 

Thank you.Untitled.png

0 Likes
Message 4 of 5

ekinsb
Alumni
Alumni
Accepted solution

Here's a slight variation of the previous program that will do what you want.

 

Public Sub SaveCurrentWindowAsThumbnail()
    Dim window As View
    Set window = ThisApplication.ActiveView
    
    Dim filename As String
    filename = "C:\Temp\IVWindow.png"
    Call window.SaveAsBitmap(filename, 250, 250)
    
    Dim doc As Document
    Set doc = ThisApplication.ActiveDocument
    
    Call doc.SetThumbnailSaveOption(kImportFromFile, filename)
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 5

Anonymous
Not applicable

Thanks a lot!

0 Likes