×
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

changing color of faces i body

changing color of faces i body

changing color of faces i body

(OP)
Hi together,

nice place here to learn NXOpen smile! I don’t really understand following:
How can I select automatically all faces of a body and then change the color of all B-surfaces to yellow and cylindrical Faces to green ?!
Would be cool if anybody can help me !

Best regards
Boro

RE: changing color of faces i body

You can get a collection of faces from a given solid body. Loop through this collection testing the face type; if the desired face type is found, change the color of the face.

Below is some example code:

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

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

        Dim mySolid As Body
        If SelectSolid("select a solid body", mySolid) = Selection.Response.Cancel Then
            Exit Sub
        End If

        For Each tempFace As Face In mySolid.GetFaces

            'lw.WriteLine(tempFace.SolidFaceType.ToString)

            If tempFace.SolidFaceType = Face.FaceType.Cylindrical Then
                '36 = green in current CDF
                tempFace.Color = 36
                tempFace.RedisplayObject()
            End If

            If tempFace.SolidFaceType = Face.FaceType.Parametric Then
                '6 = yellow in current CDF
                tempFace.Color = 6
                tempFace.RedisplayObject()
            End If

        Next

        lw.Close()

    End Sub

    Function SelectSolid(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a solid"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function

End Module 

www.nxjournaling.com

RE: changing color of faces i body

(OP)
Hi Cowski

you are super smile thank you very much for your help!
A last question, how can I change the code to get an auto select of all bodys (without asking me to select a body

Big thanks to you!!
Boro

RE: changing color of faces i body

You can loop through the part's "Bodies" collection. This collection contains both solid and sheet bodies; to differentiate between sheet and solid bodies you can check the object's .IsSolidBody or .IsSheetBody properties. The code below does not check the body type, it will process all the bodies in the work part (solids and sheets).

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

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

        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.Cylindrical Then
                    '36 = green in current CDF
                    tempFace.Color = 36
                    tempFace.RedisplayObject()
                End If

                If tempFace.SolidFaceType = Face.FaceType.Parametric Then
                    '6 = yellow in current CDF
                    tempFace.Color = 6
                    tempFace.RedisplayObject()
                End If

            Next

        Next


        lw.Close()

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function

End Module 

www.nxjournaling.com

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