Forums:
Hello,
Thanks for taking the time to look at this. I know very little about this subject but am fumbling my way through it. What I would like is a journal that applies a random color to each of the selected components. I know there is an appearance setting for this but that does not give me the results I desire. I have searched and found code originally posted here by NXJournaling that is very close. I have modified it to produce a random color, however it applies this same random color to each component. I would like each component that is selected to have a different random color. I know it needs to be in some sort of loop but I have no idea how to make that happen. Anyway, below is the code:
Option Strict Off Imports System Imports System.Collections.Generic Imports NXOpen Imports NXOpenUI Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim theUI As UI = UI.GetUI If IsNothing(theSession.Parts.BaseWork) Then 'active part required Return End If Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects() Dim theComps As New List(Of Assemblies.Component) For i As Integer = 0 To numsel - 1 Dim selObj As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i) If TypeOf (selObj) Is Assemblies.Component Then theComps.Add(selObj) End If Next If theComps.Count = 0 Then 'no components found among the preselected objects Return End If randomize Dim mycolor as integer = Int ((216-1) * Rnd + 1) Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display") Dim displayModification1 As DisplayModification displayModification1 = theSession.DisplayManager.NewDisplayModification() With displayModification1 .ApplyToAllFaces = False .ApplyToOwningParts = False .NewColor = mycolor .Apply(theComps.ToArray) End With displayModification1.Dispose() 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