<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<!--
Copyright (c) 2006 UGS Corp.

All Rights Reserved.

This software and related documentation are proprietary to UGS Corp.
-->
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Removing Selection Stickiness</title>
      <script language="javaScript">
        abridged="false";
        displayConditions=new Array();
      </script>
      <link type="text/css" href="../css/main_styles.css" rel="stylesheet">
   </head>
   <body class="bodydocs" onload="top.pageLoader()" bgcolor="#FFFFFF">
      <div class="title_topic2" id="xps10_pagetitle">Removing Selection Stickiness</div>
      <hr noshade="true">
      <div class="title_division">Introduction</div>
      <p class="para_division">By design, journals record the exact events, including the selection events, that a user performs during the recording process. What gets recorded in a journal, however, is not the &ldquo;intent&rdquo; of a selection event or the series of UI events the user performed to produce the final result. Instead, the journal records the actual name of the selected entity and specific function invoked against that entity. We refer to this as &ldquo;Selection Stickiness.&rdquo;</p>
      <p class="para_division">For example, if a user is recording the hiding of all the datums in a view, what actually gets recorded is the exact name of each datum plane and the final method to hide the given entities. Strictly replaying this journal causes the execution of the exact action on the specific object(s) chosen. Selection Stickiness can sometimes cause a replay failure if the journal is executed out of context of its original recorded events (i.e. if I replayed the hide datums journal in a different part file I&rsquo;d get an error indicating that no datums with the specific name(s) exist). However, you can modify a journal to allow for replay on any selected object by simply replacing each FindObject call in with a call to a generic selection dialog.</p>
      <p class="para_division">Here&rsquo;s one example of how to modify a journal to remove its selection stickiness. A journal was recorded that creates a block and then adds a hole to the center of a given face. To place the hole, a user must first select a face on the block. The following code is what gets recorded.</p><pre class="indent">Dim iSurface1 As ISurface = CType(features_Feature1.FindObject(&quot;FACE 2&quot;), ISurface)</pre><p class="para_division">Notice the FindObject call and the embedded string, FACE 2. These are code clues that indicate a specific feature is identified and recorded in the journal. To make the journal replay against any face, you must modify the journal with a call to a new function that prompts the user to select a face. The following demonstrates one such function. </p><pre class="indent">Public Function Selectface(ByRef selectedObject) As NXObject

Dim ui As UI = ui.GetUI
Dim message As String = &quot;Select face&quot;
Dim title As String = &quot;Selection&quot;
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
     	Dim keepHighlighted As Boolean = True
     	Dim includeFeatures As Boolean = True
     	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_face_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With

   	Dim cursor As Point3d

   	response = ui.SelectionManager.SelectObject(message, title, scope, _
                                       selectionAction, includeFeatures, _
                                       keepHighlighted, selectionMask_array, _
                                       selectedObject, cursor)

        If response = Selection.Response.Cancel 
  Or response = Selection.Response.Back 
 Then
            Return Nothing
        End If
	End Function</pre><div class="title_division">Adding a Selection Function to a Journal</div>
      <p class="para_division">You can append this method directly to the end of a journal between the End Sub for the Sub Main routine and the End Module call, as shown below.</p><pre class="indent">Module NXJournal
	Sub Main
	' Body of Journal

	End Sub

	' **** Added Code ****
    		Public Function Selectface(ByRef selectedObject) As NXObject

	' Body of function

	End Function

    	End Module</pre><div class="title_division">Calling the New Selection Subroutine</div>
      <p class="para_division">Now, modify the journal body to call the function in place of the actual face on the block.</p>
      <p class="para_division">Because we are referencing a .NET&ndash;wrapped User Function call in the body of our new method (UFConstants.UF_face_type), we must add a reference to the NXOpen.UF namespace.</p><pre class="indent">Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF  'Note the added Imports reference

Module NXJournal
Sub Main
' Body of Journal
'Dim iSurface1 As ISurface = Ctype(features_Feature1.FindObject(&quot;FACE 2&quot;), Isurface)

Dim obj As NXObject
        Selectface(obj)
        If obj Is Nothing Then
            Return
        End If
        Dim face1 As Face = Ctype(obj, Face)
Dim iSurface1 As Isurface = Ctype(face1, Isurface)
' rest of journal</pre><p class="para_division">Now when you replay the journal, it prompts the user to select a face on which to place the hole.</p>
   </body>
</html>