×
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

Trying to change the color of parts in a Assembly!!! PLEASE CAN SOMEONE HELP ME!!!!!!

Trying to change the color of parts in a Assembly!!! PLEASE CAN SOMEONE HELP ME!!!!!!

Trying to change the color of parts in a Assembly!!! PLEASE CAN SOMEONE HELP ME!!!!!!

(OP)
I have started a vb where it runs through each part in a assembly and changes the color. I have run into a problem I need to create a different color for each part. Also I need the color to the actual part not just the color in the assembly. Below you'll find the code that I have started. PLEASE CAN SOMEONE HELP ME

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.part
Imports NXOpen.UI
Imports NXOpen.Utilities


Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
Dim myBody As Body
Dim displayModification1 As DisplayModification



lw.Open
Try
' Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
Dim c As ComponentAssembly = workPart.ComponentAssembly
'Dim rnd1 As New Random()
'Dim myPt1 As interger




if not IsNothing(c.RootComponent) then

'*** insert code to process 'root component' (assembly file)



' do an action on the collected solids

Dim visibleObjects() As DisplayableObject
visibleObjects = workpart.Views.WorkView.AskVisibleObjects()
For Each displayableObject As DisplayableObject In visibleObjects
If TypeOf displayableObject Is Body Then
Dim body As Body = displayableObject
Dim rnd1 As New Random()



Randomize()
' Generate random value between 1 and 6.
Dim value As Integer = CInt(Int((97 * Rnd()) + 1))


Lw.WriteLine("Body: " & body.JournalIdentifier)
body.highlight()



displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = True

displayModification1.ApplyToOwningParts = true

displayModification1.NewColor = value


Dim objects1(0) As DisplayableObject

objects1(0) = myBody
displayModification1.Apply(visibleobjects)

displayModification1.Dispose()


End If
Next

lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
ReportComponentChildren(c.RootComponent, 0)
else
'*** insert code to process piece part

' Dim visibleObjects() As DisplayableObject
' visibleObjects = workPart.Views.WorkView.AskVisibleObjects()
' For Each displayableObject As DisplayableObject In visibleObjects
' If TypeOf displayableObject Is Body Then
' Dim body As Body = displayableObject
' Lw.WriteLine("Body: " & body.JournalIdentifier)
' body.highlight()
'


' displayModification1 = theSession.DisplayManager.NewDisplayModification()
'
' displayModification1.ApplyToAllFaces = True
'
' displayModification1.ApplyToOwningParts = false
' displayModification1.NewColor = 46


' Dim objects1(0) As DisplayableObject
'
' objects1(0) = myBody
' displayModification1.Apply(visibleobjects)
'
' displayModification1.Dispose()
'

'End If
' Next



lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close

End Sub

'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
end if
reportComponentChildren(child, indent + 1)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

end module









RE: Trying to change the color of parts in a Assembly!!! PLEASE CAN SOMEONE HELP ME!!!!!!

You are making it much more difficult than necessary.

When you right click any component in your assembly and select "properties", then there is a Check box titled "Specific Component Colour".

If its Checked ... un-Check it and it will inherit the colour from the individual part.
If its 'greyed out' ... then this gets automatically Checked when you change the colour within "Edit Display".
So if you apply this in your code you don't need to "read" the color from the original body and change it..

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX11 / TC11

RE: Trying to change the color of parts in a Assembly!!! PLEASE CAN SOMEONE HELP ME!!!!!!

Also NX only has what 216 colors?, which would put a hard limit on the number of unique components.

RE: Trying to change the color of parts in a Assembly!!! PLEASE CAN SOMEONE HELP ME!!!!!!

(OP)
How do I apply "Specific Component Colour" to my code?

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