Reply to topic  [ 5 posts ] 
Substitute selection by a file 
Author Message

Joined: 2009-02-17 17:44:12
Posts: 37
I made a macro, its simple one.

$doc1 =
$file = Choose File '~/Documents', 'Choose File to insert'
$doc2 = $file
$text = $doc2.allTexts
Document.setActive $doc1
$doc1.insertText $text, 'm'

The purpose of this macro is "Select region to substitute by a file".
However, it has a problem.
When the text inserted, there are unexpected texts are added to front and end of the inserted text.
Front one is ("
End one is ", "", "")

I hope to know the reason of the unexpected result and I'd like to make a macro which I expected.
Please help me.

2010-06-25 02:40:19

Joined: 2008-05-17 04:02:32
Posts: 400
You get those odd characters because allTexts returns an array, something like ("main body text", "header1", "header2", "header3", "footer1", "footer2", "footer3", "endnotes", "footnotes") and some text objects in your file, e.g. endnotes, are empty.

Try to use $text = $doc2.text instead of $text = $doc2.allTexts.

2010-06-25 06:16:12

Joined: 2009-02-17 17:44:12
Posts: 37
Kino, I appreciate your kindly help.
Your explanation completely understands me about the unexpected result from the macro I made.
Now, the revised macro is work fine as expected !

Thank you for your devotion to this forum.

2010-06-27 18:22:08
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Yes, we all appreciate Kino's devotion to this forum and to helping fellow users out :)

2010-06-28 10:57:05
Profile WWW
User avatar

Joined: 2008-01-20 11:08:35
Posts: 89
Location: California
What a great macro, I made a few additions. I put in a test if the user cancels the macro exits, otherwise NWP crashes, also I have the insert file open hidden and then close after grabbing the text, and last, I use options "sa" for insert so it matches the style of the document that you are inserting into. Your preference may be different.
$doc1 =
$file = Choose File '~/Documents', 'Choose File to insert'
if !$file
$doc2 = $file, false
$text = $doc2.text
Document.setActive $doc1
$doc1.insertText $text, 'sa'   

Thanks to tomoyuki-kosaka and kino.


2011-04-17 10:07:11
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software