×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help on Journal for copying surfaces to new layer

Help on Journal for copying surfaces to new layer

Help on Journal for copying surfaces to new layer

(OP)
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..

RE: Help on Journal for copying surfaces to new layer

Quote (NXsupport)

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

RE: Help on Journal for copying surfaces to new layer

(OP)
Hi Cowski,

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

Please can you share a journal on this?

Thanks in advance..

RE: Help on Journal for copying surfaces to new layer

(OP)
Hello ,

Any luck on this?

RE: Help on Journal for copying surfaces to new layer

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

RE: Help on Journal for copying surfaces to new layer

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

RE: Help on Journal for copying surfaces to new layer

(OP)
Kool.. Got it.. I will surely try this method out..

Thanks for the support..

You guys are awesome..

RE: Help on Journal for copying surfaces to new layer

(OP)
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..

RE: Help on Journal for copying surfaces to new layer

(OP)
Hi Coswki,

I was taking one step more from this thread
thread561-349780: changing color of faces i body: 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..

RE: Help on Journal for copying surfaces to new layer

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:
  • wavePointBuilder1
  • waveDatumBuilder1
  • compositeCurveBuilder1
  • extractFaceBuilder1
  • mirrorBodyBuilder1
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

RE: Help on Journal for copying surfaces to new layer

(OP)
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.. :))

RE: Help on Journal for copying surfaces to new layer

Quote (NXsupport)

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

RE: Help on Journal for copying surfaces to new layer

(OP)
HI Cowski,

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources