×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*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.

# Change colors in an assembly5

## Change colors in an assembly

### RE: Change colors in an assembly

Make yourself a Macro to do one at a time.

### RE: Change colors in an assembly

(OP)
Are several components. To open each one will take a lot.

Can you open each component automatically and run a macro to replace colors?

### RE: Change colors in an assembly

Right click a component
choose make work part
change the color

Right click next part
choose make work part
change the color

...

### RE: Change colors in an assembly

If you mean change the component color
you can simply color it in the assembly.

### RE: Change colors in an assembly

(OP)

That's exactly it:

Right click a component
choose make work part
change the color

Right click next part
choose make work part
change the color

...

But, I would like to do this automatically with macro or journal.

### RE: Change colors in an assembly

Sorry I'm wrong these steps change the component specific color
and not the model color. If this what you want you car
Simply use the edit display and color the component directly
without make work part.

### RE: Change colors in an assembly

For coloring the model you need do make display part.

### RE: Change colors in an assembly

You want to change face color in part or in assembly? Because if You change colors from assembly level (make work part) it will be only visible in assembly. Next when You make display part the colors will go back to the previous state.

With best regards
Michael

### RE: Change colors in an assembly

Below is some code I created to process whole assembly and change faces color from 78 to 36 and from 181 to 211.

#### CODE

Option Strict Off
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpenUI

Module MoveComponents

Dim theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim layerNumber as Integer = 250
Dim newlayer as Integer = 1
Dim i as integer = 0
Dim myobjects as DisplayableObject()
Dim allObjects as NXObject()

Sub Main()

Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open

Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly

if not IsNothing(c.RootComponent) then

ReportComponentChildren(c.RootComponent, 0)
ReportComponentChildren1(c.RootComponent, 0)

end if

Catch e As Exception

theSession.ListingWindow.WriteLine("Failed: " & e.ToString)

End Try

lw.Close
workpart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.false)

End Sub

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

Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

For Each child As Component In comp.GetChildren()
Dim MyPart As Part = child.Prototype.OwningPart

Try

if child.IsSuppressed = true then

lw.writeline("   Error: " & child.DisplayName & ".prt" & " -> " & "part is closed")
Continue for
end if
Catch e1 As Exception
theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

end try

Else

End If

reportComponentChildren(child, indent+1)

Next
End Sub

'*****************************************************************************************
' Changing colors
'*****************************************************************************************

Sub reportComponentChildren1( ByVal comp As Component, ByVal indent As Integer)

Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

For Each child As Component In comp.GetChildren()
Dim MyPart As Part = child.Prototype.OwningPart

Try

if child.IsSuppressed = true then

'lw.writeline("   Error: " & child.DisplayName & ".prt" & " -> " & "part is closed")
Continue for
end if
Catch e11 As Exception
theSession.ListingWindow.WriteLine("Failed: " & e11.ToString)

end try

Dim theFaces1 As New List(Of Face)
Dim theFaces2 As New List(Of Face)

For Each theBody As Body In myPart.Bodies

Dim bodyFaces() As Face
bodyFaces = theBody.GetFaces

For Each tempFace As Face In bodyFaces

If tempFace.Color = 78 Then

else if tempFace.Color = 181 Then

End If

Next

Next

Dim displayModification1 As DisplayModification

displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = true
displayModification1.ApplyToOwningParts = False
displayModification1.NewColor = 36

For Each tempFace As Face In theFaces1

Dim objects1(0) As DisplayableObject
Dim face1 As Face
face1 = tempFace
objects1(0) = face1
displayModification1.Apply(objects1)

Next
displayModification1.Dispose()

Dim displayModification2 As DisplayModification

displayModification2 = theSession.DisplayManager.NewDisplayModification()
displayModification2.ApplyToAllFaces = true
displayModification2.ApplyToOwningParts = False
displayModification2.NewColor = 211

For Each tempFace As Face In theFaces2

Dim objects1(0) As DisplayableObject
Dim face1 As Face
face1 = tempFace
objects1(0) = face1
displayModification2.Apply(objects1)

Next

displayModification2.Dispose()

Else

End If

reportComponentChildren1(child, indent+1)

Next

End Sub

'**********************************************************
'**********************************************************
Private Function LoadComponent(ByVal theComponent As Component) As Boolean

Dim thePart As Part = theComponent.Prototype.OwningPart

Dim partName As String = ""
Dim refsetName As String = ""
Dim instanceName As String = ""
Dim origin(2) As Double
Dim csysMatrix(8) As Double
Dim transform(3, 3) As Double

Try
Else
End If
Return True
Catch ex As NullReferenceException
Try
ufs.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform)

Dim allReadOnly As Boolean = True
Else
End If

Next

Return True
Else
Return False
End If
Else
Return True
End If

Catch ex2 As NXException
else
lw.WriteLine("Error: " & partname & "   " & ex2.Message)
end if
Return False
End Try
Catch ex As NXException
'unexpected error
lw.WriteLine("error: " & ex.Message)
Return False
End Try

End Function

'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer

End Function
'**********************************************************

End Module 

With best regards
Michael

### RE: Change colors in an assembly

(OP)
That's exactly what I wanted.
Thank you Michael (@niedzviedz)!!!

Best Regards
Jonatas Fuckner

### RE: Change colors in an assembly

Remember that in this yournal, the colors are only changed in assembly. Not in parts. So if You wanna change them permanently, the code must be different.

With best regards
Michael

### RE: Change colors in an assembly

Hi niedzviedz

I test your journal on an assembly
and the journal run without errors
But when I Scan the assembly to see
what happened I can't see nothing.

### RE: Change colors in an assembly

Since at least the last 6 years there is a option in the "Edit Object Display" dialog to apply the changes to the "Owning part". ( It does exist in NX7.5 but not in NX6)
This will do exactly the same as the "Make displayed part etc etc click-click-click"
The trick is to select "Bodies" and not "Components".

1) Select the body ( Set selection filter to Solid Bodies)
2) Press Ctrl+J
3) select color and tick apply to owning part.
4) OK
Done.
A journal or Macro will not do this much quicker, or with much less clicks.

Regards,
Tomas

### RE: Change colors in an assembly

What are the color numbers You wanna change? Maybe there is a problem? I used 78 to change to 36 and 181 to change to 211. Please provide simply assembly with 2 elements.

With best regards
Michael

### RE: Change colors in an assembly

(OP)
Niedzwiedz

I have a friend who has color blindness and can not see some colors.
The idea is to paint the design according to the colors that it can differentiate and at the end of the project, in the assembly environment it will paint all the components with the colors that really should be.
But, do not paint in the assembly environment, but in "make display part".
Your Journal did just that. Now I should just change some command lines to change the colors according to our need.

Thank you again!

### RE: Change colors in an assembly

Few years ago, I want to change NX palette color to be the same color we have in Catia (Catai has RGB standard). So I created my CDF file. Each column has a representation of R, G and B value in percentage, when 0 is 0 and 255 is 1. So I create excel file to covert RGB value to NX. After that I created model with cube, and colored his faces with my new colors. Then I exported this file (stp) to power mill, so guys from CAM could check if values are the same as they are in Catia. What We have found out, was that there wasn't the same values. I also exported picture to paint, and it was confirmed - even if You customize your palette, the valueas didn't be the same as RGB You want. So I gave up, I only changed values for Background in drafting to black.

With best regards
Michael

### RE: Change colors in an assembly

The CDF is part specific; as long as you keep the prt file intact, the colors should show up as you specified (regardless of who opens the file). In your situation, exporting to STEP may have changed the colors; I'm not sure how colors are assigned upon export...

### RE: Change colors in an assembly

I reopend CDF file with notepad, and values was different than values I wrote. So I gave up :)

With best regards
Michael

### RE: Change colors in an assembly

2
Hold it,
Is the purpose of this thread to make things visible for your colorblind colleague ?

Then there might be a better solution .
From the documentation.:
"Override the color palette (for color blindness)
* Create a custom CDF file that meets your visual needs. ( See the thread Cowski linked to for possible cdf's)
* In your environment variable file, or windows environment variables, set UGII_OVERRIDE_CDF to the pathname for your custom CDF file."

This will then replace the colors in the part when the part is shown on this computer/ user but it WILL NOT change the part itself.
- The colors are only different when viewed on that computer.
Example :

( No macros, no edits, no extra work.)

Regards,
Tomas

#### 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.

#### Resources

A lot has changed since the 90s. You don't surf the Web using dial-up anymore, so why are you still using a legacy PLM solution that's blocking your ability to innovate? To develop and launch products today, you need a flexible, cloud-based PLM, not a solution that's stuck in the past. Download Now
White Paper - Using Virtualization for IVI and AUTOSAR Consolidation on an ECU
Current approaches used to tackle the complexities of a vehicleâ€™s electrical and electronics (E/E) architecture are both cost prohibitive and lacking in performance. Utilizing virtualization in automotive software architecture provides a better approach. This can be achieved by encapsulating different heterogeneous automotive platforms inside virtual machines running on the same hardware. Download Now
White Paper - The Criticality of the E/E Architecture
Modern vehicles are highly sophisticated systems incorporating electrical, electronic, software and mechanical components. Mechanical systems are giving way to advanced software and electronic devices, driving automakers to innovate and differentiate their vehicles via the electric and electronic (E/E) architecture. As the pace of change accelerates, automotive companies need to evolve their development processes to deliver and maximize the value of these architectures. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!