iLogic: Remove Appearance Overrides

This method is used to remove appearance overrides from all parts in an assembly, including ones in sub assemblies. Another method is listed here, but only covers parts in the assembly the rule is ran in, not parts in sub assemblies that may be contained in that assembly.

Sub RemoveAppearanceOverrides()
	Dim clearTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Clear Appearance Overrides")
	
	For Each comp As ManagedComponentOccurrence In Components
		' Skip suppressed components
		If comp.Occurrence.Suppressed Then
			Continue For
		End If
		
		' Skip iParts
		If comp.Occurrence.IsiPartMember Then
			Continue For
		End If
		
		' Restore the render style if the component is a part
		If comp.Occurrence.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			Dim compDef As ComponentDefinition = comp.Occurrence.Definition
			Dim partDoc As PartDocument = compDef.Document
			partDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance
		End If
		
		' Recurse if the component is an assembly
		If comp.Occurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			RecurseChildren(comp.Occurrence.SubOccurrences)
		End If
	Next
	
	clearTrans.End()
End Sub 'RemoveAppearanceOverrides

Sub RecurseChildren(comps As ComponentOccurrencesEnumerator)
	For Each comp As ComponentOccurrence In comps
		' Skip the suppressed components
		If comp.Suppressed Then
			Continue For
		End If
		
		' Skip iParts
		If comp.IsiPartMember Then
			Continue For
		End If
		
		' Restore the render style if the component is a part
		If comp.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			Dim compDef As ComponentDefinition = comp.Definition
			Dim partDoc As PartDocument = compDef.Document
			partDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance
		End If
		
		' Recurse if the component is an assembly
		If comp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			RecurseChildren(comp.SubOccurrences)
		End If
	Next
End Sub 'RecurseChildren

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: