Can a macro address tracked changes?

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
chazzo
Posts: 25
Joined: 2011-10-27 03:40:31
Location: Norfolk, UK

Can a macro address tracked changes?

Post by chazzo » 2013-02-19 11:02:03

I'm working on a long document containing many tracked changes. I'd like to accept the 95 percent of the changes that relate to formatting, and keep the rest. Could a macro parse tracked changes and distinguish between the different types?

Thanks
Charles

User avatar
phspaelti
Posts: 944
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Can a macro address tracked changes?

Post by phspaelti » 2013-02-19 15:13:39

In principle yes. The Nisus macro language has the ability to access tracked changes. The tracked change object has a .isTextContentChanged property (among others), so it seems it would be possible to distinguish the ones you are looking for.
philip

User avatar
phspaelti
Posts: 944
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Can a macro address tracked changes?

Post by phspaelti » 2013-02-19 15:27:56

This macro would seem to do the trick (Test it on a copy, please!).

Code: Select all

$doc = Document.active
$changes = $doc.allTrackedChanges
foreach $change in $changes
	if ! $change.isTextContentChanged
		$change.accept
	end
end
philip

User avatar
chazzo
Posts: 25
Joined: 2011-10-27 03:40:31
Location: Norfolk, UK

Re: Can a macro address tracked changes?

Post by chazzo » 2013-02-20 02:10:24

This macro would seem to do the trick
Philip, you are a genius. That works perfectly, except for changes to the language. Is there a corresponding property for this? I tried "isTextLanguageChanged" and "isLanguageChanged", but neither of these works.

Background: I'm exchanging an RTF document with several Word users. Change tracking and commenting generally works very well. However, the document returned by one user has hundreds of marked changes relating to formatting. Perhaps she is the only one to have "track formatting changes" turned on in Word, but it's difficult to control how other people work, so with this macro it's easier to strip them out. I don't think any of these formatting changes are "real" -- in other words, I don't think my colleague has made them deliberately. If anyone can shed light on this I'd be very pleased.

Taking a wider view, is there a reference somewhere for all these macro properties? I'm extremely grateful for the help, but I could probably have figured this one out myself if I'd been able to consult a list of what's available.

User avatar
phspaelti
Posts: 944
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Can a macro address tracked changes?

Post by phspaelti » 2013-02-20 04:58:38

chazzo wrote:Taking a wider view, is there a reference somewhere for all these macro properties? I'm extremely grateful for the help, but I could probably have figured this one out myself if I'd been able to consult a list of what's available.
Help > Macro Language Reference

What do you mean by "Text Language Changed"? Are you talking about the language attribute? In that case you would have to get the attributes using ".originalTextAttributes". This is itself another object. But all of this is documented in the above mentioned file.
philip

User avatar
chazzo
Posts: 25
Joined: 2011-10-27 03:40:31
Location: Norfolk, UK

Re: Can a macro address tracked changes?

Post by chazzo » 2013-02-20 06:55:14

phspaelti wrote:Help > Macro Language Reference
I feel pretty stupid now, but thank you.
phspaelti wrote:What do you mean by "Text Language Changed"? Are you talking about the language attribute? In that case you would have to get the attributes using ".originalTextAttributes". This is itself another object. But all of this is documented in the above mentioned file.
I meant that your "if ! $change.isTextContentChanged" condition finds:

Formatted: Font: Georgia; was: Times New Roman

but not:

Formatted: Language: English (U.S.); was: German

And "if $change.isTextAttributesChanged" does not seem to work either, So yes, I guess I need to get ".originalTextAttributes.language" and compare it to the current language attribute. Thanks for the tip.

User avatar
phspaelti
Posts: 944
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Can a macro address tracked changes?

Post by phspaelti » 2013-02-20 07:31:46

chazzo wrote:I meant that your "if ! $change.isTextContentChanged" condition finds:

Formatted: Font: Georgia; was: Times New Roman

but not:

Formatted: Language: English (U.S.); was: German
That sounds like a bug to me. You should report it (using Feedback.)
philip

User avatar
chazzo
Posts: 25
Joined: 2011-10-27 03:40:31
Location: Norfolk, UK

Re: Can a macro address tracked changes?

Post by chazzo » 2013-02-20 08:43:47

phspaelti wrote:That sounds like a bug to me. You should report it (using Feedback.)
I think it's a bug in my document after too many exchanges with Word users. I tried it on a clean document and it's fine.

Looking more closely at what happens when I run the macro on my working document: some of the language changes are indeed accepted. The ones that aren't seem to be orphans: they are not actually attached to text in the document. I hadn't noticed that before. It's not surprising that the macro doesn't deal with them.

Aaargh! I hate Word but I can't avoid working with people who use it. And these are the "nice" clients, who stick to RTF...

User avatar
martin
Official Nisus Person
Posts: 4361
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Can a macro address tracked changes?

Post by martin » 2013-02-21 18:53:42

chazzo wrote:
phspaelti wrote:That sounds like a bug to me. You should report it (using Feedback.)
I think it's a bug in my document after too many exchanges with Word users. I tried it on a clean document and it's fine.

Looking more closely at what happens when I run the macro on my working document: some of the language changes are indeed accepted. The ones that aren't seem to be orphans: they are not actually attached to text in the document. I hadn't noticed that before. It's not surprising that the macro doesn't deal with them.

Aaargh! I hate Word but I can't avoid working with people who use it. And these are the "nice" clients, who stick to RTF...
Even if the problem is related to Word or too many file exchanges, we'd still be happy to take a look at your file and see if we can't fix the problem. If you don't mind, please send it to us privately using the menu Help > Send Feedback so we can see what can be done. Thanks!

User avatar
chazzo
Posts: 25
Joined: 2011-10-27 03:40:31
Location: Norfolk, UK

Re: Can a macro address tracked changes?

Post by chazzo » 2013-02-22 03:24:24

If you don't mind, please send it to us privately using the menu Help > Send Feedback so we can see what can be done. Thanks!
Thanks Martin -- I've done that.
Charles

User avatar
martin
Official Nisus Person
Posts: 4361
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Can a macro address tracked changes?

Post by martin » 2013-02-22 13:05:00

Thanks Charles, I see the report you submitted and we'll reply to you privately.

User avatar
martin
Official Nisus Person
Posts: 4361
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Can a macro address tracked changes?

Post by martin » 2013-02-22 18:32:12

chazzo wrote:Looking more closely at what happens when I run the macro on my working document: some of the language changes are indeed accepted. The ones that aren't seem to be orphans: they are not actually attached to text in the document.
The tracked changes the macro is missing are actually changes applied in your document's footnote text areas. The problem is that the ".allTrackedChanges" command doesn't return those changes, which is a bug we'll have to fix. Sorry about that.

Here's another macro that (mostly) works around that:

Code: Select all

$doc = Document.active
$docText = $doc.text
$lastDocTextLoc = 0

# iterate all changes in the document
Select Document Start
While TRUE
	Menu "Go To Next Change"
	$selected = TextSelection.active
	$text = $selected.text

	# accept formatting changes
	$changes = $text.trackedChangesAtIndex($selected.location)
	If $changes
		ForEach $change in $changes
			If ! $change.isTextContentChanged
				$change.accept
			End
		End
	End
	
	# check if wrapped
	If $text == $docText
		If $selected.location < $lastDocTextLoc
			Break
		End
		$lastDocTextLoc = $selected.location
	End
End
I say "almost" works around the problem because this macro still misses a few changes in your file. There are about 3 changes which aren't visited properly, due to a related bug which is triggered by the particular way the changes and footnote references overlap.

User avatar
chazzo
Posts: 25
Joined: 2011-10-27 03:40:31
Location: Norfolk, UK

Re: Can a macro address tracked changes?

Post by chazzo » 2013-02-24 11:07:46

Thanks Martin, that's very helpful.

Post Reply