Code:
Public Sub Object_Clean_arameters(ByVal WorkObject As INFITF.Document) '-------------------------------------------------------------------------------
' Cleans Parameters in Object
' creates missing Entries and deletes multi entries
'-------------------------------------------------------------------------------
Dim OProduct As ProductStructureTypeLib.Product
Dim oPart As ProductStructureTypeLib.Product
Dim oDrawing As DRAFTINGITF.DrawingDocument
Dim oParameters As KnowledgewareTypeLib.Parameters
Dim oParam As KnowledgewareTypeLib.Parameter
Dim oParamFullname As String
Dim oParamNodes() As String
Dim oParamName As String
Dim FoundParam(8) As Boolean
Dim i As Integer
Try
If InStr(WorkObject.Name, ".CATPart") Then
oPart = WorkObject.GetItem(1)
oParameters = oPart.UserRefProperties
ElseIf InStr(WorkObject.Name, ".CATProduct") Then
OProduct = WorkObject.Product
oParameters = OProduct.UserRefProperties
Else
oDrawing = WorkObject
oParameters = oDrawing.Parameters
End If
For i = 0 To 8
FoundParam(i) = False
Next
For Each OParam In oParameters
oParamFullname = OParam.Name
oParamNodes = oParamFullname.Split("\")
oParamName = oParamNodes(oParamNodes.Count - 1)
If InStr(oParamName, ".") > 1 Then
oParamName = Left(oParamName, InStr(oParamName, "."))
End If
If InStr(oParamName, ".") > 1 Then
oParamName = Left(oParamName, InStr(oParamName, ".") - 1)
End If
Select Case oParamName
Case "Param1"
If FoundParam(0) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(0) = True
End If
Case "Param2"
If FoundParam(1) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(1) = True
End If
Case "Param3"
If FoundParam(2) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(2) = True
End If
Case "Param4"
If FoundParam(3) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(3) = True
End If
Case "Param5"
If FoundParam(4) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(4) = True
End If
Case "Param6"
If FoundParam(5) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(5) = True
End If
Case "Param7"
If FoundParam(6) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(6) = True
End If
Case "Param8"
If FoundParam(7) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(7) = True
End If
Case "Param9"
If FoundParam(8) = True Then
oParameters.Remove(oParam.Name.ToString)
Else
FoundParam(8) = True
End If
End Select
Application.DoEvents()
Next
If FoundParam(0) = False Then
oParameters.CreateString("Param1", "")
End If
If FoundParam(1) = False Then
oParameters.CreateString("Param2", "")
End If
If FoundParam(2) = False Then
oParameters.CreateString("Param3", "")
End If
If FoundParam(3) = False Then
oParameters.CreateString("Param4", "")
End If
If FoundParam(4) = False Then
oParameters.CreateString("Param5", "")
End If
If FoundParam(5) = False Then
oParameters.CreateString("Param6", "")
End If
If FoundParam(6) = False Then
oParameters.CreateString("Param7", "")
End If
If FoundParam(7) = False Then
oParameters.CreateString("Param8", "")
End If
If FoundParam(8) = False Then
oParameters.CreateString("Param9", "")
End If
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical, "Error in Functions: Object_Parameters_Clean")
End Try
End Sub