SUB main()
Dim oDoc As Document = ThisDoc.Document
Dim oDef As Object = oDoc.ComponentDefinition
Dim oDcc As ComponentOccurrence = Nothing
On Error Resume Next
'부품과 어셈블리 모두 적용할수 있는 코드
Dim oBody As SurfaceBody
If TypeOf oDoc Is PartDocument Then
oDef = DirectCast(oDoc, PartDocument).ComponentDefinition
oBody = oDef.SurfaceBodies(1)
ElseIf TypeOf oDoc Is AssemblyDocument Then
oDef = DirectCast(oDoc, AssemblyDocument).ComponentDefinition
Dim oOcc As ComponentOccurrence = oDoc.ComponentDefinition.Occurrences.Item(1)
Dim oPartDef As PartComponentDefinition = oOcc.Definition
oBody = oPartDef.SurfaceBodies.Item(1)
Else
'MessageBox.Show("이 코드는 부품 또는 어셈블리 문서", "ilogic")
End If
Dim selectSet As SelectSet = ThisDoc.Document.SelectSet
Dim F1 As PartFeatures
F1 = oDoc.ComponentDefinition.Features
For i = 1 To F1.Count
If InStr(F1.Item(i).Name, "구멍") <> 0 or InStr(F1.Item(i).Name, "스레드") Then
Dim bb As String = F1.Item(i).ExtendedName
If InStr(bb, "M2.5") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Red"
ElseIf InStr(bb, "M3") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Orange"
ElseIf InStr(bb, "M4") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Yellow"
ElseIf InStr(bb, "M5") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Green"
ElseIf InStr(bb, "M6") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Blue"
ElseIf InStr(bb, "M8") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Pink"
ElseIf InStr(bb, "M10") <> 0 Then
Feature.Color(F1.Item(i).Name) = "Purple"
ElseIf InStr(bb, "M12") <> 0 Then
Feature.Color(F1.Item(i).Name) = "magenta"
ElseIf InStr(bb, "M16") <> 0 Then
Feature.Color(F1.Item(i).Name) = "violet"
ElseIf InStr(bb, "M20") <> 0 Then
Feature.Color(F1.Item(i).Name) = "gold"
Else
Feature.Color(F1.Item(i).Name) = "As Material"
End If
Else
End If
Next i
END SUB