Batch Export Images with transparent background

patioroofriser
Explorer

Batch Export Images with transparent background

patioroofriser
Explorer
Explorer

Hello! I am currently using an iLogic rule I found from some years back on this forum to batch export a large group of images. It would be ideal if these images could already have a transparent background when I export them, so I don't have to run another photoshop script to accomplish this. I know that some compression formats of .bmp support an alpha channel, but I'm not sure what all can be accomplished in Inventor, or if there's a rule to export as PNG which would make it much easier potentially. Any feedback would be greatly appreciated!

Imports System.Windows.Forms
Imports System.IO

Sub Main
sResultPathImage = SelFolder(ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath) 'oDefaultPathImage)
sResultPathBatch = SelFolder(ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath) 'oDefaultPathBatch)

'Dim oHolderList As String
If sResultPathBatch <> "" Then
    Dim oFiles = Directory.GetFiles(sResultPathBatch, "*.IAM")
    For Each FileName As String In oFiles
        On Error Resume Next
        oDoc = ThisApplication.Documents.Open(FileName, True)
        Dim sPartNumber As String = oDoc.PropertySets("Design Tracking Properties")("Part Number").Value
        oCamera = InventorVb.Application.ActiveView.Camera
        oCamera.Fit
        oCamera.Apply
        oCamera.SaveAsBitmap(sResultPathImage & "\" & sPartNumber & ".bmp",2800,2000)
        oDoc.Close()
        oHolderList = oHolderList & sPartNumber & vbLf
    Next
End If
MessageBox.Show(oHolderList)
End Sub


Private Function SelFolder(sPath As String) As String
On Error Resume Next
    If sPath = "" Then sPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
    Dim FBrowserDialog As New FolderBrowserDialog
    FBrowserDialog.SelectedPath = sPath
    Dim result As DialogResult = FBrowserDialog.ShowDialog()
    SelFolder = ""
    If ( result = DialogResult.OK ) Then 'And ( FBrowserDialog.SelectedPath <> sPath ) Then
        SelFolder = FBrowserDialog.SelectedPath
    End If
End Function
0 Likes
Reply
758 Views
4 Replies
Replies (4)

dalton98
Collaborator
Collaborator

Edit: this doesn't work woops 

There's a transparency option when creating a color:

Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(255, 255, 255, 0)
'---
'-------
'----------
Dim oCamera As Camera
oCamera.SaveAsBitmap(sResultPathImage & "\" & sPartNumber & ".png", 2800, 2800, oColor)

 

0 Likes

patioroofriser
Explorer
Explorer

This won't export with a transparent background though because it's a 24x bitmap. only 32x bitmaps have a transparency layer.

0 Likes

JelteDeJong
Mentor
Mentor

If you use the function:

Camera.CreateImageWithOptions( Width As Long, Height As Long, Options As NameValueMap ) As IPictureD...

then there is an option according to the help files.

 

But this will not give you a picture file but just an IPictureDisp object. You can convert those objects to Bitmap objects check this post:

https://adndevblog.typepad.com/manufacturing/2012/06/how-to-convert-iconbitmap-to-ipicturedisp-witho...

 

Maybe then it's possible to save the picture to a file. But I'm afraid this will be too much for an iLogic rule. I would suggest that you create an addin for this. You can find a tutorial for this on my blog.

http://www.hjalte.nl/60-creating-an-inventor-addin

And in the follow-up post a converter Bitmap <-> IPictureDisp is used for creating buttons.

http://www.hjalte.nl/61-adding-icons-to-your-buttons

 

Maybe it will help you but I guess it won't be easy and in the end I'm not sure it will work.

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes

Tony_Yates
Advocate
Advocate

This might be helpful to you:-

 

'Get the active view.
    Dim oView = ThisApplication.ActiveView
'Create a new NameValueMap Object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap '.TransientObjects.CreateNameValueMap
    oOptions.Value("TransparentBackground") = True

'save screenshot 
    Call oView.SaveAsBitmapWithOptions(CurrentFile, 0, 0, oOptions)
0 Likes