Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Change the transparency of the selected part using a journal

Status
Not open for further replies.

neshom

Mechanical
Feb 7, 2016
43
I am new user and this is my first journal.
I'd like to have a button to set the translucency of the selected part to 70%. I have recorded the following journal, but it basically does it only for the part that was selected during the record procedure:

Code:
using System;
using NXOpen;
 
public class NXJournal
{
  public static void Main(string[] args)
  {
    NXOpen.Session theSession = NXOpen.Session.GetSession();
    NXOpen.Part workPart = theSession.Parts.Work;
    NXOpen.Part displayPart = theSession.Parts.Display;
    // ----------------------------------------------
    //   Menu: Edit->Object Display...
    // ----------------------------------------------
    NXOpen.Session.UndoMarkId markId1;
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Object Display");
 
    NXOpen.DisplayModification displayModification1;
    displayModification1 = theSession.DisplayManager.NewDisplayModification();
 
    displayModification1.ApplyToAllFaces = true;
 
    displayModification1.ApplyToOwningParts = false;
 
    displayModification1.NewTranslucency = 79;
 
    NXOpen.DisplayableObject[] objects1 = new NXOpen.DisplayableObject[1];
    NXOpen.Assemblies.Component component1 = (NXOpen.Assemblies.Component)workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT model3 1");
    objects1[0] = component1;
    displayModification1.Apply(objects1);
 
    displayModification1.Dispose();
    // ----------------------------------------------
    //   Menu: Tools->Journal->Stop Recording
    // ----------------------------------------------
 
  }
  public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}

Could you please guide me on how I can change it so that it validates the variable component1 to the selected part instead of the part named "model3"?

Thanks in advance.
 
Replies continue below

Recommended for you

You need the vb code to act on a selected component, instead of the one recorded in your journal.
I suggest you get one of our samples, and adapt it.
If you search our knowledge base for Sample NX Open .NET Visual Basic program selected component you will see several that would make a good starting point.

Mark Rief
NX CAM Customer Success
Siemens PLM Software
 
Try this code:

Code:
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 = 40
            .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


With best regards
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor