Imports System Imports System.Reflection Imports NXOpen Imports NXOpen.UF Imports NXOpen.Selection Module ReverseText Dim sess As NXOpen.Session Dim ufs As UFSession Dim wp As NXOpen.Part Dim nxui As NXOpen.UI Sub Main() #If PLATFORM = "x86" Then sess = frm_debug.sess ufs = frm_debug.ufs nxui = frm_debug.nxui #Else sess = Session.GetSession() ufs = UFSession.GetUFSession nxui = UI.GetUI #End If wp = sess.Parts.Work Dim udm As Session.UndoMarkId = sess.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Reverse Note") Dim note As NXOpen.Annotations.Note Dim feat As Features.Feature Dim ot, st As Integer Dim selobjs() As NXObject Do selobjs = SelectText("Select Notes to reverse", "Notes") If selobjs Is Nothing OrElse selobjs.Length = 0 Then Exit Do For i As Integer = 0 To selobjs.Length - 1 ufs.Obj.AskTypeAndSubtype(selobjs(i).Tag, ot, st) If ot = UFConstants.UF_drafting_entity_type AndAlso st = UFConstants.UF_draft_note_subtype Then note = CType(selobjs(i), Annotations.Note) ReverseDraftingNote(note) ElseIf ot = UFConstants.UF_feature_type AndAlso st = UFConstants.UF_feature_subtype Then feat = CType(selobjs(i), Features.Feature) If TypeOf feat Is Features.Text Then ReverseTextFeature(CType(feat, Features.Text)) End If End If Next Loop End Sub Private Sub ReverseDraftingNote(ByVal note As Annotations.Note) Dim dnbld As NXOpen.Annotations.DraftingNoteBuilder = wp.Annotations.CreateDraftingNoteBuilder(note) Dim txt() As String = dnbld.Text.GetEditorText Dim rtxt(txt.Length - 1) As String Dim chars() As Char For i As Integer = 0 To txt.Length - 1 chars = txt(i).ToCharArray Array.Reverse(chars) rtxt(i) = String.Join("", chars) Next dnbld.Text.SetEditorText(rtxt) Dim nxo As NXObject = dnbld.Commit() dnbld.Destroy() End Sub Private Sub ReverseTextFeature(ByVal txtfeat As Features.Text) Dim txtbld As Features.TextBuilder = wp.Features.CreateTextBuilder(txtfeat) Dim txt As String = txtbld.TextString Dim chars() As Char = txt.ToCharArray Array.Reverse(chars) Dim rtxt As String = String.Join("", chars) txtbld.TextString = rtxt Dim nxo As NXOpen.NXObject = txtbld.Commit() txtbld.Destroy() sess.UpdateManager.DoUpdate(sess.NewestVisibleUndoMark) End Sub Private Function SelectText(ByVal Message As String, ByVal Title As String) As NXObject() Dim scope As SelectionScope = SelectionScope.AnyInAssembly Dim action As SelectionAction = SelectionAction.ClearAndEnableSpecific Dim keep_hl As Boolean = False Dim appname As String = sess.ApplicationName Dim mask() As MaskTriple If appname = "UG_APP_DRAFTING" Then mask = {New MaskTriple(UFConstants.UF_drafting_entity_type, UFConstants.UF_draft_note_subtype, -1)} ElseIf appname = "UG_APP_MODELING" OrElse appname = "UG_APP_STUDIO" Then mask = {New MaskTriple(UFConstants.UF_feature_type, UFConstants.UF_feature_subtype, -1)} Else mask = {New MaskTriple(UFConstants.UF_note_type, UFConstants.UF_general_note_subtype, -1), _ New MaskTriple(UFConstants.UF_drafting_entity_type, UFConstants.UF_draft_note_subtype, -1), _ New MaskTriple(UFConstants.UF_feature_type, UFConstants.UF_feature_subtype, -1)} End If Dim obj(-1) As TaggedObject Dim resp As Response = nxui.SelectionManager.SelectTaggedObjects(Message, Title, scope, action, False, keep_hl, mask, obj) Return Array.ConvertAll(obj, AddressOf ConvTobj2Nxobj) End Function Private Function ConvTobj2Nxobj(ByVal tobj As TaggedObject) As NXObject Return CType(tobj, NXObject) End Function End Module