Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

change all parts translucency automatically

Status
Not open for further replies.

zhengzhou83

Mechanical
Oct 20, 2016
7
Hi,can anybody help me. I'm working on journal. I want to change all dispalyedparts translucency automatically.
Not ask for selecting body.
 
Replies continue below

Recommended for you

mathisudar2007 thanks for reply.
Can I have the details?
 
can you tell more, why, when, how ?

I assume that you know about the display state "See through all" ?

Regards,
Tomas
 
Sorry for not describing my issue clearly.

I'm looking for a journal that can change the displayed parts automatically.
just like the icon of Shaded ,the icon of Static Wireframe.

I found a journal that can change the translucency by selecting the parts one by one.
How can I modify the journal and make it to select all displayed parts automatically ,change the translucency value.

This is the journal I found.

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI


Module changeColorOfPreSelectedFaces_v2
Dim theSession As Session = Session.GetSession()
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager

Sub Main()

'' The selectFaces method takes an NXobject array by reference
Dim selectedObjectsArray() As NXObject
Selectbody(selectedObjectsArray)

'' Need to recast the face NXObjects to Displayable objects
Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
For i As Integer = 0 To selectedObjectsArray.Length - 1
faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
Next

Dim changeBodytransluency As DisplayModification = theSession.DisplayManager.NewDisplayModification()
With changeBodytransluency
.ApplyToAllFaces = true
' .NewColor = newColorCode
.NewTranslucency = 50
.Apply(faceArray)
.Dispose()
End With

End Sub


'' The following routine is from GTAC

' ----------------------------------------------
' sub to select faces
' ----------------------------------------------

Sub Selectbody(ByRef selectedObjects As NXObject())

Dim ui As UI = NXOpen.UI.GetUI

Dim message As String = "Select body"
Dim title As String = "Selection"

Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = False
Dim response As Selection.Response

Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific

Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_component_subtype
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

With selectionMask_array(1)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End with

response = ui.SelectionManager.SelectObjects(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObjects)

If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
Return
End If

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY

End Function
End Module


Thanks
 
Can you describe how do you do it
In NX interactive mode.

So I exactly understand it. (And maybe helping)
 
We still want to know why and if you have tried the DIFFERENT STYLES of the display state "See through all" ?
(
see-trough_tw1oxd.png


Regards,
Tomas
 
a984928,Thanks for you reply.
Dou you means how to excute the code?
You can do it by clicking the command Tools → Journal → Edit and paste the code ,play it.
 
Tomas,Thanks for remind me the commad " see through-all".
I just tried it.But I found when I excuted the commad, the original colors dispeared.
I don't want it happen.



 

I run your journal and on the selection dialog I choosed "Select All"
and all the assembly components are applied the translucency.

Is this is what you want OK if not please describe how you
perform this in NX interactive mode. (In real NX session not by journal
 
a984928,Thanks for you reply.

I want components can be selected antomaticaaly even if them can be seleced by " select all".

I don't know how to perform this in NX interactive mode.I have not NXopen Lisence.
 
I used some of your code and some code from this post


I hop this can helping (run journal in an opened part assembly No selection needed)


Option Strict Off

Imports System
Imports System.Collections

Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Assemblies

Module changeColorOfPreSelectedFaces_v3

Dim theSession As Session = Session.GetSession()

Sub Main()

Dim disPart As Part = theSession.Parts.Display
Dim i As Integer = 0
Dim faceArray(-1) As DisplayableObject
Dim allComp1 As ArrayList = New ArrayList

Dim root As Component = disPart.ComponentAssembly.RootComponent
If Not IsNothing(root) Then
getAllComponents2(root, allComp1)
Dim dispobj As DisplayableObject = Nothing
Dim cnt1 As Integer = allComp1.Count
Dim objectArray1(cnt1 - 1) As DisplayableObject
For i = 0 To cnt1 - 1
dispobj = DirectCast(allComp1(i), DisplayableObject)
ReDim Preserve faceArray(i)
faceArray(i) = dispobj
Next
End If

Dim changeBodytransluency As DisplayModification = _
theSession.DisplayManager.NewDisplayModification()
With changeBodytransluency
.ApplyToAllFaces = true
' .NewColor = newColorCode
.NewTranslucency = 75
.Apply(faceArray)
.Dispose()
End With

End Sub

Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
Dim child As Component = Nothing
Dim space As String = Nothing
For Each child In comp.GetChildren()
allComp.Add(child)
getAllComponents2(child, allComp)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function

End Module
 

Changed to run on a peece part or on an assembly part



Option Strict Off

Imports System
Imports System.Collections

Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Assemblies

Module changeColorOfPreSelectedFaces_v4

Dim theSession As Session = Session.GetSession()

Sub Main()

Dim disPart As Part = theSession.Parts.Display
Dim workPart As Part = theSession.Parts.Work
Dim i As Integer = 0
Dim faceArray(-1) As DisplayableObject
Dim allComp1 As ArrayList = New ArrayList
Dim dispobj As DisplayableObject = Nothing

Dim root As Component = disPart.ComponentAssembly.RootComponent
If Not IsNothing(root) Then
getAllComponents2(root, allComp1)
Dim cnt1 As Integer = allComp1.Count
For i = 0 To cnt1 - 1
dispobj = DirectCast(allComp1(i), DisplayableObject)
ReDim Preserve faceArray(i)
faceArray(i) = dispobj
Next
Else
i = 0
For Each objBody As Body In workPart.Bodies
ReDim Preserve faceArray(i)
faceArray(i) = CType(objBody, DisplayableObject)
i = i + 1
Next
End If

Dim changeBodytransluency As DisplayModification = _
theSession.DisplayManager.NewDisplayModification()
With changeBodytransluency
.ApplyToAllFaces = true
' .NewColor = newColorCode
.NewTranslucency = 75
.Apply(faceArray)
.Dispose()
End With

End Sub

Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
Dim child As Component = Nothing
Dim space As String = Nothing
For Each child In comp.GetChildren()
allComp.Add(child)
getAllComponents2(child, allComp)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function

End Module
 

Final correcting


Option Strict Off

Imports System
Imports System.Collections

Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Assemblies

Module changeColorOfPreSelectedFaces_v5

Dim theSession As Session = Session.GetSession()

Sub Main()

Dim disPart As Part = theSession.Parts.Display
Dim workPart As Part = theSession.Parts.Work
Dim i As Integer = 0
Dim faceArray(-1) As DisplayableObject
Dim allComp1 As ArrayList = New ArrayList
Dim dispobj As DisplayableObject = Nothing
Dim root As Component = disPart.ComponentAssembly.RootComponent
Dim markId1 As Session.UndoMarkId

markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Change Transluency")

Dim objBody As Body() = workPart.Bodies.ToArray()

If objBody.Length > 0 Then
For i = 0 To objBody.Length - 1
ReDim Preserve faceArray(i)
faceArray(i) = CType(objBody(i), DisplayableObject)
Next
Dim changeBodytransluency As DisplayModification = _
theSession.DisplayManager.NewDisplayModification()
With changeBodytransluency
.ApplyToAllFaces = true
' .NewColor = newColorCode
.NewTranslucency = 75
.Apply(faceArray)
.Dispose()
End With
End If

If Not IsNothing(root) Then
getAllComponents2(root, allComp1)
Dim cnt1 As Integer = allComp1.Count
For i = 0 To cnt1 - 1
dispobj = DirectCast(allComp1(i), DisplayableObject)
ReDim Preserve faceArray(i)
faceArray(i) = dispobj
Next
Dim changeBodytransluency As DisplayModification = _
theSession.DisplayManager.NewDisplayModification()
With changeBodytransluency
.ApplyToAllFaces = true
' .NewColor = newColorCode
.NewTranslucency = 75
.Apply(faceArray)
.Dispose()
End With
End If

End Sub

Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
Dim child As Component = Nothing
Dim space As String = Nothing
For Each child In comp.GetChildren()
allComp.Add(child)
getAllComponents2(child, allComp)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function

End Module
 
a984928 Thanks for your help.
The code works great.

I'm just beginning with journals.I don't know how to start.
I think it's a good place for studying.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor