×
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

Change color of feature faces

Change color of feature faces

RE: Change color of feature faces

Don't forget to mention the version of NX that you are on.

Jerry J.
Milwaukee Electric Tool
http://www.milwaukeetool.com/

RE: Change color of feature faces

(OP)
Sure.

I´m working on NX 8.0.3.4

RE: Change color of feature faces

Here's a slight modification of Frank's journal code:

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features

Module HoleColours

    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim dp As Part = s.Parts.Work
        Dim expstring As String = Nothing
        Dim index2 As Integer = -1
        Dim exps() As Expression
        Dim holewiththread As Boolean = False
        Dim holeexpstring As String = "Threaded"
        Dim hole As BodyFeature
        Dim faces() As Face
        Dim nFaces As Integer = 0
        Dim obj(-1) As DisplayableObject
        Dim displayModification1 As DisplayModification
        Dim featcoll As FeatureCollection = dp.Features
        For Each f As Feature In featcoll
            If f.FeatureType = "SIMPLE HOLE" Then
                holewiththread = False
                exps = f.GetExpressions()
                index2 = exps(0).Description.IndexOf(holeexpstring)
                If index2 > 0 Then
                    holewiththread = True
                End If
                If holewiththread = True Then
                    hole = DirectCast(f, BodyFeature)
                    faces = hole.GetFaces()
                    nFaces = faces.Length
                    ReDim obj(nFaces - 1)
                    For i As Integer = 0 To nFaces - 1
                        obj(i) = faces(i)
                    Next
                    displayModification1 = s.DisplayManager.NewDisplayModification()
                    displayModification1.ApplyToAllFaces = False
                    displayModification1.NewColor = 6
                    displayModification1.Apply(obj)
                Else 'holewiththread is false
                    'hole = DirectCast(f, BodyFeature)
                    'faces = hole.GetFaces()
                    'nFaces = faces.Length
                    'ReDim obj(nFaces - 1)
                    'For i As Integer = 0 To nFaces - 1
                    '    obj(i) = faces(i)
                    'Next
                    'displayModification1 = s.DisplayManager.NewDisplayModification()
                    'displayModification1.ApplyToAllFaces = False
                    'displayModification1.NewColor = 211
                    'displayModification1.Apply(obj)
                End If
            End If
        Next
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module 

www.nxjournaling.com

RE: Change color of feature faces

The code above only works on threaded holes created with the "hole" command. Also, the journal will assign color #6 to the threaded hole face; the actual color will depend on the color definition file (CDF) that the part references (in recent versions, for the default CDF, color #6 = yellow).

www.nxjournaling.com

RE: Change color of feature faces

What version could you right click on a feature and change the feature color? So in the part navigator right click on a fillet feature and you should be able to turn it to red or what ever color you like.

RE: Change color of feature faces

NX 8.5 has the ability to assign colors to features, Sim77Son is using NX 8.

www.nxjournaling.com

RE: Change color of feature faces

Ok, I see the issue now. The code above loops through the hole feature expressions looking for the English word "threaded" to determine if it is a threaded hole or not. You will need to search for the equivalent word in the language NX is set to use (German?)

Change the following line to look for the appropriate word:

CODE

Dim holeexpstring As String = "Threaded" 

www.nxjournaling.com

RE: Change color of feature faces

(OP)
Great, it works.

Thank you.

RE: Change color of feature faces

Here is a variation on Frank's code that is independent of the NX language setting.

CODE

Option Strict Off
Imports System
Imports NXOpen

Module change_hole_color

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

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

        Const undoMarkName As String = "change hole color"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Const holeColor As Integer = 211
        Const holeThreadedColor As Integer = 6
        Dim newColor As Integer
		Dim changeColor as Boolean = True

        For Each theFeature As Features.Feature In workPart.Features

            If theFeature.FeatureType = "HOLE PACKAGE" Then
                Dim theHolePackageBuilder As Features.HolePackageBuilder = workPart.Features.CreateHolePackageBuilder(theFeature)

                If theHolePackageBuilder.Type = Features.HolePackageBuilder.Types.ThreadedHole Then
					changeColor = True
                    newColor = holeThreadedColor
                Else
					changeColor = False
                    newColor = holeColor
                End If

                theHolePackageBuilder.Destroy()
				
		if changeColor then
			Dim displayModification1 As DisplayModification
			displayModification1 = theSession.DisplayManager.NewDisplayModification()
			displayModification1.ApplyToAllFaces = False
			displayModification1.NewColor = newColor
			displayModification1.Apply(CType(theFeature, Features.HolePackage).GetFaces)
			displayModification1.Dispose()
		end if

            End If

        Next


        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    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