macro to delete "tracks" containing certain characters

Get help using and writing Nisus Writer Pro macros.
Post Reply
Nobumi Iyanaga
Posts: 158
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

macro to delete "tracks" containing certain characters

Post by Nobumi Iyanaga »

Hello,

I am editing a file containing an enormous number of "track changes -- and I notice that NWP is very weak to deal with this kind of documents. If I open and edit it in MS Word, there are almost no problems, but in NWP, each change takes minutes and each time, the rainbow wheel is turning indefinitly... I really would like to request a better treatment of this kind of documents...

Anyway, this enormous number of "track changes" is the result of several "change all" for formatting. The editor who made these changes made "change all" to change all the spaces after "«" and before "»" into "non-breaking spaces". This is correct in terms of editing process, but leaving all these changes in "track changes" seems to me a rather silly thing...

Anyway, what I would love to have is a macro that would select every instance of "track change" which contains a "non-breaking space". Is such a macro possible?

Thank you very much in advance to whoever would be so kind as to write for me this macro...

Best regards,

Nobumi
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: macro to delete "tracks" containing certain characters

Post by martin »

Hi Nobumi,

Here's a macro that finds text in tracked changes. It will search all tracked deletions and replacements in your document, selecting those whose original (ie: deleted) text matches the search text. You can then either accept or reject them all.

As an aside, are you able to send us your document privately, so I can see the slowdown firsthand? I'd like to see if there's anything we can do to help Nisus Writer behave more smoothly. Thanks!
Nobumi Iyanaga
Posts: 158
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

Re: macro to delete "tracks" containing certain characters

Post by Nobumi Iyanaga »

Hello Martin,

Thank you for your reply and your excellent macro!

You wrote:
Here's a macro that finds text in tracked changes. It will search all tracked deletions and replacements in your document, selecting those whose original (ie: deleted) text matches the search text. You can then either accept or reject them all.
The macro worked very well. I could delete (that is, accept) more than 300 changes. -- But there are much more of the same kind, in which no traces of deleted text seem to be left; there are only the added elements which are indicated in the side bar...

It seems that NWP macro language lacks the "

Code: Select all

.addedTextContent"
property among the TrackedChange Object Properties. But going through the "

Code: Select all

.markedText"
or "

Code: Select all

.markedTextRange
"..., it seems possible to get the values of the added text?? The macro would be much more complicated, but is it possible to write such a macro, please...?

Thank you very much in advance!

You wrote also:
As an aside, are you able to send us your document privately, so I can see the slowdown firsthand? I'd like to see if there's anything we can do to help Nisus Writer behave more smoothly. Thanks!
Yes, surely. I will send you the file in a feedback. Thank you in advance for examining it, and see how it would be possible to improve NWP's behavior.

Best regard,

Nobumi Iyanaga
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: macro to delete "tracks" containing certain characters

Post by martin »

I'm very happy to help!
Nobumi Iyanaga wrote:The macro worked very well. I could delete (that is, accept) more than 300 changes. -- But there are much more of the same kind, in which no traces of deleted text seem to be left; there are only the added elements which are indicated in the side bar...
Ah yes, I should have anticipated this need. Here's an amended macro that can search tracked deletions and additions.
It seems that NWP macro language lacks the "

Code: Select all

.addedTextContent"
property among the TrackedChange Object Properties. But going through the "

Code: Select all

.markedText"
or "

Code: Select all

.markedTextRange
"..., it seems possible to get the values of the added text??
Yes, the trick is to set the selection to the marked text/range and then search only within the selection. You can see how it works in the updated macro.
Yes, surely. I will send you the file in a feedback.
Great, I'll be on the lookout for it, thank you!
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: macro to delete "tracks" containing certain characters

Post by phspaelti »

Nobumi Iyanaga wrote: It seems that NWP macro language lacks the "

Code: Select all

.addedTextContent"
property among the TrackedChange Object Properties. But going through the "

Code: Select all

.markedText"
or "

Code: Select all

.markedTextRange
"..., it seems possible to get the values of the added text?? The macro would be much more complicated, but is it possible to write such a macro, please...?
You should be able to use

Code: Select all

$addedText = $change.markedText.subtextInRange($change.markedTextRange)
But of course if you do a find on this subtext (or substring) the returned range values will not be applicable to the main text. That is why Martin does the find via the GUI.
The range value for the main text would have to be calculated with something like this:

Code: Select all

$isMatch = $addedText.find($findText, $findOps)
if $isMatch
    $findRange = Range.new $change.markedTextRange.location + $isMatch.location, $isMatch.length
end
NB: I have not tested any of this.
philip
Nobumi Iyanaga
Posts: 158
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

Re: macro to delete "tracks" containing certain characters

Post by Nobumi Iyanaga »

Hello Martin,
Hello Philip,

Thank you for your new macro, Martin. I downloaded it and used it. It works perfectly, as I have expected. This helped much, and now, with much less "track changes", I can edit my document without difficulties. Thank you very much again!

As Philip points out, you use "GUI Find" to test if a track changed text contains an added item that matches those items to be found -- and this seems to slow down the macro...? But this is not a major problem; anyway, with your macro, I could make the file "workable".

Philip's codes seem very interesting, but I don't understand how they should be inserted in Martin's macro.

Anyway, I find that it is rather not very intelligent to record these kinds of "Replace All" in track changes (for example Replace All every space with a non-breaking-space for cases like "« " or " »", etc.); but there are certainly people who do that. NWP should be able to deal with this kind of files too...

Best regard,

Nobumi Iyanaga
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: macro to delete "tracks" containing certain characters

Post by phspaelti »

Hello Nobumi,
Nobumi Iyanaga wrote:Philip's codes seem very interesting, but I don't understand how they should be inserted in Martin's macro.
I had a more careful look at Martin's code, and I see that he doesn't make use of the find on the added text after all. He really just checks for presence of the find text. So the change to the macro is really simple:

Martin's code:

Code: Select all

	If $isSearchAdditions
		$markedText = $change.markedText
		If $markedText
			$markedRange = $change.markedTextRange
			If $markedRange
				$select = TextSelection.new($markedText, $markedRange)
				$doc.setSelection($select)
				If Find $findText, "s$findOps"
					$isMatch = @TRUE
				End
			End
		End
	End
Changed code:

Code: Select all

	If $isSearchAdditions
		$markedText = $change.markedText
		If $markedText
			$markedRange = $change.markedTextRange
			If $markedRange
				$addedText = $markedText.subtextInRange($markedRange)
				$isMatch = $addedText.find($findText, $findOps)
			End
		End
	End
Here is a copy of the macro with the change included.
Find in Tracked Changes.nwm
(5.55 KiB) Downloaded 939 times
Nobumi Iyanaga wrote: Anyway, I find that it is rather not very intelligent to record these kinds of "Replace All" in track changes (for example Replace All every space with a non-breaking-space for cases like "« " or " »", etc.); but there are certainly people who do that. NWP should be able to deal with this kind of files too...
This problem strikes me as the fundamental problem with Tracked Changes and why I never use them in the first place. The machine simply has no way to know the difference between a meaningful change and a cosmetic change. So unless you constantly weed through the changes and accept the cosmetic ones you end up with a document heavy with changes, and you end up with a "needle in the haystack" problem. Managing the changes can be more work than is gained by tracking them.
philip
Post Reply