DeleteCommands script

Build 1501 on 14/Nov/2017  This topic last edited on: 9/May/2012, at 13:02

DeleteCommands: deletes all the markup commands from the current text. If bSaveParaStyles is true the paragraph style commands are preserved. If bSaveTextStyle is true the text style commands and their corresponding closing >res< are preserved. Example: DeleteCommands True,True deletes all the markup but paragraph styles and text styles. Note: this function require specific constants. See Constants for TxtPosDesc functions.

Sub DeleteCommands(bSaveParaStyles,bSaveTextSyles)

 

  ' Create a cursor at the beginning of the text

  ' The cursor is always in 'source mode with markup' mode

  ' so that the function will work in the same way

  ' regardless of the current editing mode

 

  dim objCur = Text.GetCursor(modeSrcOn,cposBegin,False)

 

  ' Main loop through all the text

 

  Do

    dim objDesc = objCur.Desc

    If (objDesc.GetType = tptStartCmd Or objDesc.GetType = tptEndCmd) And (Not bSaveParaStyles Or objDesc.GetCmdType <> ctParaStyle) And (Not bSaveTextSyles Or (objDesc.GetCmdType <> ctTextStyleBegin And objDesc.GetCmdType <> ctTextStyleEnd)) Then

 

      ' objCur is at the start of a command: select and delete it

 

      dim objTo = objCur.Duplicate

      objTo.Move(1)

      Ted.DelRange objCur,objTo

      dim objTo = Nothing

    End If

    dim objDesc = Nothing

 

    ' Loop until the end of the text

 

  Loop While objCur.Move(1) = 0

End Sub

 

See also DeleteNotes procedure.