Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a sample way to change features faces colors

Status
Not open for further replies.

PSI-CAD

Computer
Feb 13, 2009
997
0
0
FR
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 ?


Regards
Didier Psaltopoulos
 
Replies continue below

Recommended for you

For now you'll have to select the faces which make up the feature, either individually or by region select.

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
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
 
Below is a journal that changes the colours for simple hole features only.

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
 
My only excuse is that I must be getting color blind. I thought I had it correct on my small test part. Below is the revised journal. Thanks also goes to cowski for suggesting the correction.

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
 
Hi Franck,

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
 
We have two lines of code which use name checking. These lines are:

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
 
I changed the following lines

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
 
Open/create a model that has a simple hole and a threaded hole, then run the journal below. If it opens a listing window, then keep the line as
Code:
If f.FeatureType = "SIMPLE HOLE" Then
and change "TROU FILETE" in
Code:
Dim holeexpstring As String = "TROU FILETE"
to the same French word(s) reported after "description:" that denote the hole is threaded. You don't need the entire phrase after "description:", just the French equivalent of "thread" or "threaded" that is used by NX.

Code:
Imports System
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

 
Following my call to GTAC, we found the answer. So find below a working program with UGII_LANG set to English or French

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
 
Status
Not open for further replies.
Back
Top