Guest User

Untitled

a guest
Nov 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. // Project name: id0000131-convert-index-entries-into-Word-or-Google-Doc-comments
  2. // Github: Adobe Indesign Script examples: https://github.com/firedevelop/id0000013-Adobe-InDesign-Scripts-Examples
  3. // Github of this project: id0000131-convert-adobe-indesign-index-into-Word-or-Google-Doc-comments
  4. // YouTube Playlist: https://www.youtube.com/playlist?list=PLfdbMQ5CoohPqK8ekjthm2fNoGMLwYeFf
  5. // Blog: https://www.firedevelop.com/2018/11/id0000131-convert-index-entries-into.html
  6.  
  7. // Script Author:
  8. // Peter Kahrel -- www.kahrel.plus.com
  9. // http://www.kahrel.plus.com/indesign/index-to-text.jsx
  10. // http://www.kahrel.plus.com/indesign/index_to_text.html
  11.  
  12.  
  13.  
  14. (function () {
  15.  
  16. function addSortOrder (topic) {
  17. var s = topic.name;
  18. if (topic.sortOrder !== '') {
  19. s += '@' + topic.sortOrder;
  20. }
  21. return s;
  22. }
  23.  
  24. function topicPath (topic, str) {
  25. if (topic.parent.constructor.name == 'Index') {
  26. return str;
  27. } else {
  28. return topicPath (topic.parent, addSortOrder (topic.parent) + '#' + str);
  29. }
  30. }
  31.  
  32. function main () {
  33. var i, j;
  34. var topics;
  35. var err = false;
  36. if (app.documents[0].indexes.length === 0) {
  37. alert ('Document doesn't have an index.');
  38. exit();
  39. }
  40. topics = app.documents[0].indexes[0].allTopics;
  41. for (i = topics.length-1; i >= 0; i--) {
  42. for (j = topics[i].pageReferences.length-1; j > -1; j--) {
  43. try {
  44. topics[i].pageReferences[j].sourceText.contents = '<!-- ' + topicPath (topics[i], addSortOrder (topics[i])) + ' -->';
  45. //topics[i].pageReferences[j].remove();
  46. } catch (_) {
  47. err = true;
  48. }
  49. }
  50. }
  51. if (err) {
  52. alert ('Some markers could not be converted. Please check the Index panel');
  53. }
  54. }
  55.  
  56. main();
  57.  
  58. }());
Add Comment
Please, Sign In to add comment