Converting comments to inline comments

Get help using and writing Nisus Writer Pro macros.
Post Reply
ptram
Posts: 279
Joined: 2007-10-21 14:59:09

Converting comments to inline comments

Post by ptram » 2010-10-18 09:40:05

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

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

Re: Converting comments to inline comments

Post by martin » 2010-10-18 12:28:05

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).

User avatar
Hamid
Posts: 734
Joined: 2007-01-17 03:25:42

Re: Converting comments to inline comments

Post by Hamid » 2010-10-19 00:33:01

The second macro does not work for me. Inline comments are just deleted..

ptram
Posts: 279
Joined: 2007-10-21 14:59:09

Re: Converting comments to inline comments

Post by ptram » 2010-10-19 01:04:16

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

ptram
Posts: 279
Joined: 2007-10-21 14:59:09

Re: Converting comments to inline comments

Post by ptram » 2010-10-19 01:28:10

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

User avatar
Hamid
Posts: 734
Joined: 2007-01-17 03:25:42

Re: Converting comments to inline comments

Post by Hamid » 2010-10-19 06:14:43

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.

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

Re: Converting comments to inline comments

Post by martin » 2010-10-19 13:20:28

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."

ptram
Posts: 279
Joined: 2007-10-21 14:59:09

Re: Converting comments to inline comments

Post by ptram » 2010-10-20 04:53:08

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

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

Re: Converting comments to inline comments

Post by martin » 2010-10-20 12:42:26

Sounds like a good idea to me- topic moved, thanks Paolo.

Post Reply