Close all closes Document Manager Too?

Get help using and writing Nisus Writer Pro macros.
Post Reply
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Close all closes Document Manager Too?

Post by Groucho »

I wrote this macro some time ago (it is for converting any document into pdf):

Code: Select all

# 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?
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Close all closes Document Manager Too?

Post by martin »

Not with a single command, but you can do it with a loop:

Code: Select all

$allDocs = Document.openDocuments
ForEach $doc in $allDocs
	$doc.close
End
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Close all closes Document Manager Too?

Post by Groucho »

Where there’s a loop there’s a way. Thank you, Martin.

Henry
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Close all closes Document Manager Too?

Post by Kino »

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: Select all

$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
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Close all closes Document Manager Too?

Post by Groucho »

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.
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.
Post Reply