@Tiffany_Hayden_
I have often just used the PurgeAttributes method as part of creating attributes to clean up orphaned attributes as I go. This might or might not work for you depending upon how you're using the data.
example:
Sub Main
' Check to make sure a sketch is open.
If Not TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
MsgBox("A sketch must be active to use this tool.")
Exit Sub
End If
Dim oCompDef As ComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oSketch As Sketch
oSketch = ThisApplication.ActiveEditObject
Dim oObjCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSelectedLine As SketchEntity
Do
oSelectedLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Select a Sketch Line.")
oObjCol.Add(oSelectedLine)
Loop While oSelectedLine Is Nothing
For Each oObject As Object In oObjCol
If TypeName(oObject) = "SketchLine" Then
Dim oSketchEntity As SketchEntity = oObject
Call CreateAttrib(oSketchEntity, oSketch.Name & "_Atttributes", oSketch.Name & "_Test", "hello world")
End If
Next
End Sub
Public Sub CreateAttrib(oSketchEntity As SketchEntity, sAttribSetName As String, sAttribName As String, sValue As String)
Dim oAttrSet As AttributeSet
Dim oAttrib As Inventor.Attribute
ThisDoc.Document.AttributeManager.PurgeAttributeSets(sAttribSetName)
Try
oAttrSet = oSketchEntity.AttributeSets.Item(sAttribSetName)
Logger.Info("Attr Set Found")
Catch
oAttrSet = oSketchEntity.AttributeSets.Add(sAttribSetName)
Logger.Info("Attr Set Created")
End Try
Try
oAttrib = oAttrSet.Item(sAttribName)
Logger.Info("Attrib Found")
Catch
oAttrib = oAttrSet.Add(sAttribName, ValueTypeEnum.kStringType, sValue)
Logger.Info("Attrib Created")
End Try
oAttrib.Value = sValue
End Sub
