Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Change color of feature faces

Status
Not open for further replies.

Sim77Son

Mechanical
Aug 4, 2012
18
thread561-317547

In the above thread is a journal to change the face color for simple and threaded hole.

But i need a journal that only change the color of the threaded hole and dont change the color of any othe hole.

Is it possible for someone to edit the journal for me?
 
Replies continue below

Recommended for you

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
 
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
 
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.
 
All threaded hole are features created with the hole command (see attached picture).

we have our own cdf, so in our case it would be blue, but the journal doesnt change anything. I have tried several numbers with different colors.
 
 http://files.engineering.com/getfile.aspx?folder=468014bc-3797-4ba3-a4e6-82449a386fee&file=20.04_01.jpg
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor