@orhan.alihanov,
I've seen a few people asking about this recently. I've looked into the Thumbnail extraction a little, but have not gotten the conversion of IPictureDisp to an actual image working in VB.net iLogic. The camera method is likely not the best for large assemblies because each file needs to be open and visible in the graphics window for the camera to work.
With that in mind, this is a rule that uses the camera method:
Sub Main
'Setup
Dim SaveName As String
Dim NewPath As String
Dim ThisFile As String
Dim PictureFileType As String = ".jpg"
Dim pDoc As PartDocument = TryCast(InventorVb.Application.ActiveDocument, PartDocument)
If Not IsNothing(pDoc)
'Set Path
NewPath = System.IO.Path.GetDirectoryName(pDoc.FullFileName) & "\"
ThisFile = System.IO.Path.GetFileNameWithoutExtension(pDoc.FullDocumentName)
SaveName = NewPath & ThisFile & PictureFileType
'Call Capture Sub
CaptureImage(SaveName)
Else 'it is not a part document
Dim aDoc As AssemblyDocument = TryCast(InventorVb.Application.ActiveDocument, AssemblyDocument)
If IsNothing(aDoc) Then Exit Sub
'Set Path
NewPath = System.IO.Path.GetDirectoryName(aDoc.FullFileName) & "\"
ThisFile = System.IO.Path.GetFileNameWithoutExtension(aDoc.FullDocumentName)
SaveName = NewPath & ThisFile & PictureFileType
'Call Capture Sub for assembly
CaptureImage(SaveName)
'Cycle Through all referenced documents
For Each refDoc As Document In aDoc.ReferencedDocuments
'make sure referenced document exists as a component in the assembly
If aDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(refDoc).Count < 1 Then Continue For
'Activate Referenced Document
Dim alreadyopen As Boolean = IsVisibleOpen(refDoc, InventorVb.Application.Documents.VisibleDocuments)
If Not alreadyopen
InventorVb.Application.Documents.Open(refDoc.FullDocumentName, True)
Else
refDoc.Activate()
End If
'Set FileName
ThisFile = System.IO.Path.GetFileNameWithoutExtension(refDoc.FullDocumentName)
SaveName = NewPath & ThisFile & PictureFileType
'Call Capture Sub
CaptureImage(SaveName)
'Return to assembly document [Also, close opened document if This rule opened it]
If Not alreadyopen
refDoc.Close(True)'Skip Save
Else
aDoc.Activate()
End If
Next
End If
End Sub
Sub CaptureImage(SaveName As String)
'Save pic
oCamera = InventorVb.Application.ActiveView.Camera
oCamera.Fit
oCamera.Apply
oCamera.SaveAsBitmap(SaveName, 300, 300)
End Sub
Function IsVisibleOpen(oDoc As Document, DocumentCollection As Object) As Boolean
For Each Item In DocumentCollection
If Item Is oDoc Then Return True
Next
Return False
End Function