Hi jb. That's clever! Just use Nisus built in default output for the Comment object.
Here is a slightly modified version of your macro, that directly gives you the list without needing to use Find/Replace to clean it up.
Move Comments to Marked Text (in one swell foop)—Solved
Re: Move Comments to Marked Text (in one swell foop)—Solved
- Attachments
-
GatherComments.nwm
- (5.87 KiB) Downloaded 1883 times
philip
Re: Move Comments to Marked Text (in one swell foop)—Solved
Thanks, Philip.
Of course I was thinking of you when I mentioned the macro guru, but it's been five years (!).
I'm traveling now so can't try out your improved version.
Will do so next week when I'm back in town and thank you properly then.
Cheers,
James
Of course I was thinking of you when I mentioned the macro guru, but it's been five years (!).
I'm traveling now so can't try out your improved version.
Will do so next week when I'm back in town and thank you properly then.
Cheers,
James
Re: Move Comments to Marked Text (in one swell foop)—Solved
Yes, your version is a big improvement (of course).
So: Thank you!
I wondered why $listDoc = is in the final line
$listDoc = Document.newWithText $commentList.join("\n")
Of course it was in the macro I put up recently, but I didn’t really understand it. It came along for the ride when I copied/pasted from another, earlier macro.
Then I deleted the part that mystified me ( $listDoc =), and I discovered that it isn’t necessary.
My guess now is that it was used to do two things at once: to create a new Document and also to define that new document as a named object. And since I don’t need to do anything more than create the new document whose text is the list, I’ve just deleted that part of the last line.
I need to read a bit in the Macro Reference Guide to understand arrayByMakingValuesDoCommand
Thanks again
So: Thank you!
I wondered why $listDoc = is in the final line
$listDoc = Document.newWithText $commentList.join("\n")
Of course it was in the macro I put up recently, but I didn’t really understand it. It came along for the ride when I copied/pasted from another, earlier macro.
Then I deleted the part that mystified me ( $listDoc =), and I discovered that it isn’t necessary.
My guess now is that it was used to do two things at once: to create a new Document and also to define that new document as a named object. And since I don’t need to do anything more than create the new document whose text is the list, I’ve just deleted that part of the last line.
I need to read a bit in the Macro Reference Guide to understand arrayByMakingValuesDoCommand
Thanks again
Re: Move Comments to Marked Text (in one swell foop)—Solved
That is exactly how it is.jb wrote: ↑2018-07-18 16:26:05 I wondered why $listDoc = is in the final line
$listDoc = Document.newWithText $commentList.join("\n")
…
Then I deleted the part that mystified me ( $listDoc =), and I discovered that it isn’t necessary.
My guess now is that it was used to do two things at once: to create a new Document and also to define that new document as a named object. And since I don’t need to do anything more than create the new document whose text is the list, I’ve just deleted that part of the last line.
The arrayByMakingValuesDoCommand command (that's quite a mouthfulI need to read a bit in the Macro Reference Guide to understand arrayByMakingValuesDoCommand

Code: Select all
$newArray = Array.new
foreach $value in $oldArray
$newArray.push $value.doCommand
end
Hope that helps.
philip
Re: Move Comments to Marked Text (in one swell foop)—Solved
In short: arrayByMakingValuesDoCommand is "Map" in other languages. I wonder: is there an equivalent to "Filter" and "Reduce?"
Re: Move Comments to Marked Text (in one swell foop)—Solved
I see. So JavaScript has this kind of thing.
Nisus arrayByMakingValuesDoCommand is a bit more limited than map, since you can only use it for maps of arrays of objects using properties/commands that apply to that object. For example you can take an array of selections and get their lengths, but you couldn't extend all the selections by n characters, since the selection object does not have a an "extend by n characters" command.
And if you have an array of number values you can't use arrayByMakingValuesDoCommand at all, since number values are not objects.
And there is nothing like "Filter" or "Reduce". But you can always write defined commands for doing things like that.
In the end Nisus macro language is tailored for the tasks you will most likely need as a (text) document creator. And if you need more technical stuff you can always insert a Perl block.
philip
Re: Move Comments to Marked Text (in one swell foop)—Solved
Hmm. That's a subtle quirk there Philip. The Macro language guide, under the "Call" section, explains how to build a proper "Map" command, though you apparently have to hand build the function. You can no doubt do "filter" and "Reduce" the same way. I wish it was built in, though.
The macro language is a curious combination of functional and object oriented.
The macro language is a curious combination of functional and object oriented.