Change colors in an assembly
Change colors in an assembly
(OP)
How to change specific colors of models in an assembly quickly in NX?
Would you like to open each component with macro, change the color and return to the main assembly?
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
Change colors in an assembly
|
Change colors in an assemblyChange colors in an assembly(OP)
How to change specific colors of models in an assembly quickly in NX? Would you like to open each component with macro, change the color and return to the main assembly? Red Flag SubmittedThank you for helping keep Eng-Tips Forums free from inappropriate posts. Reply To This ThreadPosting in the Eng-Tips forums is a member-only feature.Click Here to join Eng-Tips and talk with other members! |
ResourcesThe world has changed considerably since the 1980s, when CAD first started displacing drafting tables. Download Now
Prototyping has always been a critical part of product development. Download Now
As the cloud is increasingly adopted for product development, questions remain as to just how cloud software tools compare to on-premise solutions. Download Now
Engineering-centric businesses face a number of challenges today, but unmanageable design and change processes don’t need to be counted among them. Download Now
|
RE: Change colors in an assembly
RE: Change colors in an assembly
Can you open each component automatically and run a macro to replace colors?
RE: Change colors in an assembly
choose make work part
change the color
Right click next part
choose make work part
change the color
...
RE: Change colors in an assembly
you can simply color it in the assembly.
RE: Change colors in an assembly
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
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
RE: Change colors in an assembly
With best regards
Michael
RE: Change colors in an assembly
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 If LoadComponent(child) Then Else 'component could not be loaded 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) If LoadComponent(child) Then 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 theFaces1.Add(tempFace) else if tempFace.Color = 181 Then theFaces2.Add(tempFace) 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 'component could not be loaded End If reportComponentChildren1(child, indent+1) Next End Sub '********************************************************** ' FUNCTION TO LOAD COMPONENTS '********************************************************** 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 If thePart.IsFullyLoaded Then 'component is fully loaded Else 'component is partially loaded End If Return True Catch ex As NullReferenceException 'component is not loaded Try ufs.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform) Dim theLoadStatus As PartLoadStatus theSession.Parts.Open(partName, theLoadStatus) If theLoadStatus.NumberUnloadedParts > 0 Then Dim allReadOnly As Boolean = True For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1 If theLoadStatus.GetStatus(i) = 641058 Then 'read-only warning, file loaded ok Else '641044: file not found lw.WriteLine("File not found") allReadOnly = False End If Next If allReadOnly Then Return True Else 'warnings other than read-only... Return False End If Else Return True End If Catch ex2 As NXException if ex2.message = "File not found" then lw.WriteLine("Error: " & partname & " " & "File not found") 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 Return Session.LibraryUnloadOption.Immediately End Function '********************************************************** End ModuleWith best regards
Michael
RE: Change colors in an assembly
Thank you Michael (@niedzviedz)!!!
Best Regards
Jonatas Fuckner
RE: Change colors in an assembly
With best regards
Michael
RE: Change colors in an assembly
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
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
With best regards
Michael
RE: Change colors in an assembly
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
Just as curiosity. I was able to change colors by .CFD, but it was not what I wanted.
RE: Change colors in an assembly
thread561-244752: UG color definition file
www.nxjournaling.com
RE: Change colors in an assembly
With best regards
Michael
RE: Change colors in an assembly
www.nxjournaling.com
RE: Change colors in an assembly
With best regards
Michael
RE: Change colors in an assembly
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