OlafU
Automotive
- Jan 31, 2012
- 19
Hello all.
I´m looking for a way, to Change the Color of components automatically. My idea is, to run through an assembly structure, search for a certain component name and change the color of this component to a defined color. I tried it with some bits and pieces from other scripts, I´m able to find the components in the assembly structure and highlight them. But I´m not able to select the components, neither to modify the Color of the components.
I created a small example assembly with the components Yellow, Green, Blue
Here is my script for this simple example:
'Search for Components, Highlight Components, Modify Coloring
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.Utilities
Module ListStructureOnlyComponents
Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theComps As New List(Of Assemblies.Component)
Sub Main()
Dim dp As Part = s.Parts.Display
Try
Dim c As Component = dp.ComponentAssembly.RootComponent
WalkAssemblyTree(c, "")
Catch e As Exception
End Try
End Sub
Sub Echo(ByVal output As String)
s.ListingWindow.Open()
s.ListingWindow.WriteLine(output)
s.LogFile.WriteLine(output)
End Sub
Sub WalkAssemblyTree(ByVal c As Component, ByVal indent As String)
Dim children As Component() = c.GetChildren()
Dim newIndent As String
Dim loadStatus1 As UFPart.LoadStatus = Nothing
Dim displayModification1 As DisplayModification
For Each child As Component In children
If indent.Length = 0 Then
newIndent = " "
Else
newIndent = indent & " "
End If
Dim theInst As NXOpen.Tag = ufs.Assem.AskInstOfPartOcc(child.Tag)
Try
If child.DisplayName.Contains("Yellow") Then
Echo ("Yellow found")
'Dim my_select As SelectionHandle = TransientObject()
'Selection.AddToTaggedObjectsSelectionList(my_select, child,True)
child.Highlight ()
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 6 'Color Yellow
displayModification1.Dispose()
End If
If child.DisplayName.Contains("Green") Then
Echo ("Green found")
'Dim my_select As SelectionHandle = TransientObject()
'Selection.AddToTaggedObjectsSelectionList(my_select, child,True)
child.Highlight ()
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 36 'Color Green
displayModification1.Dispose()
End If
If child.DisplayName.Contains("Blue") Then
Echo ("Blue found")
'Dim my_select As SelectionHandle = TransientObject()
'Selection.AddToTaggedObjectsSelectionList(my_select, child,True)
child.Highlight ()
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 211 'Color Blue
displayModification1.Dispose()
End If
Catch ex As Exception
Echo("Exception: " & ex.Message())
End Try
WalkAssemblyTree(child, newIndent)
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
Is there a way to to solve this issue?
Thanks in advance
NX11.0.0
I´m looking for a way, to Change the Color of components automatically. My idea is, to run through an assembly structure, search for a certain component name and change the color of this component to a defined color. I tried it with some bits and pieces from other scripts, I´m able to find the components in the assembly structure and highlight them. But I´m not able to select the components, neither to modify the Color of the components.
I created a small example assembly with the components Yellow, Green, Blue
Here is my script for this simple example:
'Search for Components, Highlight Components, Modify Coloring
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.Utilities
Module ListStructureOnlyComponents
Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theComps As New List(Of Assemblies.Component)
Sub Main()
Dim dp As Part = s.Parts.Display
Try
Dim c As Component = dp.ComponentAssembly.RootComponent
WalkAssemblyTree(c, "")
Catch e As Exception
End Try
End Sub
Sub Echo(ByVal output As String)
s.ListingWindow.Open()
s.ListingWindow.WriteLine(output)
s.LogFile.WriteLine(output)
End Sub
Sub WalkAssemblyTree(ByVal c As Component, ByVal indent As String)
Dim children As Component() = c.GetChildren()
Dim newIndent As String
Dim loadStatus1 As UFPart.LoadStatus = Nothing
Dim displayModification1 As DisplayModification
For Each child As Component In children
If indent.Length = 0 Then
newIndent = " "
Else
newIndent = indent & " "
End If
Dim theInst As NXOpen.Tag = ufs.Assem.AskInstOfPartOcc(child.Tag)
Try
If child.DisplayName.Contains("Yellow") Then
Echo ("Yellow found")
'Dim my_select As SelectionHandle = TransientObject()
'Selection.AddToTaggedObjectsSelectionList(my_select, child,True)
child.Highlight ()
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 6 'Color Yellow
displayModification1.Dispose()
End If
If child.DisplayName.Contains("Green") Then
Echo ("Green found")
'Dim my_select As SelectionHandle = TransientObject()
'Selection.AddToTaggedObjectsSelectionList(my_select, child,True)
child.Highlight ()
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 36 'Color Green
displayModification1.Dispose()
End If
If child.DisplayName.Contains("Blue") Then
Echo ("Blue found")
'Dim my_select As SelectionHandle = TransientObject()
'Selection.AddToTaggedObjectsSelectionList(my_select, child,True)
child.Highlight ()
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 211 'Color Blue
displayModification1.Dispose()
End If
Catch ex As Exception
Echo("Exception: " & ex.Message())
End Try
WalkAssemblyTree(child, newIndent)
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
Is there a way to to solve this issue?
Thanks in advance
NX11.0.0