Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Orphaned AttributeSet - Sketchline

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Tiffany_Hayden_
169 Views, 4 Replies

Orphaned AttributeSet - Sketchline

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__0-1721662126976.png

 

 

 

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.

EESignature

4 REPLIES 4
Message 2 of 5

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.

SketchLine.AttributeSets 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

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.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 5

@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

 

Message 5 of 5

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.

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report