Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Changing configuration files for hole operations

AspirineCD

Aerospace
Oct 18, 2024
2
Hi
I need help modifying standard NX settings. Can I add a parameter to the “Hole” command, so that each hole created is colored according to its type: simple, threaded, or drilled?
If that’s not possible, or too complex to implement, then I have another question. I need to modify a script that I borrowed from comrade cowski, and adapted to my needs, but I lack the knowledge to make the hole coloring work for the entire assembly, without selecting a single detail, and have it inherited by the detail.

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

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 = 200 
        Const holeThreadedColor As Integer = 6
 	Const holeDrillColor As Integer = 150
        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 holePackageBuilder As Features.HolePackageBuilder = workPart.Features.CreateHolePackageBuilder(theFeature)

                If holePackageBuilder.TypeOfHole = NXOpen.Features.HolePackageBuilder.TypesOfHole.ThreadedHole Then
                    changeColor = True
                    newColor = holeThreadedColor
                Else
			If holePackageBuilder.TypeOfHole = NXOpen.Features.HolePackageBuilder.TypesOfHole.Simple and holePackageBuilder.SizeOfHole = NXOpen.Features.HolePackageBuilder.SizesOfHole.DrillSize Then
                    	changeColor = True
                    	newColor = holeDrillColor
			Else
                    changeColor = True 
                    newColor = holeColor                 
		End If
		End If
                holePackageBuilder.Destroy()

                If changeColor Then
                    Dim displayModification1 As DisplayModification
                    displayModification1 = theSession.DisplayManager.NewDisplayModification()
                    displayModification1.ApplyToAllFaces = True
		    displayModification1.ApplyToOwningParts = True
                    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
Thanks!
 
Replies continue below

Recommended for you

mb, a script that runs alongside NX and operates during modeling, which would identify hole creation and color it immediately. [ponder]
 

Part and Inventory Search

Sponsor