Skip to main content
Inspiring
December 3, 2008
Question

[CS3] Search Index Markers

  • December 3, 2008
  • 6 replies
  • 650 views
Is there a way to search for index markers and then get the content from it to put it in a new created anchored inline textframe? I wan't to create side-heading like in Framemaker.
This topic has been closed for replies.

6 replies

stoereeeAuthor
Inspiring
December 5, 2008
Thank you both, this is very helpfull!
Peter Kahrel
Community Expert
Community Expert
December 4, 2008
Thanks, Martin, that will be useful.

Peter
Inspiring
December 4, 2008
Hi Peter,

what a nice script!

I have took the liberty of doing some modifications to take use of the conditional text feature in InDesign CS4. So one can make the previous index entries visible or not.

Here it goes with the (new) function 'conditional_note()' instead of 'side_note()':

// index2text.jsx
// based on a script of Peter Kahrel, modified to take use of InDesign CS4 conditional text

Object.prototype.get = function( )
{
try {
var myObject = this.item( arguments[0].name );
myObject.name;
}
catch (e) {
var myObject = this.add( arguments[0] );
}
return myObject;
}

var myConditionSet = app.activeDocument.conditions.get( {name:'Index', indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT} )
index2text (app.activeDocument);
//delete_index (app.activeDocument);
myConditionSet.visible = false;

function index2text (doc)
{
var tops = doc.indexes[0].allTopics;
for (var i = 0; i < tops.length; i++)
for (var j = tops.pageReferences.length-1; j > -1; j--)
{
var ip = tops.pageReferences.sourceText;
var p_ref = topic_path (tops, tops.name);
conditional_note (ip, p_ref)
}
}

// create topic string. Subtopics are separated by '#'
function topic_path (top, str)
{
if (top.parent.constructor.name == 'Index')
return str;
else
return topic_path (top.parent, top.parent.name + '#' + str)
}

function delete_index (doc)
{
// delete page references and topics
doc.indexes[0].topics.everyItem().pageReferences.everyItem().remove();
doc.indexes[0].topics.everyItem().remove();
}

function conditional_note (ins_point, s)
{
ins_point.appliedConditions = myConditionSet;
ins_point.contents = s;
}

function side_note (ins_point, s)
{
var sidebar = ins_point.textFrames.add ();
sidebar.geometricBounds = [0,0,10,70];
sidebar.appliedObjectStyle = app.activeDocument.objectStyles.get( { name:'sidebar' } );
sidebar.itemLayer = app.activeDocument.layers.get( { name:'sidebar' } );
sidebar.contents = s;
sidebar.fit (FitOptions.frameToContent);
}


Thanks
Martin Fischer
Peter Kahrel
Community Expert
Community Expert
December 4, 2008
Ah -- I thought you just wanted to know about the index markers. To create side headings, just insert a text frame at the index marker. The script needs an object style "sidebar" that has all the necessary settings. It now creates sidebars 70 points wide, you can change that in the line
>sidebar.geometricBounds = [0,0,10,70];

Change 70 to the width you need (you can use other units like this: "20mm"). I've tried this on a simple document and it worked fine. Maybe the orientation of the ruler plays a role, I don't know.

Peter

index2text (app.activeDocument);

delete_index (app.activeDocument);

function index2text (doc)
{
var tops = doc.indexes[0].allTopics;
for (var i = 0; i < tops.length; i++)
for (var j = tops.pageReferences.length-1; j > -1; j--)
{
var ip = tops.pageReferences.sourceText;
var p_ref = topic_path (tops, tops.name);
side_note (ip, p_ref)
}
}

// create topic string. Subtopics are separated by '#'
function topic_path (top, str)
{
if (top.parent.constructor.name == 'Index')
return str;
else
return topic_path (top.parent, top.parent.name + '#' + str)
}

function delete_index (doc)
{
// delete page references and topics
doc.indexes[0].topics.everyItem().pageReferences.everyItem().remove();
doc.indexes[0].topics.everyItem().remove();
}

function side_note (ins_point, s)
{
var sidebar = ins_point.textFrames.add ();
sidebar.geometricBounds = [0,0,10,70];
sidebar.appliedObjectStyle = app.activeDocument.objectStyles.item ('sidebar');
sidebar.contents = s;
sidebar.fit (FitOptions.frameToContent);
}
stoereeeAuthor
Inspiring
December 4, 2008
The Script works fine. But how can I put anchored inline textframe at Index marker position?
Peter Kahrel
Community Expert
Community Expert
December 3, 2008
I use the script below to convert page references to text. The contents of the references is placed at the index marker, using the format bla. Any subtopics are separated by #.

Peter

index2text (app.activeDocument);
delete_index (app.activeDocument);

function index2text (doc)
   {
   var tops = doc.indexes[0].allTopics;
   for (var i = 0; i < tops.length; i++)
      for (var j = tops.pageReferences.length-1; j > -1; j--)
         tops.pageReferences.sourceText.contents =
               '<ix>' + topic_path (tops, tops.name) + '</ix>';
   }

// create topic string. Subtopics are separated by '#'
function topic_path (top, str)
   {
   if (top.parent.constructor.name == 'Index')
      return str;
   else
      return topic_path (top.parent, top.parent.name + '#' + str)
   }

function delete_index (doc)
   {
   // delete page references and topics
   doc.indexes[0].topics.everyItem().pageReferences.everyItem().remove();
   doc.indexes[0].topics.everyItem().remove();
   }