color

color

dhanshri_gavas
Contributor Contributor
200 Views
1 Reply
Message 1 of 2

color

dhanshri_gavas
Contributor
Contributor

Hi Team,
In Inventor, how do I get the color of each occurrence using the API?  in the part and assembly document?  
Thanks in advance!

0 Likes
201 Views
1 Reply
Reply (1)
Message 2 of 2

Andrii_Humeniuk
Advisor
Advisor

Hi @dhanshri_gavas . To get the color of the part, you need to use the ActiveAppearance method. This method will give you the active Asset. An example of getting an Asset in assemblies and details is below:

 

Public Sub Main()
	Dim oDoc As Document = ThisDoc.Document
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oADoc As AssemblyDocument = oDoc
		Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
		For Each oRefDoc As PartDocument In oADoc.AllReferencedDocuments.OfType(Of PartDocument)
			If oOccs.AllLeafOccurrences(oRefDoc.ComponentDefinition).Count = 0 Then Continue For
			Call GetColorDoc(oRefDoc)
		Next
	Else If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = oDoc
		Call GetColorDoc(oPDoc)
	End If
End Sub

Private Function GetColorDoc(ByVal oPDoc As PartDocument)
	Dim oAsset As Asset = oPDoc.ActiveAppearance
	Logger.Info("Part - " & oPDoc.DisplayName)
	Logger.Info("Color - " & oAsset.DisplayName & vbLf)
End Function

 

This code gets the Asset in line 17 and then shows the color information in the iLogic Log.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes