Search code examples
vbaimageexportautodeskautodesk-inventor

How can I export a picture with white background in Inventor VBA?


My set-up on my desktop pc is all... dark. Not that I'm a goth or something but it is pleasing for the eyes. However, whenever I save a picture in Inventor I have to change the background setting to white. Then change it back to dark-mode after I finished the image export.

I once had a VBA-code to easily save a picture while backdrop is set to white. All with one button. Can someone help me? I know the code isn't that difficult.

The code should work as follows:

  • As user, set the desired angle and distance in the main viewer.
  • Push a button and a VBA script runs in the background.
  • A export image saved on desktop with a predefined name. But the background is set to white.

Thank you!

Searched for VBA-codes online. Searched in my own folders for the code I once used.


Solution

  • Easily you can export active view with transparent or explicitly white background without modifying application settings

    Sub ExportActiveView()
        Dim v As View
        Set v = ThisApplication.ActiveView
        
        Dim width, height As Integer
        width = 300
        height = 300
        
        'Export with transparent background
        Dim options As NameValueMap
        Set options = ThisApplication.TransientObjects.CreateNameValueMap
        options.value("TransparentBackground") = True
        Call v.SaveAsBitmapWithOptions("C:\Temp\img.png", width, height, options)
        
        'Export with white bacground
        Dim white As Color
        Set white = ThisApplication.TransientObjects.CreateColor(255, 255, 255)
        Call v.Camera.SaveAsBitmap("C:\Temp\img.jpg", width, height, white)
    End Sub