Reply to topic  [ 5 posts ] 
Close all closes Document Manager Too? 
Author Message

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
I wrote this macro some time ago (it is for converting any document into pdf):
Code:
# Save all open documents.

Require Application Version 3.1


Prompt 'This macro opens and converts documents into pdf. Any open document will be closed first. Pdfs are saved in the same folder as the original and with the same name.'



File:Close All # first close all open documents
File:Open… # then open new ones

# loop through all open documents
$allDocs = Document.openDocuments
ForEach $doc in $allDocs
   Document.setActive($doc)
   Save as PDF...
   Press Default Button
   Close
end

Is there a way to tell NWP to close all open documents but not the Document Manager?


2010-12-03 11:07:25
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Not with a single command, but you can do it with a loop:
Code:
$allDocs = Document.openDocuments
ForEach $doc in $allDocs
   $doc.close
End


2010-12-03 12:26:15
Profile WWW

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Where there’s a loop there’s a way. Thank you, Martin.

Henry


2010-12-04 02:25:18
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
Groucho’s macro wrote:
Any open document will be closed first.
Your macro seems to close all open documents for the sole purpose of preventing them from being saved as PDF together with those which are going to be opened. So do I think but I may be wrong. Perhaps it makes you happy, very happy, very very happy to see the Document Manager window with no document window, perhaps. Chacun son goût. Anyway, in such a situation, if you use Choose Files command instead of Open… (menu command) to select files, you don’t need closing any document, for newly opened ones are identified by their file paths ($path[s]) and then by a Document object ($doc) returned by Document.open $path.
Code:
$paths = Choose Files '', 'Make PDF'

if $paths == undefined
   exit  # Cancelled by the user
end

foreach $path in $paths
   $doc = Document.open $path
   $pdfPath = $path.filePathByChangingExtension 'pdf'
   Document.setActive $doc  # make sure that $doc is the frontmost
   Save As PDF $pdfPath
   $doc.close true  # true [= discard changes] is very unlikely to be useful here, though
end


2011-01-17 09:23:29
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Quote:
At first Kino was saying:
Your macro seems to close all open documents for the sole purpose of preventing them from being saved as PDF together with those which are going to be opened. So do I think but I may be wrong.

No, you are right, Kino. I like to keep the Document Manager always open.

Quote:
Then he went on like this…
Anyway, in such a situation, if you use Choose Files command instead of Open…

Grand. I had thought of using Choose Files but I was at a loss how to develop a macro that way. Until you came to rescue. Thank you, Kino.

Henry.


2011-01-17 11:08:42
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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