Looking for a sample way to change features faces colors
Looking for a sample way to change features faces colors
(OP)
I am looking for a sample way to change features faces colors.
For example: faces from sample hole to be blue and faces from threaded hole to be yellow.
I know that it's not possible with NX8. Is it possible with a sample vb programm ?
For example: faces from sample hole to be blue and faces from threaded hole to be yellow.
I know that it's not possible with NX8. Is it possible with a sample vb programm ?
Regards
Didier Psaltopoulos
http://www.psi-cad.com





RE: Looking for a sample way to change features faces colors
RE: Looking for a sample way to change features faces colors
Which kind of selection filter do you propose ?
Regards
Didier Psaltopoulos
http://www.psi-cad.com
RE: Looking for a sample way to change features faces colors
In the next version of NX (the one after NX 8.0) there will be an explicit option which will allow you to select the feature itself and assign it a color.
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
http://www.siemens.com/plm
UG/NX Museum: http://www.plmworld.org/p/cm/ld/fid=209
To an Engineer, the glass is twice as big as it needs to be.
RE: Looking for a sample way to change features faces colors
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module HoleColours
Sub Main()
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim dp As Part = s.Parts.Work
Dim expstring As String = Nothing
Dim index2 As Integer = -1
Dim exps() As Expression
Dim ent() As NXObject
Dim holewiththread As Boolean = False
Dim holeexpstring As String = "thread"
Dim hole As BodyFeature
Dim faces() As Face
Dim nFaces As Integer = 0
Dim obj(-1) As DisplayableObject
Dim displayModification1 As DisplayModification
Dim featcoll As FeatureCollection = dp.Features
For Each f As Feature In featcoll
If f.FeatureType = "SIMPLE HOLE" Then
ent = f.GetEntities()
holewiththread = False
exps = f.GetExpressions()
For Each e As Expression In exps
expstring = e.Equation.ToString
index2 = expstring.IndexOf(holeexpstring)
If index2 > 0 Then
holewiththread = True
End If
Next
If holewiththread = True Then
hole = DirectCast(f, BodyFeature)
faces = hole.GetFaces()
nFaces = faces.Length
ReDim obj(nFaces - 1)
For i As Integer = 0 To nFaces - 1
obj(i) = faces(i)
Next
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = False
displayModification1.NewColor = 6
displayModification1.Apply(obj)
Else 'holewiththread is false
hole = DirectCast(f, BodyFeature)
faces = hole.GetFaces()
nFaces = faces.Length
ReDim obj(nFaces - 1)
For i As Integer = 0 To nFaces - 1
obj(i) = faces(i)
Next
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = False
displayModification1.NewColor = 211
displayModification1.Apply(obj)
End If
End If
Next
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
Hope this helps.
Frank Swinkels
RE: Looking for a sample way to change features faces colors
Thanks a lot.
Very good job, but I need more. Is it easy for you to differentiate sample hole and threaded hole with another color ?
Thanks in advance
Regards
Didier Psaltopoulos
http://www.psi-cad.com
RE: Looking for a sample way to change features faces colors
I apologize. In fact It seems that you understand my request, but the programm set the same color on simple hole or threaded hole. did you check it ?
TIA
Regards
Didier Psaltopoulos
http://www.psi-cad.com
RE: Looking for a sample way to change features faces colors
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module HoleColours
Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim dp As Part = s.Parts.Work
Dim expstring As String = Nothing
Dim index2 As Integer = -1
Dim exps() As Expression
Dim holewiththread As Boolean = False
Dim holeexpstring As String = "Threaded"
Dim hole As BodyFeature
Dim faces() As Face
Dim nFaces As Integer = 0
Dim obj(-1) As DisplayableObject
Dim displayModification1 As DisplayModification
Dim featcoll As FeatureCollection = dp.Features
For Each f As Feature In featcoll
If f.FeatureType = "SIMPLE HOLE" Then
holewiththread = False
exps = f.GetExpressions()
index2 = exps(0).Description.IndexOf(holeexpstring)
If index2 > 0 Then
holewiththread = True
End If
If holewiththread = True Then
hole = DirectCast(f, BodyFeature)
faces = hole.GetFaces()
nFaces = faces.Length
ReDim obj(nFaces - 1)
For i As Integer = 0 To nFaces - 1
obj(i) = faces(i)
Next
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = False
displayModification1.NewColor = 6
displayModification1.Apply(obj)
Else 'holewiththread is false
hole = DirectCast(f, BodyFeature)
faces = hole.GetFaces()
nFaces = faces.Length
ReDim obj(nFaces - 1)
For i As Integer = 0 To nFaces - 1
obj(i) = faces(i)
Next
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = False
displayModification1.NewColor = 211
displayModification1.Apply(obj)
End If
End If
Next
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
Regards
Frank Swinkels
RE: Looking for a sample way to change features faces colors
I found that the programm doesn't give the good result if I use NX with french menu !!!
So the workaround for me is to use NX with English Menu, But did you have any idea ?
TIA
Regards
Didier Psaltopoulos
http://www.psi-cad.com
RE: Looking for a sample way to change features faces colors
If f.FeatureType = "SIMPLE HOLE" Then
and
Dim holeexpstring As String = "Threaded"
index2 = exps(0).Description.IndexOf(holeexpstring)
Either or both could be a French equivalent which you would need to be changed as appropriate.
Regards
Frank Swinkels
RE: Looking for a sample way to change features faces colors
Dim holeexpstring As String = "TROU FILETE"
Dim hole As BodyFeature
then
If f.FeatureType = "PERçAGE SIMPLE" Then
But it doesn't work with NX in French
So I will open a call and let you informed
Regards
Didier Psaltopoulos
http://www.psi-cad.com
RE: Looking for a sample way to change features faces colors
CODE
CODE
CODE
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module HoleColours
Sub Main()
Dim s As Session = Session.GetSession()
Dim dp As Part = s.Parts.Work
Dim exps() As Expression
Dim featcoll As FeatureCollection = dp.Features
Dim lw As ListingWindow = s.ListingWindow
lw.Open()
For Each f As Feature In featcoll
If f.FeatureType = "SIMPLE HOLE" Then
exps = f.GetExpressions()
For Each e As Expression In exps
lw.WriteLine("description: " & e.Description)
Next
End If
Next
lw.Close
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
www.nxjournaling.com
RE: Looking for a sample way to change features faces colors
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module HoleColours
Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim dp As Part = s.Parts.Work
Dim expstring As String = Nothing
Dim index2 As Integer = -1
Dim exps() As Expression
Dim holewiththread As Boolean = False
Dim holeexpstring As String = "Threaded"
Dim hole As BodyFeature
Dim faces() As Face
Dim nFaces As Integer = 0
Dim obj(-1) As DisplayableObject
Dim displayModification1 As DisplayModification
Dim featcoll As FeatureCollection = dp.Features
Dim langUsed As String = ""
For Each f As Feature In featcoll
ufs.UF.TranslateVariable("UGII_LANG", langUsed)
If langUsed.Contains("French") Then
holeexpstring = "Trou filet"
End If
If f.FeatureType = "SIMPLE HOLE" Then
holewiththread = False
exps = f.GetExpressions()
index2 = exps(0).Description.IndexOf(holeexpstring)
If index2 > 0 Then
holewiththread = True
End If
If holewiththread = True Then
hole = DirectCast(f, BodyFeature)
faces = hole.GetFaces()
nFaces = faces.Length
ReDim obj(nFaces - 1)
For i As Integer = 0 To nFaces - 1
obj(i) = faces(i)
Next
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = False
displayModification1.NewColor = 78
displayModification1.Apply(obj)
Else 'holewiththread is false
hole = DirectCast(f, BodyFeature)
faces = hole.GetFaces()
nFaces = faces.Length
ReDim obj(nFaces - 1)
For i As Integer = 0 To nFaces - 1
obj(i) = faces(i)
Next
displayModification1 = s.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = False
displayModification1.NewColor = 211
displayModification1.Apply(obj)
End If
End If
Next
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
Regards
Didier Psaltopoulos
http://www.psi-cad.com