Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on Journal for copying surfaces to new layer

Status
Not open for further replies.

NXsupport

Computer
Joined
Apr 11, 2008
Messages
251
Location
US
Hi,

NX8.5.3

I able to change color of faces of geometry which are B-Surfaces to a specific color . Now I want to copy those surfaces to a new layer and then change the color and also the font of the edges to ----- ..

A journal or macro would be awesome for this..

Also, I have seen that there is no way to select surfaces whose faces have a different color than the body color..

As Copy to layer does not allow to pick faces, how can we achieve this?

Please help..

Thanks so much..

 
NXsupport said:
As Copy to layer does not allow to pick faces, how can we achieve this?

Using the Extract geometry -> faces command, you can create an associative copy of the face, move it to the desired layer, change the color, etc.

www.nxjournaling.com
 
Hi Cowski,

How do I do all these operations in one Journal file?

Please can you share a journal on this?

Thanks in advance..
 
I was going to ask you the same question [bigsmile]

I would suggest that you start by recording a journal while creating an extract face feature, then try to incorporate that into the existing code. When that works, then work on adding code to move it to the desired layer. Add code to change the color. Etc etc. Build it up in manageable pieces.

www.nxjournaling.com
 
don't forget when you COPY to another layer you are actually making another copy of the surface so there will be two of them in the model
 
Kool.. Got it.. I will surely try this method out..

Thanks for the support..

You guys are awesome..
 
Hi Cowski,

I created this journal. Now this works fine on solid body or parasolid with B surfaces.. This errors out if I try to run it on a file which has only surfaces..For example, I do IGES import and run this journal. It errors out..

How can I tune it?

Please help..
 
 http://files.engineering.com/getfile.aspx?folder=2ad1649f-4d33-48e1-b822-6448d22d96b9&file=COPYBSURFACE.vb
Hi Coswki,

I was taking one step more from this thread
thread561-349780: changing color of faces i body

Once I get those yellow faces, I want to extract the surfaces of the faces and then move them to a new layer and change the color and font of the edges of the extracted faces.

Please let me know how I can achieve this..
 
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
 
Hi Cowski,

Thanks for all the support and help ..

I recorded this journal to move the surfaces to new layer and change the color and font of the edge. Now I want to combine the code which you gave me to extract the sheets and this..

Please can you help me ?

Also, Can we integrate Macros into Journal file?

Iam not a code developer, but trying to be one.. :))
 
 http://files.engineering.com/getfile.aspx?folder=085ba116-3d05-46d7-aa63-4337175aad38&file=MOVETOLAYER.vb
NXsupport said:
Also, Can we integrate Macros into Journal file?
Not that I know of, and even if there is a way, I advise against it.



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

        lw.WriteLine(BFaces.Count.ToString & " B surface faces found")


        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)

        extractFaceBuilder1.Commit()

        Dim myExtractedFaces() As NXObject
        myExtractedFaces = extractFaceBuilder1.GetCommittedObjects

        extractFaceBuilder1.Destroy()

        Dim theExtractedFaces As New List(Of DisplayableObject)

        For Each myFeat As Features.ExtractFace In myExtractedFaces
            lw.WriteLine(myFeat.GetFeatureName)
            For Each tempBody As Body In myFeat.GetBodies
                theExtractedFaces.Add(tempBody)
            Next
        Next


        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()

        displayModification1.ApplyToAllFaces = True

        displayModification1.ApplyToOwningParts = False

        displayModification1.NewColor = 130

        displayModification1.NewFont = DisplayableObject.ObjectFont.Dashed

        displayModification1.NewWidth = DisplayableObject.ObjectWidth.Two

        displayModification1.NewLayer = 220

        displayModification1.Apply(theExtractedFaces.ToArray)

        displayModification1.Dispose()



        lw.Close()

    End Sub

End Module

www.nxjournaling.com
 
HI Cowski,

You ROCK.. You are awesome.. Thanks a ton to fixing the journal..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top