Clear appearence override on selected parts

Clear appearence override on selected parts

Anonymous
Not applicable
3,166 Views
12 Replies
Message 1 of 13

Clear appearence override on selected parts

Anonymous
Not applicable

I found this code, but have no experience modifying it. Can you help me to change the code, so it only clears the override on selected parts, and not on all parts in the active assembly?

 

Many ythanks!

 

 

  Dim Title As String = "Excitech iLogic"

        ' Attempt to get the active assembly document
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule must be run from an assembly", Title)
            Exit Sub
        End Try

        Dim oADoc As AssemblyDocument = Nothing
        Dim oPDoc As PartDocument = Nothing
        Dim TotCount As Integer = oDoc.AllReferencedDocuments.Count

        Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
        Dim oRefDoc As Document = Nothing
        Dim oPartDef As PartComponentDefinition = Nothing
        Dim oAsmDef As AssemblyComponentDefinition = Nothing
        Dim FailCount As Integer = 0

        Dim Count As Integer = 1

        ' Top level clear override command
        oDef.ClearAppearanceOverrides()

        ' Loop through all the documents referenced by this assembly document...
        For Each oRefDoc In oDoc.AllReferencedDocuments
            Try
                ThisApplication.StatusBarText = Count & " of " & TotCount & " components processed."

                ' Is it a part document?
                If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                    ' Get the component definition.
                    oPartDef = oRefDoc.ComponentDefinition

                    ' First set the top level part appearance to be the same as the material 
                    oRefDoc.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance

                    ' Try a top level 'clear appearance overrides' command first
                    oPartDef.ClearAppearanceOverrides()

                    ' Clear the override on all the override objects found....
                    oPartDef.ClearAppearanceOverrides(ObjColl)

                    ThisApplication.ActiveView.Update()

                    ' Is it an assembly document?
                ElseIf oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                    ' Get the assembly definition
                    oAsmDef = oRefDoc.ComponentDefinition
                    ' Run top level 'clear appearances' command on this assembly
                    ThisApplication.StatusBarText = Count & " of " & TotCount & " components processed. Clearing assembly overrides..."
                    oAsmDef.ClearAppearanceOverrides()
                End If
                Count += 1
            Catch
                FailCount += 1
            End Try
        Next

        ThisApplication.ActiveView.Update()

        If FailCount > 0 Then
            MsgBox("All Appearance overrides removed." & vbLf & vbLf & _
        "Operation failed on " & FailCount & " component(s) - these may be read-only.", , Title)
        Else
            MsgBox("All Appearance overrides removed.", , Title)
        End If


 

Accepted solutions (2)
3,167 Views
12 Replies
Replies (12)
Message 2 of 13

HermJan.Otterman
Advisor
Advisor

 

Hello jdg,

 

Try first to select your parts than run this:

 

Dim Title As String = "Excitech iLogic"

        ' Attempt to get the active assembly document
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule must be run from an assembly", Title)
            Exit Sub
        End Try

        Dim oADoc As AssemblyDocument = Nothing
        Dim oPDoc As PartDocument = Nothing

        Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
        Dim oRefDoc As Document = Nothing
        Dim oObj As Object = Nothing

        Dim SelectedOccurences As ObjectCollection
        SelectedOccurences = ThisApplication.TransientObjects.CreateObjectCollection

        For Each oObj In oDoc.SelectSet
            Try


                If oObj.Definition.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or
                    oObj.Definition.Document.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

                    SelectedOccurences.Add(oObj)
                End If

            Catch ex As Exception

            End Try
        Next

        oDef.ClearAppearanceOverrides(SelectedOccurences)

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 13

Anonymous
Not applicable

Many Thanks! That is indeed my preferred workflow: Select the parts, than run the rule, but this one doesn't change anything. Does it on your side?

0 Likes
Message 4 of 13

HermJan.Otterman
Advisor
Advisor

Hi, Yes for me it does change things.

I made a screencast where you can see that it will change.

the designview is what is being changed! so if you have a sub assy an you open it, it can look defferent than when you look at it from the main assembly... so this is why you sometime don't see changes...

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 5 of 13

HermJan.Otterman
Advisor
Advisor

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 6 of 13

Anonymous
Not applicable

Appreciate your help. Here is mine

https://autode.sk/2JTh05S

0 Likes
Message 7 of 13

HermJan.Otterman
Advisor
Advisor

Hello Johan,

 

Can you share your Assembly, shown in the screen cast, then I will look in to that.

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 8 of 13

Anonymous
Not applicable

zipped pack and go

0 Likes
Message 9 of 13

HermJan.Otterman
Advisor
Advisor

dear Johan,

 

I added and altered some of the code I deleted,

on you assembly this now works.

maybe test it with sub assies...

 

the code:

 

Dim Title As String = "Excitech iLogic"

        ' Attempt to get the active assembly document
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule must be run from an assembly", Title)
            Exit Sub
        End Try

        Dim oADoc As AssemblyDocument = Nothing
        Dim oPDoc As PartDocument = Nothing
        Dim TotCount As Integer = oDoc.AllReferencedDocuments.Count

        Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
        Dim oRefDoc As Document = Nothing
        Dim oObj As Object = Nothing

        Dim oPartDef As PartComponentDefinition
        Dim oAsmDef As AssemblyComponentDefinition
        Dim FailCount As Integer = 0

        Dim Count As Integer = 1

        Dim SelectedOccurences As ObjectCollection
        SelectedOccurences = ThisApplication.TransientObjects.CreateObjectCollection

        For Each oObj In oDoc.SelectSet
            Try


                If oObj.Definition.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or
                    oObj.Definition.Document.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

                    SelectedOccurences.Add(oObj)
                End If

            Catch ex As Exception

            End Try
        Next

        oDef.ClearAppearanceOverrides(SelectedOccurences)

        'Loop through all the documents referenced by this assembly document...
        For Each oObj In SelectedOccurences
            Try

                           If oObj.Definition.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or
                    oObj.Definition.Document.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

                    'ThisApplication
                    ThisApplication.StatusBarText = Count & " of " & TotCount & " components processed."

                    ' Is it a part document?
                    If oObj.Definition.Document.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

                        ' First set the top level part appearance to be the same as the material
                        oObj.Definition.Document.AppearanceSourceType = AppearanceSourceTypeEnum.kMaterialAppearance

                        ' Try a top level 'clear appearance overrides' command first
                        oObj.Definition.ClearAppearanceOverrides()

                        '' Clear the override on all the override objects found....
                        'oObj.Definition.ClearAppearanceOverrides(oObj)
                        'ThisApplication
                        ThisApplication.ActiveView.Update()

                        ' Is it an assembly document?
                    ElseIf oObj.Definition.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                        ' Get the assembly definition
                        oAsmDef = oObj.Definition
                        ' Run top level 'clear appearances' command on this assembly
                        'ThisApplication
                        ThisApplication.StatusBarText = Count & " of " & TotCount & " components processed. Clearing assembly overrides..."
                        'oAsmDef.ClearAppearanceOverrides(oObj)
                    End If
                    Count += 1
                End If
            Catch
                FailCount += 1
            End Try
        Next

        'ThisApplication
        ThisApplication.ActiveView.Update()

        If FailCount > 0 Then
            MsgBox("All Appearance overrides removed." & vbLf & vbLf &
        "Operation failed on " & FailCount & " component(s) - these may be read-only.", , Title)
        Else
            MsgBox("All Appearance overrides removed.", , Title)
        End If
    End Sub

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 10 of 13

Anonymous
Not applicable

Thank you, but if i try to save the rule I get error

Error on Line 98 : End Sub moet worden voorafgegaan door een overeenkomende Sub-instructie.

0 Likes
Message 11 of 13

HermJan.Otterman
Advisor
Advisor
Accepted solution

delete the last line: "end sub"

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 12 of 13

Anonymous
Not applicable

Thank you very much! Works like a charm.

Was my assembly that other than yours that it didn(t work in the 1st place?

0 Likes
Message 13 of 13

HermJan.Otterman
Advisor
Advisor
Accepted solution

yours had overides in the parts, I tested with overrides in the assembly..

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan