forked from mspace912/iLogic-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteAppearances_and_OLE.ILOGICVB
More file actions
123 lines (108 loc) · 3.52 KB
/
DeleteAppearances_and_OLE.ILOGICVB
File metadata and controls
123 lines (108 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Sub Main()
Dim TotalAppearancesDeleted As Integer = 0
'Delete appearances in current document
Try
Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
DeleteOLEs(oDoc)
Dim appearance As Inventor.Asset
For Each appearance In oDoc.AppearanceAssets
Try
appearance.Delete
TotalAppearancesDeleted = TotalAppearancesDeleted + 1
Catch ex As Exception
End Try
Next
Catch
Try
Dim oDoc2 As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim appearance As Inventor.Asset
For Each appearance In oDoc2.AppearanceAssets
Try
appearance.Delete
TotalAppearancesDeleted = TotalAppearancesDeleted + 1
Catch
End Try
Next
Catch
End Try
End Try
' Get all occurrences from component definition for Assembly document
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc In oCompDef.Occurrences
Try
' Check if it's child occurrence (leaf node)
If oCompOcc.SubOccurrences.Count = 0 Then
'Not an assembly - try to delete its appearances
Dim CompDoc As Inventor.Document = oCompOcc.Definition.Document
DeleteOLEs(CompDoc)
For Each appearance In CompDoc.AppearanceAssets
Try
appearance.Delete
Catch
End Try
Next
Else
'It's an assembly, process its components
TotalAppearancesDeleted = TotalAppearancesDeleted + processAllSubOcc(oCompOcc)
End If
Catch
End Try
Next
MessageBox.Show("Deleted a total of : " & TotalAppearancesDeleted.ToString() & " appearances.")
End Sub
' This function is called for processing sub assembly. It is called recursively
' to iterate through the entire assembly tree.
Private Function processAllSubOcc(ByVal oCompOcc As ComponentOccurrence) As Integer
Dim ReturnDeletes As Integer = 0
Dim SubAssyDoc As Inventor.Document = oCompOcc.Definition.Document
DeleteOLEs(SubAssyDoc)
For Each appearance In SubAssyDoc.AppearanceAssets
'Delete the appearances from the currently processing sub assembly
Try
appearance.Delete
ReturnDeletes = ReturnDeletes + 1
Catch
End Try
Next
Dim oSubCompOcc As ComponentOccurrence
For Each oSubCompOcc In oCompOcc.SubOccurrences
Try
' Check if it's child occurrence (leaf node)
If oSubCompOcc.SubOccurrences.Count = 0 Then
'It's a part, delete its appearances
Dim CompDoc As Inventor.Document = oSubCompOcc.Definition.Document
DeleteOLEs(CompDoc)
For Each appearance In CompDoc.AppearanceAssets
Try
appearance.Delete
ReturnDeletes = ReturnDeletes + 1
Catch
End Try
Next
Else
'It's an assembly, process occurrences
ReturnDeletes = ReturnDeletes + processAllSubOcc(oSubCompOcc)
End If
Catch
End Try
Next
Return ReturnDeletes
End Function
Function DeleteOLEs(parentDoc As Object) As Integer
Dim NumDeleted As Integer = 0
Try
Dim oEachOLEDesc As Inventor.ReferencedOLEFileDescriptor
For Each oEachOLEDesc In parentDoc.ReferencedOLEFileDescriptors
'If oEachOLEDesc.ReferenceStatus = Inventor.ReferenceStatusEnum.kMissingReference Then
oEachOLEDesc.Delete
NumDeleted = NumDeleted + 1
MessageBox.Show("Deleted an OLE")
parentDoc.Dirty = True
'End If
Next
Catch
End Try
Return NumDeleted
End Function