Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic Appearance of all occurrences in an Assembly

fce
Enthusiast

iLogic Appearance of all occurrences in an Assembly

fce
Enthusiast
Enthusiast

Hello there,

I would like to open each occurrence in an already open top assembly and get each appearance as a string.
I'm aware that the command "iProperties.PartColor" allows you to get the Appearance, but it's not working running from the top assembly. I'm probably just missing a simple function. Bellow you can find the code:

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension

Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the referenced models

For Each oRefDoc In oRefDocs
    Dim oCurFile As Document
    oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
	
			oCurFileAppearance = iProperties.PartColor
			'oCurFileAppearance= oCurFile.Definition.Document.ActiveRenderStyle
			MessageBox.Show(oCurFileAppearance, "oCurFileAppearance")
			If oCurFileAppearance = "-"
			oCurFileAppearance ="-"
			End If
'			MessageBox.Show(oCurFileAppearance, "oCurFileAppearance")
oCurFile.Close		
			
Next




0 Likes
Reply
Accepted solutions (1)
1,923 Views
5 Replies
Replies (5)

JhoelForshav
Mentor
Mentor

@fce 

Just to make sure - Do you want the appearance of the document or the occurrence?, beacuase those are not always the same :slightly_smiling_face:

0 Likes

fce
Enthusiast
Enthusiast

Good question. I would like to get the appearance of each ipt. and .iam opened in the "For" cycle. 

oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
 

The appearance that shows on the top of Inventor WIndow.

0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

@fce 

Those are actually two different things (iam and ipt). For an iam, the appearance shown in that dropdown is the appearance set to the selected occurrence in that assembly. The appearance in the document can be something else. So an assembly document in itself can't have an active appearance, only the occurrences of that assembly.

Do I make any sense to you? :grinning_face_with_smiling_eyes:

 

This code however will give you the active appearance of all parts :slightly_smiling_face:

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAppearances As String = "Appearances:" & vbCrLf
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
	Dim oAppearance As String = DirectCast(oRefDoc, PartDocument).ActiveAppearance.DisplayName
	oAppearances = oAppearances & vbCrLf &  oRefDoc.DisplayName & "	" & oAppearance
End If			
Next
MessageBox.Show(oAppearances, "Appearance list")

fce
Enthusiast
Enthusiast

Nice, it worked perfectly. Thanks a lot!

0 Likes

_KarlH
Enthusiast
Enthusiast

Thanks for sharing that example. I'm attempting to modify the loop so that it can change all the colours within an Assembly at the Part level.

 

My initial attempt simply re-named the active Color within the Part but unfortunately didn't change the Colours appearance.

 

For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
		DirectCast(oRefDoc, PartDocument).ActiveAppearance.DisplayName = "Cyan"
	End If			
Next

 

 

Using the likes of Component.Color only creates an assembly appearance overide on the active view rep, which is why I can't use the below;

Component.Color("Example_Part:1") = "Red"

Would appreciate any help on having assembly level iLogic code change a parts Appearance at the part level.

0 Likes