Page 1 of 1

Converting comments to inline comments

Posted: 2010-10-18 09:40:05
by ptram
Hi,

I wonder if someone knows how to program such a macro: one that converts each comment to an inline comment of this type:

This is the referring text [This is the comment I added to this text, PT].

Author's abbreviation would be optional; automatic highlight (optional) would be very highly appreciated.

Uh, and the other way round (from inline comments to NW comment) would also be nice...

(Sooner or later, I'll learn how to program...)

Cheers,
Paolo

Re: Converting comments to inline comments

Posted: 2010-10-18 12:28:05
by martin
Hi Paolo, here's a macro for you:

Code: Select all

Select Document Start
$count = 0

While true
	# move to the next comment, detecting if no more comments
	$previousSelection = TextSelection.active
	Menu 'Go to Next Comment'
	$selection = TextSelection.active
	If $selection.range == $previousSelection.range
		Break
	End
	
	# save the comment, remove it, and place it inline
	$comment = Read Selection
	Menu 'Remove Comments in Selection'
	Select End
	Type Text ' [['
	Insert Attributed Text $comment
	Menu 'Highlight:Yellow'
	Select End
	Menu 'Highlight:Remove Highlight Attribute'
	Type Text ']]'
	$count += 1
End

Prompt "Converted $count comments to be inline."
It doesn't insert the initials of the authors, which I don't think is currently possible, but it does highlight the comments. You'll notice I used double brackets to [[surround]] the comments, so that the inverse macro doesn't slurp up all bracketed text. But perhaps that's not necessary for you.

Here's the inverse:

Code: Select all

Select Document Start
$count = 0

# scan for comments enclosed in double brackets
While Find Next ' \[\[(?<comment>.+?)\]\]', 'E$'
	# delete the inline comment and add back in the normal comment
	Delete
	Menu 'Add Comment'
	Insert Attributed Text $comment
	# remove highlight
	Menu 'Highlight:Remove Highlight Attribute'
	Menu 'Paragraph Style:Comment'
	$count += 1
End

Prompt "Found and converted $count inline comments."
There is one possibly significant limitation: the revived comments will all be marked as if they had been created by the current author (ie: the author running the macro).

Re: Converting comments to inline comments

Posted: 2010-10-19 00:33:01
by Hamid
The second macro does not work for me. Inline comments are just deleted..

Re: Converting comments to inline comments

Posted: 2010-10-19 01:04:16
by ptram
I'll try these macros later today. In the meantime, thank you very much Martin, these promise to be real time-savers. Good idea to avoid using square brackets. I could eventually replace the double square brackets with a brace.

Paolo

Re: Converting comments to inline comments

Posted: 2010-10-19 01:28:10
by ptram
OK, tested both macros (after adapting them to the Italian version). They seem to work fine.

I'll post both the English and the Italian version in the Macro forum.

Thank you Martin!

Paolo

Re: Converting comments to inline comments

Posted: 2010-10-19 06:14:43
by Hamid
Hamid wrote:The second macro does not work for me. Inline comments are just deleted..
That was in Draft View.

In Page View the macro works fine.

Re: Converting comments to inline comments

Posted: 2010-10-19 13:20:28
by martin
Hamid wrote:
Hamid wrote:The second macro does not work for me. Inline comments are just deleted..
That was in Draft View.

In Page View the macro works fine.
That's odd, that shouldn't make a difference. I just tested it and you're right, the macro doesn't work in Draft view. For some reason the "Add Comment" macro command doesn't move the focus/selection to the comment area in Draft View. I'll have a look at fixing this.

Here's a revised macro that functions both in Draft View or Page View:

Code: Select all

Select Document Start
$count = 0

# scan for comments enclosed in double brackets
While Find Next ' \[\[(?<comment>.+?)\]\]', 'E$'
	# delete the inline comment and add back in the normal comment
	Delete
	Menu 'Add Comment'

	# in Draft View the Add Comment command doesn't move focus to the comment area; fix that
	$selection = TextSelection.active
	If 'comment' != $selection.text.documentContentType
		Menu 'Go to Comment Text'
	End

	# insert comment text and remove highlight
	Insert Attributed Text $comment
	Menu 'Highlight:Remove Highlight Attribute'
	Menu 'Paragraph Style:Comment'
	
	$count += 1
End

Prompt "Found and converted $count inline comments."

Re: Converting comments to inline comments

Posted: 2010-10-20 04:53:08
by ptram
Martin, may I ask you to move this discussion to the Macro forum? I would prefer to avoid duplicates, and I did the mistake to start it in the wrong one.

Thanx, Paolo

Re: Converting comments to inline comments

Posted: 2010-10-20 12:42:26
by martin
Sounds like a good idea to me- topic moved, thanks Paolo.