Export PNG with transparent background via VBA

Export PNG with transparent background via VBA

jsmeker
Participant Participant
301 Views
2 Replies
Message 1 of 3

Export PNG with transparent background via VBA

jsmeker
Participant
Participant

Trying to export png with a transparent background via VBA and having some trouble .  If I export with the background, I get a nice image:

jsmeker_0-1731444009434.png

If I set ("TransparentBackground") = True, and leave everything else the same, I get the transparent background but the image is very pixelated.

jsmeker_1-1731444022778.png

Anybody have any idea why this would happen?  I'm running Inventor 2024.  Thanks for the help!

 

Relevant part of the export code:

'Get the active view.
Dim oView As view
Set oView = ThisApplication.ActiveView

'configure view for export
oView.DisplayMode = DisplayModeEnum.kWireframeNoHiddenEdges
oView.ShowGroundReflections = False
oView.ShowGroundShadows = False
oView.ShowAmbientShadows = False
oView.ShowObjectShadows = False

Dim camera As camera
Set camera = oView.camera

camera.Fit
camera.Apply

'Create a new NameValueMap Object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

oOptions.value("TransparentBackground") = True
    
Call oView.SaveAsBitmapWithOptions(pngFileName, 800, 0, oOptions)

 

 

0 Likes
302 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @jsmeker.  My best guess is that this extremely specific situation has to do with the current 'Visual Style' being used when capturing the Image, and how the 'transparent' functionality needs to work.  The Visual Style you are using in those images looks similar to 'Wireframe with Visible Edges Only'.  I am only guessing here, but my guess is that some of the 'lines/arcs' being used to represent the model in the visual style may have some of the same color in them that is being used in the 'background color'.  And when it tries to make the background transparent, it is looking for pixels with that color, and eliminating them.  And that is eliminating some pixels from within the lines/arcs representing the model edges.  You might try different backgrounds, such as pure white or different Visual Styles, or different 'Theme' color settings, in an attempt to eliminate the 'color bleed' situation.  Just some thoughts.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

jsmeker
Participant
Participant

I ended up changing the Inventor color scheme to a white background, which will work for me in this situation.  I used:

 

ThisApplication.ColorSchemes.Item("Presentation").Activate 'this color scheme contains a white background

 

0 Likes