Delete Parts in an assembly with zero surfacebodies

Delete Parts in an assembly with zero surfacebodies

PACDrafting
Collaborator Collaborator
302 Views
1 Reply
Message 1 of 2

Delete Parts in an assembly with zero surfacebodies

PACDrafting
Collaborator
Collaborator

How do I write code to delete any parts/part occurence within an assembly that is without a surface body?

 

I've been trying to cycle through the assembly but it is deleting all sub assemblies to.

 

Thanks

 

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

PACDrafting
Collaborator
Collaborator

Does this look correct?

 

Public Sub RemoveEmptyParts()

Dim oassy As AssemblyDocument
Set oassy = ThisApplication.ActiveDocument

Dim compdef As ComponentDefinition
Set compdef = oassy.ComponentDefinition

Dim occur As ComponentOccurrence

    For Each occur In compdef.Occurrences
   
    If occur.SurfaceBodies.Count = 0 And occur.DefinitionDocumentType = kPartDocumentObject Then
   
    occur.Delete
   
    End If
  
    Next
   

End Sub

0 Likes