Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Hey there!
I want to get image (screenshot) of each parts in assembly, and save all of these with definity name. I wrote the code to enumeration of all components in the assembly (with several levels). Can iLogic refer to the component (for example with name "PartA:1") , set parameter ActiveView.Camera and get image? Or may be refer to part with name "PartA.ipt"...
The code with enumeration of all components is shown below.
Sub Main()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub
Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer)
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccurrences
Name= oOcc.Name
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAsm(oOcc.SubOccurrences, Level + 1)
End If
Next
GoExcel.Save
End Sub
Solved! Go to Solution.
Solved by J-Camper. Go to Solution.
Here is an article that explains how to do this for one document. The thumbnail is kept as an iproperty.
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
Hi Can we get 2D images of assembly part without changing the scale of the assembly and part. I want this to show the exploded view assembly image with balloon and part no.
Can't find what you're looking for? Ask the community or share your knowledge.