Is there a way to find attributes that have been orphaned.
In my case the user can delete a sketchline and that sketchline has attributes attached to it but once the sketchline is deleted the attribute set changes to "Nothing" with the attribute still attached to the orphaned object. I've looked at the planar sketch and the part document. But I don't see an object that will help.
Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by JelteDeJong. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @Tiffany_Hayden_. If the attributes were within an AttributeSet, that was within the AttributeSets, that were attached to a SketchLine, then you deleted that SketchLine, then all the AttributeSets attached to it, as well as all the AttributeSet objects, and Attribute objects within those, would be deleted also. But just in case I am not understanding the situation clearly, you can use the Document.AttributeManager property to access the main AttributeManager object, then use its powerful methods to attempt to find the attributes you are looking for.
Wesley Crihfield
(Not an Autodesk Employee)
Maybe this can help you. This test rule will find the attribute sets that are not attached to an entity.
Dim doc As DrawingDocument = ThisDoc.Document
Dim attManager = doc.AttributeManager
Dim allsets As IEnumerable(Of AttributeSet) = doc.AttributeManager.FindAttributeSets().Cast(Of AttributeSet)
For Each attributeSet As AttributeSet In allsets
Dim foundEntities As ObjectCollection = attManager.FindObjects(attributeSet.Name)
If (foundEntities.Count = 0) Then
MsgBox("Found attribute set without entities")
End If
Next
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
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
Thanks! @Curtis_Waguespack @JelteDeJong @WCrihfield I think the missing piece for me was the Attrubute Manager. I have Nifty Attributes installed and that application could see it so I knew there had to be a way! Thanks so much for all your help!
Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Can't find what you're looking for? Ask the community or share your knowledge.