Viewing 3 posts - 1 through 3 (of 3 total)
- AuthorPosts
- May 28, 2022 at 8:38 am #28213Yang YangParticipant
Hello, could you kindly give me an example of processing multiple selections in the macro? For example, suppose “abc” and “xyz” are selected in the document, and I want to change their text to “[abc]” and “[xyz]”, respectively. Thanks!
May 28, 2022 at 9:30 am #28214Yutaka EmuraKeymasterIf the Auto-Complete Brackets/Quotation Marks option is set, you can simply type [.
However, I know you want to write a macro to process multiple selection scenarios. Here is an example:
sInsertBefore = "["; sInsertAfter = "]"; var axT = []; var ayT = []; var axB = []; var ayB = []; Redraw = false; CombineHistory = true; nCount = document.selection.Count; // retrieves the number of selections for( i = 1; i <= nCount; ++i ) { // loop through multiple selections x = document.selection.GetTopPointX( eePosLogical, i ); // retrieve x of the left side of each selection axT.push( x ); y = document.selection.GetTopPointY( eePosLogical, i ); // retrieve y of the left side of each selection ayT.push( y ); x = document.selection.GetBottomPointX( eePosLogical, i ); // retrieve x of the right side of each selection axB.push( x ); y = document.selection.GetBottomPointY( eePosLogical, i ); // retrieve y of the right side of each selection ayB.push( y ); } for( i = nCount - 1; i >= 0; --i ) { document.selection.SetActivePoint( eePosLogical, axB[i], ayB[i] ); // set the cursor to the right side of each selection document.selection.Text = sInsertAfter; // insert ']' document.selection.SetActivePoint( eePosLogical, axT[i], ayT[i] ); // set the cursor to the left side of each selection document.selection.Text = sInsertBefore; // insert '[' }
May 28, 2022 at 9:39 am #28215Yang YangParticipantThank you very much! More steps that I expected, honestly.
- AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.