Getting the translucency property of a body

Hello, has somebody an idea how I can get the translucency property of a body?
I have tried several code, but it was not working. I want to have something like:
> selecting a body
> asking if the body translucency is enabled
> decide to enable/disable the translucency

Thanks!

Below is code (NX 8.5) that will check if translucency is enabled; if it is it will allow you to select a body, report the translucency, and set the translucency to 50%.





Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim theUi As UI = UI.GetUI
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "NXJ body translucency"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim globalTranslucency As Boolean = theUi.VisualizationVisualPreferences.Translucency
lw.WriteLine("Global translucency enabled: " & globalTranslucency.ToString)

If Not globalTranslucency Then
'no bodies are translucent
Return
End If

Dim theBody As Body
If SelectBody("select a body", theBody) = Selection.Response.Cancel Then
'user pressed cancel
Return
End If

Dim percentTranslucent As Integer
theUfSession.Obj.AskTranslucency(theBody.Tag, percentTranslucent)

lw.WriteLine("current translucency value: " & percentTranslucent.ToString & "%")
lw.WriteLine("setting translucency to: 50%")

Dim displayModification1 As DisplayModification = theSession.DisplayManager.NewDisplayModification()

Dim objects1(0) As DisplayableObject
objects1(0) = theBody

displayModification1.NewTranslucency = 50
displayModification1.Apply(objects1)

displayModification1.Dispose()

lw.Close()

End Sub

Function SelectBody(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a body"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

End Module

Thanks for the code! This will report if the work part contains a body which
is translucence, correct? Is it also possible to report if the selected body is
translucence (for instance if there are more bodies and I want to differentiate them)?

The code as written will first check to see if translucency is enabled in the current session; it will report the status (true or false) to the listing window. If translucency is not enabled (the journal reports false), the journal will exit since none of the bodies in the file will appear translucent.

If translucency is enabled, it will then allow you to select a solid body, report the current translucency (as a percent) of the body, and finally set the translucency of the selected body to 50%. With the techniques illustrated in this journal, you should be able to query and set the translucency of any body in your file.

yes you're right, it was my mistake. I have missed the part of the code that I was looking for.
Everything is working well! Thanks for your help :)