Both journals are short and straightforward, so let's step through the process of combining them. First step is to remove some unnecessary code from the journal recorder.
In the COPYBSURFACE.vb journal, you will see references to:
[ul][li]wavePointBuilder1[/li]
[li]waveDatumBuilder1[/li]
[li]compositeCurveBuilder1[/li]
[li]extractFaceBuilder1[/li]
[li]mirrorBodyBuilder1[/li][/ul]
We are only interested in the extractFaceBuilder1; keep the lines that reference the extractFaceBuilder1, and delete the rest. The journal recorder faithfully records the settings in the dialog box as you work; since it doesn't know which option you will be using, it records them all.
Next up, you'll see a lot of lines that look like:
Code:
Dim face1 As Face = CType(brep1.FindObject("FACE 6 {(116.8973819204165,165.0696538070952,-8.5412500043044) UNPARAMETERIZED_FEATURE(34)}"), Face)
The journal recorder also records the exact entities that you pick while recording. This means that the journal in its current form will only really work when run on that one particular part you had open when you recorded the journal. This is known as "selection stickiness" and we need to remove the dependency on the particular objects in the particular part file to make the code usable in other parts. Delete the lines that reference these particular faces. We'll need to write code that will find the faces for us (this is where the other journal comes in, it finds the B-sufaces, we'll only need to tweak it slightly for our new use).
At this point, the code that extracts the faces looks like this:
Code:
Dim nullFeatures_Feature As Features.Feature = Nothing
If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If
Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
extractFaceBuilder1 = workPart.Features.CreateExtractFaceBuilder(nullFeatures_Feature)
extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.WorkPart
theSession.SetUndoMarkName(markId1, "Extract Geometry Dialog")
extractFaceBuilder1.Associative = True
extractFaceBuilder1.FixAtCurrentTimestamp = True
extractFaceBuilder1.HideOriginal = False
extractFaceBuilder1.DeleteHoles = False
extractFaceBuilder1.InheritDisplayProperties = False
extractFaceBuilder1.Type = Features.ExtractFaceBuilder.ExtractType.Face
' ----------------------------------------------
' Menu: Edit->Selection->Detailed Filtering...
' ----------------------------------------------
Dim objects1(14) As DisplayableObject
Dim added1 As Boolean
added1 = extractFaceBuilder1.ObjectToExtract.Add(objects1)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Extract Geometry")
theSession.DeleteUndoMark(markId2, Nothing)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Extract Geometry")
Dim nXObject1 As NXObject
nXObject1 = extractFaceBuilder1.Commit()
theSession.DeleteUndoMark(markId3, Nothing)
theSession.SetUndoMarkName(markId1, "Extract Geometry")
extractFaceBuilder1.Destroy()
Take note of these lines of code:
Code:
Dim objects1(14) As DisplayableObject
Dim added1 As Boolean
added1 = extractFaceBuilder1.ObjectToExtract.Add(objects1)
If you check the API reference, you will see that the extractFaceBuilder .Add method accepts either a single object or an array of objects of type DisplayableObject. Let's modify the other journal to collect the B-surface faces in preparation for the extractFaceBuilder.
Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Bsurface_extract_color
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim BFaces As New List(Of DisplayableObject)
For Each myBody As Body In workPart.Bodies
For Each tempFace As Face In myBody.GetFaces
'lw.WriteLine(tempFace.SolidFaceType.ToString)
If tempFace.SolidFaceType = Face.FaceType.Parametric Then
BFaces.Add(tempFace)
End If
Next
Next
lw.WriteLine(BFaces.Count.ToString & " B surface faces found")
lw.Close()
End Sub
End Module
If you run the code above, it will simply report how many B-surface faces were found. You'll see that I used a "list" object to keep track of the faces (as displayable objects). The list object is more convenient to use than an array and it includes a method to convert it to an array - just what we need.
Now, let's copy & paste the extract face code into the other journal and tweak it to use the faces it found.
Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Bsurface_extract_color
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "extract B-surface faces")
Dim BFaces As New List(Of DisplayableObject)
For Each myBody As Body In workPart.Bodies
For Each tempFace As Face In myBody.GetFaces
'lw.WriteLine(tempFace.SolidFaceType.ToString)
If tempFace.SolidFaceType = Face.FaceType.Parametric Then
BFaces.Add(tempFace)
End If
Next
Next
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
extractFaceBuilder1 = workPart.Features.CreateExtractFaceBuilder(nullFeatures_Feature)
extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.WorkPart
extractFaceBuilder1.Associative = True
extractFaceBuilder1.FixAtCurrentTimestamp = True
extractFaceBuilder1.HideOriginal = False
extractFaceBuilder1.DeleteHoles = False
extractFaceBuilder1.InheritDisplayProperties = False
extractFaceBuilder1.Type = Features.ExtractFaceBuilder.ExtractType.Face
Dim added1 As Boolean
added1 = extractFaceBuilder1.ObjectToExtract.Add(BFaces.ToArray)
Dim nXObject1 As NXObject
nXObject1 = extractFaceBuilder1.Commit()
extractFaceBuilder1.Destroy()
'lw.WriteLine(BFaces.Count.ToString & " B surface faces found")
lw.Close()
End Sub
End Module
The code above will now find all the B-surface faces in any file it is run on and extract them.
www.nxjournaling.com