Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get parts image

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
orhan.alihanov
846 Views, 6 Replies

Get parts image

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


	

 

6 REPLIES 6
Message 2 of 7
A.Acheson
in reply to: orhan.alihanov

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
Message 3 of 7
orhan.alihanov
in reply to: A.Acheson

Thanks for reply! But how is this supposed to help me? I can't call iProperty with thumbnail
Message 4 of 7
J-Camper
in reply to: orhan.alihanov

@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

 

 

Message 5 of 7
orhan.alihanov
in reply to: J-Camper

Thank you very much! You helped me a lot!
Message 6 of 7
2020mme013
in reply to: J-Camper

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.

Message 7 of 7
2020mme013
in reply to: 2020mme013

Just like attached screenshot.

 

2020mme013_0-1731586242053.png

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report