Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Get parts image

orhan.alihanov
Participant

Get parts image

orhan.alihanov
Participant
Participant

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


	

 

0 Likes
Reply
Accepted solutions (1)
910 Views
6 Replies
Replies (6)

A.Acheson
Mentor
Mentor

Here is an article that explains how to do this for one document. The thumbnail is kept as an iproperty. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

orhan.alihanov
Participant
Participant
Thanks for reply! But how is this supposed to help me? I can't call iProperty with thumbnail
0 Likes

J-Camper
Advisor
Advisor
Accepted solution

@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

 

 

orhan.alihanov
Participant
Participant
Thank you very much! You helped me a lot!
0 Likes

2020mme013
Enthusiast
Enthusiast

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.

0 Likes

2020mme013
Enthusiast
Enthusiast

Just like attached screenshot.

 

2020mme013_0-1731586242053.png

 

0 Likes