Blend Reference Cleaner

remove missing parents from edge blend features

I don't think this will come as news to anyone, but edge blend features depend on edges in the model. This sounds really obvious (which it is), but given how even minor edits can create or remove dozens of edges, it is surprising how stable the edge blend features really are. When a parent edge is modeled away, the edge blend feature will 'remember' where it used to be and display a warning icon in the feature tree. Occasionally, these warnings are very useful to track down unintentional changes; but more often than not, you are well aware of the changes and simply want to remove the old blend parents and get rid of the warning.

The Code

The journal below will search through the feature tree and remove any missing parents from the edge blends.


The code below should run on NX 7.5 or above.





Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module BlendCleaner_75

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoName As String = "Blend Cleaner"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, undoName)

Dim numCleaned As Integer = 0

Dim nullFeature As Features.Feature = Nothing
Dim currentFeat As Features.Feature = workPart.CurrentFeature

Dim prevFeat As Features.Feature = Nothing
For Each tempFeat As Features.Feature In workPart.Features

If tempFeat.FeatureType = "BLEND" Then

Dim myBlend As Features.EdgeBlend = tempFeat
Dim blendWarnings() As String = myBlend.GetFeatureWarningMessages()
Dim needsCleaning As Boolean = False

For Each myLine As String In blendWarnings
If myLine.ToLower.Contains("consumed") Then
needsCleaning = True
End If
Next

If needsCleaning Then
'make previous feature the current feature
prevFeat.MakeCurrentFeature()

'edit blend feature with rollback
'workPart.Features.SetEditWithRollbackFeature(myBlend)

Dim blendBuilder As Features.EdgeBlendBuilder = workPart.Features.CreateEdgeBlendBuilder(myBlend)

Dim validEdges As New List(Of Edge)

Dim myCollector As ScCollector
Dim myExp As Expression
Dim valid As Boolean
For i As Integer = 0 To blendBuilder.GetNumberOfValidChainsets - 1
blendBuilder.GetChainsetAndStatus(i, myCollector, myExp, valid)

Dim myObjects() As TaggedObject = myCollector.GetObjects

For Each temp As Edge In myObjects
Try
temp.GetLength()
validEdges.Add(temp)

Catch ex As NXException
'lw.WriteLine(" error: " & ex.Message)
'edge has been consumed or suppressed
End Try
Next

Dim edgeMultipleSeedTangentRule1 As EdgeMultipleSeedTangentRule
edgeMultipleSeedTangentRule1 = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(validEdges.ToArray, 0.5, True)

Dim rules1(0) As SelectionIntentRule
rules1(0) = edgeMultipleSeedTangentRule1
myCollector.ReplaceRules(rules1, False)

Dim csIndex1 As Integer
csIndex1 = blendBuilder.AddChainset(myCollector, myExp.Value.ToString)

Next

blendBuilder.CommitFeature()
blendBuilder.Destroy()

numCleaned += 1

currentFeat.MakeCurrentFeature()
'workPart.Features.SetEditWithRollbackFeature(nullFeature)

End If

End If

prevFeat = tempFeat

Next

If numCleaned > 0 Then
theSession.SetUndoMarkVisibility(markId1, undoName, Session.MarkVisibility.Visible)
End If
lw.Close()

End Sub

End Module




Warnings

The code above will remove any missing edge parents and will set the selection intent rule to 'tangent edges'. If this selection intent rule is not what you desire, modify the code accordingly. Also, the journal was not thoroughly tested with variable radius edge blends. If you find any bugs or encounter unexpected results, leave a comment or email me at info@nxjournaling.com