Hi guys. I am going to post this one here too, because the code process you posted often creates a 'squished' looking image for me. Code like what I am posting below has been posted here on the forums before, and did not entirely originate from me. I just customized a few things. This process seems to create a much better looking BMP file, that looks more closely like the preview image of the document that I see within the Windows file explorer screen when set to 'Extra Large Icons' view setting. And as you can see within the code, you can change the size of the output image, if needed, but I primarily just needed small images, similar to what we see in the file system previews.
AddReference "System.Drawing"
AddReference "stdole"
AddReference "System.Windows.Forms"
Class ThisRule
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
ConvertDocThumbnailToBMP(oDoc)
End Sub
Sub ConvertDocThumbnailToBMP(oDoc As Inventor.Document, Optional sBMPfile As String = vbNullString)
If oDoc Is Nothing Then Return
If String.IsNullOrEmpty(sBMPfile) Then
'same path and file name, but with .bmp file extension
sBMPfile = System.IO.Path.ChangeExtension(oDoc.FullFileName, ".bmp")
End If
Break
Dim oThumb As stdole.IPictureDisp
Do
oThumb = oDoc.Thumbnail
Loop While oThumb.Handle < 0
Dim oAHConverter As New AxHostConverter
Dim oImage As System.Drawing.Image = oAHConverter.GetImageFromIPictureDisp(oThumb)
'this call must be created, but is never used
Dim myCallback As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
'create a thumbnail before save - seems to generate a better quality
oImage.GetThumbnailImage(180, 180, myCallback, IntPtr.Zero).Save(sBMPfile, System.Drawing.Imaging.ImageFormat.Bmp)
End Sub
Public Function ThumbnailCallback() As Boolean
Return False
End Function
End Class
Class AxHostConverter
Inherits System.Windows.Forms.AxHost
Public Sub New()
'MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
MyBase.New((New Guid).ToString)
End Sub
Public Function GetImageFromIPictureDisp(ByVal IPDisp As stdole.IPictureDisp) As System.Drawing.Image
Return MyBase.GetPictureFromIPicture(IPDisp)
End Function
End Class
That special 'Class' could be saved out into its own external iLogic rule, then turn its 'Straight VB Code' option on, then you could use it by referencing it in the rule using the AddVBFile line within the 'Header' of the rule, instead of directly including the whole Class block of code within the rule.
And of course, there are also several built-in Inventor API methods for saving images of the active view out to the file system with various settings, but that may require visibly opening each document, and possibly reorienting the view and zoom level (by code) before capturing the image, and that may take a longer time to process.
Wesley Crihfield

(Not an Autodesk Employee)