Orphan Attributes - Bug or By Design

nnikbin
Collaborator
Collaborator

Orphan Attributes - Bug or By Design

nnikbin
Collaborator
Collaborator

When an AttributeSet and an Attribute are added to an entity, such as a SurfaceBody, and the entity is subsequently deleted, the AttributeSet and Attribute remain in the document. Even after saving and loading the document, the attribute is still present.

 

The following is a sample code in C#, along with a result after adding the attribute to the "body" (left image) and then deleting the feature that created the body (and hence deleting the body - right image). I used the Nifty Attributes add-in developed by @BrianEkins (thank you, Brian!) to view the attributes.

 

 

AttributeSet attributeSet = body.AttributeSets.Add("TestSet");
attributeSet.Add("TestAttribute", ValueTypeEnum.kStringType, "Test Attribute");

 

 

63.png

Is it a bug or by design?

0 Likes
Reply
Accepted solutions (1)
508 Views
6 Replies
Replies (6)

nnikbin
Collaborator
Collaborator

I found that there is a Purge Orphaned Attributes button in Nifty Attributes add-in.

0 Likes

Michael.Navara
Advisor
Advisor

This is only my opinion based on my experience.

 

I don't know how it is internally implemented, but according to my experience it looks like a separate "database layer" (later attDatabase) in Inventor document. When you create an AttributeSet/Attribute, you create entry to this attDatabase with some reference to the native object (perhaps referenceKeys are used). When you delete the native object, attDatabase entry still persists, but lost the reference (reference is not valid, can't be associated with object). When you call "Purge Orphaned Attributes", all attributes without valid reference are removed from this attDatabase.

 

Summary: It works as designed

BrianEkins
Mentor
Mentor
Accepted solution

This is as designed. The reason is that some entities can come back at some point in the future. For example, you can add an attribute to an edge and then add a fillet to that edge. The edge no longer exists, and the attribute becomes detached. However, you can delete or suppress the fillet, and the edge will return. That original attribute will be attached to the edge. Not all entity types can come back, especially after saving or clearing the undo stack, but the API is very conservative and never deletes an attribute. There is a purge method that will delete all attributes that are currently detached. That's what the button in Nifty Attributes uses. It's a developer's choice if an when to delete an attribute.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

nnikbin
Collaborator
Collaborator

Thank you @Michael.Navara for your answer and thank you, @BrianEkins, for describing what the main reasons for the existence of orphan attributes are and your detailed explanation of the technical aspects involved.

0 Likes

nnikbin
Collaborator
Collaborator

@BrianEkins , I initially installed Attribute Helper from the SDK and later installed Nifty Attributes. However, since you developed both and changed Attribute Helper to Nifty Attributes, they both have the same ClassId. As a result, Nifty Attributes only appeared after I uninstalled Attribute Helper. I believe that other users may encounter the same problem.

0 Likes

BrianEkins
Mentor
Mentor

@nnikbin, thanks for letting me know

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes