Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

changing color of faces i body

Status
Not open for further replies.

Boro42

Automotive
Jul 31, 2013
10
Hi together,

nice place here to learn NXOpen :)! 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
 
Replies continue below

Recommended for you

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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor