Remove All Appearances with iLogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I frequently have to import .stp models that import as a large assembly with many sub-assemblies and each sub-assembly has many parts. I need to recolor these models to have acceptable appearances, but based on the software that the supplier of the .stp file uses, the parts and faces already have incorrect appearances applied.
I want to use iLogic to loop through all sub-assemblies and strip all appearances from all parts so that the parts have no appearances applied and are just set to the default appearance.
Can someone help me with this iLogic. I have tried using ChatGPT to generate the code, but it has yet to work. As a jumping off point, here is what ChatGPT has helped me generate so far:
Sub Main()
' Get the active document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
' Check if the active document is an assembly
If oDoc.DocumentType = kAssemblyDocumentObject Then
Dim oAsmDoc As AssemblyDocument
oAsmDoc = oDoc
' Loop through all occurrences in the assembly
For Each oOccurrence As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences
RemoveAppearanceFromOccurrence(oOccurrence)
Next
MessageBox.Show("All appearances in the assembly have been reset to material appearance.")
ElseIf oDoc.DocumentType = kPartDocumentObject Then
' If the active document is a part, set its appearance to material appearance
Dim oPartDoc As PartDocument
oPartDoc = oDoc
oPartDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance
MessageBox.Show("The appearance of the part has been reset to material appearance.")
Else
MessageBox.Show("The active document is neither an assembly nor a part document.")
End If
End Sub
' Function to remove appearances from a component occurrence
Sub RemoveAppearanceFromOccurrence(oOccurrence As ComponentOccurrence)
Try
' Set the appearance source type to material appearance
oOccurrence.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance
' If this occurrence is an assembly, apply to all sub-occurrences
If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
Dim oSubAsmDoc As AssemblyDocument
oSubAsmDoc = oOccurrence.Definition.Document
For Each oSubOccurrence As ComponentOccurrence In oSubAsmDoc.ComponentDefinition.Occurrences
RemoveAppearanceFromOccurrence(oSubOccurrence)
Next
End If
Catch ex As Exception
' Handle any errors that might occur
MessageBox.Show("Error occurred while processing occurrence: " & oOccurrence.Name & vbCrLf & ex.Message)
End Try
End Sub
Any help you can provide with this is greatly appreciated. I have searched the forums and Google and tried all code snippets that I have found, but none work as I would like.
I just want to remove all appearance overrides for every component in the assembly.
Thank you!