Showing results for 
Search instead for 
Did you mean: 

Change color of all Objects in a Layer

Hello all,


I am working on NXOpen c++. Had a requirement to change color of an imported stl file. What I did is imported in a particular layer. Now thinking to change its color automatically through c++ code. If I can change all objects color in one layer, I can acheive it. Can anyone tell me how to do it. ..?



Thanks in advance


Re: Change color of all Objects in a Layer

Siemens Phenom Siemens Phenom
Siemens Phenom

You can use UF_LAYER_cycle_by_layer() to cycle all of the objects on a particular layer. Set the color for each object using UF_OBJ_set_color().


Search the Solution Center for "UF_LAYER_cycle_by_layer" and "UF_OBJ_set_color" to see examples.

Re: Change color of all Objects in a Layer

Hi Jim,


Can I do the same process using NXOpen c++ code. Because we are not supporting Ufunc any more.


Thanks in advance



Re: Change color of all Objects in a Layer

Valued Contributor
Valued Contributor

Hello @BhargavaBoddeti


I wrote the code in VB.Net. Hope you can understand and change it to C++

Here I run a loop through all the layer and collect all the objects, then assign color to the objects.



Dim displayModification1 As DisplayModification
Dim objects1(0) As DisplayableObject

Dim allObjects As NXObject()
For i As Integer = 1 To 256

allObjects = workPart.Layers.GetAllObjectsOnLayer(i)
For Each someObject As DisplayableObject In allObjects



displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = True

displayModification1.ApplyToOwningParts = False

displayModification1.NewColor = 181

displayModification1.NewWidth = DisplayableObject.ObjectWidth.Two
objects1(0) = someObject



Catch ex As Exception
Exit Try
End Try



Hope it helps.