×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

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

Students Click Here

Jobs

Looking for a sample way to change features faces colors

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 ?


Regards
Didier Psaltopoulos
http://www.psi-cad.com

RE: Looking for a sample way to change features faces colors

Are you looking for a way to do it automatically? Manual is pretty easy with selection filter.

RE: Looking for a sample way to change features faces colors

(OP)
There is no feature selection filter in Edit Object Display
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

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

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

RE: Looking for a sample way to change features faces colors

(OP)
Hi Franck

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

(OP)
Hi Franck,

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

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

RE: Looking for a sample way to change features faces colors

(OP)
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
http://www.psi-cad.com

RE: Looking for a sample way to change features faces colors

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
 

RE: Looking for a sample way to change features faces colors

(OP)
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
http://www.psi-cad.com

RE: Looking for a sample way to change features faces colors

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

www.nxjournaling.com

RE: Looking for a sample way to change features faces colors

(OP)
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
http://www.psi-cad.com

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.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources