[COLOR=green]'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=356772[/URL][/color]
[COLOR=green]'clean invalid edge references from edge blends[/color]
[COLOR=green]'not thouroughly tested for variable radius blends[/color]
[COLOR=green]'February 10, 2014[/color]
[COLOR=blue]Option Strict Off[/color]
[COLOR=blue]Imports[/color] System
[COLOR=blue]Imports[/color] System.Collections.Generic
[COLOR=blue]Imports[/color] NXOpen
[COLOR=blue]Module[/color] BlendCleaner
[COLOR=blue]Sub[/color] Main()
[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work
[COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow
lw.Open()
[COLOR=blue]Const[/color] undoName [COLOR=blue]As String =[/color] "Blend Cleaner"
[COLOR=blue]Dim[/color] markId1 [COLOR=blue]As[/color] Session.UndoMarkId
markId1 [COLOR=blue]=[/color] theSession.SetUndoMark(Session.MarkVisibility.Invisible, undoName)
[COLOR=blue]Dim[/color] numCleaned [COLOR=blue]As Integer =[/color] 0
[COLOR=blue]Dim[/color] nullFeature [COLOR=blue]As[/color] Features.Feature [COLOR=blue]= Nothing[/color]
[COLOR=blue]Dim[/color] currentFeat [COLOR=blue]As[/color] Features.Feature [COLOR=blue]=[/color] workPart.CurrentFeature
[COLOR=blue]Dim[/color] prevFeat [COLOR=blue]As[/color] Features.Feature [COLOR=blue]= Nothing[/color]
[COLOR=blue]For Each[/color] tempFeat [COLOR=blue]As[/color] Features.Feature [COLOR=blue]In[/color] workPart.Features
[COLOR=blue]If[/color] tempFeat.FeatureType [COLOR=blue]=[/color] "BLEND" [COLOR=blue]Then[/color]
[COLOR=blue]Dim[/color] myBlend [COLOR=blue]As[/color] Features.EdgeBlend [COLOR=blue]=[/color] tempFeat
[COLOR=blue]Dim[/color] blendWarnings() [COLOR=blue]As String =[/color] myBlend.GetFeatureWarningMessages()
[COLOR=blue]Dim[/color] needsCleaning [COLOR=blue]As Boolean = False[/color]
[COLOR=blue]For Each[/color] myLine [COLOR=blue]As String In[/color] blendWarnings
[COLOR=blue]If[/color] myLine.ToLower.Contains("consumed") [COLOR=blue]Then[/color]
needsCleaning [COLOR=blue]= True[/color]
End [COLOR=blue]If[/color]
[COLOR=blue]Next[/color]
[COLOR=green]'make previous feature the current feature[/color]
prevFeat.MakeCurrentFeature()
[COLOR=green]'edit blend feature with rollback[/color]
workPart.Features.SetEditWithRollbackFeature(myBlend)
[COLOR=blue]Dim[/color] blendBuilder [COLOR=blue]As[/color] Features.EdgeBlendBuilder [COLOR=blue]=[/color] workPart.Features.CreateEdgeBlendBuilder(myBlend)
[COLOR=blue]Dim[/color] validEdges [COLOR=blue]As New[/color] List(Of Edge)
[COLOR=blue]Dim[/color] myCollector [COLOR=blue]As[/color] ScCollector
[COLOR=blue]Dim[/color] myExp [COLOR=blue]As[/color] Expression
[COLOR=blue]Dim[/color] valid [COLOR=blue]As Boolean[/color]
[COLOR=blue]For[/color] i [COLOR=blue]As Integer =[/color] 0 [COLOR=blue]To[/color] blendBuilder.GetNumberOfValidChainsets [COLOR=blue]-[/color] 1
blendBuilder.GetChainsetAndStatus(i, myCollector, myExp, valid)
[COLOR=blue]Dim[/color] myObjects() [COLOR=blue]As[/color] TaggedObject [COLOR=blue]=[/color] myCollector.GetObjects
[COLOR=blue]For Each[/color] temp [COLOR=blue]As[/color] Edge [COLOR=blue]In[/color] myObjects
[COLOR=blue]Try[/color]
temp.GetLength()
validEdges.Add(temp)
[COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] NXException
[COLOR=green]'edge has been consumed or suppressed[/color]
End [COLOR=blue]Try[/color]
[COLOR=blue]Next[/color]
[COLOR=blue]Dim[/color] edgeMultipleSeedTangentRule1 [COLOR=blue]As[/color] EdgeMultipleSeedTangentRule
edgeMultipleSeedTangentRule1 [COLOR=blue]=[/color] workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(validEdges.ToArray, 0.5, [COLOR=blue]True[/color])
[COLOR=blue]Dim[/color] rules1(0) [COLOR=blue]As[/color] SelectionIntentRule
rules1(0) [COLOR=blue]=[/color] edgeMultipleSeedTangentRule1
myCollector.ReplaceRules(rules1, [COLOR=blue]False[/color])
[COLOR=blue]Dim[/color] csIndex1 [COLOR=blue]As Integer[/color]
csIndex1 [COLOR=blue]=[/color] blendBuilder.AddChainset(myCollector, myExp.Value.ToString)
[COLOR=blue]Next[/color]
blendBuilder.CommitFeature()
blendBuilder.Destroy()
numCleaned [COLOR=blue]+=[/color] 1
currentFeat.MakeCurrentFeature()
workPart.Features.SetEditWithRollbackFeature(nullFeature)
End [COLOR=blue]If[/color]
prevFeat [COLOR=blue]=[/color] tempFeat
[COLOR=blue]Next[/color]
[COLOR=blue]If[/color] numCleaned > 0 [COLOR=blue]Then[/color]
theSession.SetUndoMarkVisibility(markId1, undoName, Session.MarkVisibility.Visible)
End [COLOR=blue]If[/color]
lw.Close()
End [COLOR=blue]Sub[/color]
End [COLOR=blue]Module[/color]