tag:support.primatelabs.com,2011-01-31:/discussions/voodoopad/10209-orphaned-pages-script-errorPrimate Labs: Discussion 2018-10-19T03:39:24Ztag:support.primatelabs.com,2011-01-31:Comment/459765152018-08-28T17:00:18Z2018-08-28T17:00:18ZOrphaned Pages Script Error<div><p>Hi svs,</p>
<p>This code should work instead:</p>
<pre>
<code>function makeOrphanedPage(document) {
var linkedPages = {}; // using a hash table here because it's convenient.
var orphanedPages = [];
var summaryPageName = "Orphaned Pages";
/* Collect all linked pages. */
var keys = document.keys();
for (i = 0; i < keys.length; i++) {
var page = document.pageForKey(keys[i]);
if (!page.isText() || (page.key() == "orphaned pages")) {
continue;
}
var pageContent = page.dataAsAttributedString();
var linkedPageNames = document.linkedPageNamesInAttributedString(pageContent);
for (j = 0; j < linkedPageNames.length; j++) {
linkedKey = linkedPageNames[j].vpkey();
// ignore self links.
if (!linkedKey.isEqualToString(page.key())) {
linkedPages[linkedKey] = "";
}
}
}
/* Now compare the linked pages with all pages to find the orphaned ones. */
for (i = 0; i < keys.length; i++) {
var key = keys[i];
if (linkedPages[key] == null) {
orphanedPages.push(key);
}
}
/* Create a summary page and open it. */
var summaryPage = document.createNewPageWithName(summaryPageName);
summaryPage.setDataAsString(summaryPageName + "\n\n" + orphanedPages.join("\n"));
}
function pageWasOpened(document, page) {
if (page.key() == "orphaned pages") {
makeOrphanedPage(document);
}
}</code>
</pre>
<p>the <code>keys.length()</code> has been replaced with <code>keys.length</code>. I apologize for the trouble. We will update the documentation as soon as we can. Let me know if you run into anymore issues.</p></div>Sarahtag:support.primatelabs.com,2011-01-31:Comment/459765152018-08-28T20:21:20Z2018-08-28T20:21:20ZOrphaned Pages Script Error<div><p>Thank you so much, that worked perfectly!</p></div>svs