Changing a NonParametricBaseFeature without destroying references?

Changing a NonParametricBaseFeature without destroying references?

Anonymous
Not applicable
676 Views
3 Replies
Message 1 of 4

Changing a NonParametricBaseFeature without destroying references?

Anonymous
Not applicable

Hello there!

 

We've written an Inventor AddIn that creates a ClientFeature in a part document using one or more NonParametricBaseFeature objects that get force-fed with the geometry we compute (through a TransientBRep object). The result of this is one solid. So far, this works well enough.

 

However, we've recently encountered a problem with drawings based on part documents like that: Dimensions (measures) added to the drawing get deleted when the NonParametricBaseFeature gets replaced by a new one, even if the two have the same topology or are, in fact, geometrically identical. I assume this is because the new feature has no relation to the original one and there is basically no way the drawing can know what geometry the dimension is referring to. So far, we assumed the references to geometry in a part document would be something like Solid(0).Face(0).Edge(0) etc, but this doesn't seem to be the case. Otherwise, replacing the feature with a new one that is identical would not destroy these references.

 

Is there a way to make this work?

 

Ideally, I would like to achieve the following: Through the use of ModelingEvents.OnClientFeatureDoubleClick our ClientFeature gets replaced by an updated version and all drawings referencing this feature get updated accordingly with all dimensions intact, as long as the changes only affect geometry and the topology stays the same.

 

PS: Currently we're working with Inventor 2013 and 2014, using the .NET API in C#.

0 Likes
Accepted solutions (1)
677 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

What you want to is possible using an undocumented property.  There's a property on the Face, Edge, and Vertex objects called AssociativeID that is there for this specific purpose.  It's only purpose is for these non-parametric bodies.  While the body is still transient, this property can be set and it is maintained when the NonParametricBaseBody is created.  Downstream operations will use this ID for associativity.  The easiest thing to do is to just apply it to the faces because Inventor can figure out the edges and vertices if the faces have ID's.  Your work is to consistently apply the same ID's to what are logically the same faces in the new body.  The sample code below can be used to demonstrate this.  The first sub creates a base body with ID's.  The second sub updates it with a new body, but it applies the same ID's to the new body used for the replacement.  Once you create the initial feature you can apply additional features and use the part in a drawing or assembly.  After you do the replacement everything should update as expected.

 

Public Sub CreateBrep()
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    Dim b As Box
    Set b = tg.CreateBox
    b.MinPoint = tg.CreatePoint(0, 0, 0)
    b.MaxPoint = tg.CreatePoint(5, 4, 2)
    Dim body As SurfaceBody
    Set body = ThisApplication.TransientBRep.CreateSolidBlock(b)
    
    Dim f As Face
    Dim cnt As Integer
    cnt = 1
    For Each f In body.Faces
        f.AssociativeID = cnt
        cnt = cnt + 1
    Next
    
    Dim part As PartDocument
    Set part = ThisApplication.ActiveDocument
    
    Call part.ComponentDefinition.Features.NonParametricBaseFeatures.Add(body)
End Sub


Public Sub ReplaceBrep()
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    Dim b As Box
    Set b = tg.CreateBox
    b.MinPoint = tg.CreatePoint(0, 0, 0)
    b.MaxPoint = tg.CreatePoint(5, 2, 3)
    Dim body As SurfaceBody
    Set body = ThisApplication.TransientBRep.CreateSolidBlock(b)
    
    Dim f As Face
    Dim cnt As Integer
    cnt = 1
    For Each f In body.Faces
        f.AssociativeID = cnt
        cnt = cnt + 1
    Next
    
    Dim part As PartDocument
    Set part = ThisApplication.ActiveDocument

    Dim baseFeature As NonParametricBaseFeature
    Set baseFeature = part.ComponentDefinition.Features.NonParametricBaseFeatures.Item(1)
    Call baseFeature.Redefine(body)
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 4

Anonymous
Not applicable

Great! Thanks for your very detailed answer. I will definitely try this today.

0 Likes
Message 4 of 4

Anonymous
Not applicable

Works really well overall, thanks again.

 

A few issues with dimensions in a drawing losing their reference or getting placed oddly after the update remain, but I guess those lost references were points _on_ edges, not vertices or edges of the model and the odd placements are probably due to Inventor trying to find a good spot to place that new dimension. Most dimensions remain intact, though, so I'm pretty happy with that.

 

Would giving vertices and edges the same ids help Inventor or will those get ignored anyway? The geometry is created the same way each time, so it wouldn't really be an issue to create identical ids throughout the entire model.

0 Likes