Skip to main content
Inspiring
May 1, 2025
Answered

Defining a Cross-Reference format via script

  • May 1, 2025
  • 2 replies
  • 372 views

Hi everyone,

From this old post, I've learned that it's possible to create a cross-reference to paragraph via script. My question now is: Is there a way to also define/edit it via script? - see screenshot below. For instance, I would like to remove the quotations marks and leave only <paraText /> when creating the cross-reference. @Peter Kahrel, any help will be greatly appreciated 🙂 Thanks!

 

Correct answer Peter Kahrel

@Rogerio5C09 -- The thing with editing cross-refernce formats is that you can't remove individual items: you have to remove all parts, then add what you want:

 

cr = app.activeDocument.crossReferenceFormats.item ('Paragraph Text');

// Can't remove the lot using everyItem().remove(),
// so you have to remove each item separately

for (i = cr.buildingBlocks.length-1; i >= 0; i--) {
  cr.buildingBlocks[i].remove();
}

// Add the desired building block

cr.buildingBlocks.add (BuildingBlockTypes.PARAGRAPH_TEXT_BUILDING_BLOCK);

2 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
May 5, 2025

@Rogerio5C09 -- The thing with editing cross-refernce formats is that you can't remove individual items: you have to remove all parts, then add what you want:

 

cr = app.activeDocument.crossReferenceFormats.item ('Paragraph Text');

// Can't remove the lot using everyItem().remove(),
// so you have to remove each item separately

for (i = cr.buildingBlocks.length-1; i >= 0; i--) {
  cr.buildingBlocks[i].remove();
}

// Add the desired building block

cr.buildingBlocks.add (BuildingBlockTypes.PARAGRAPH_TEXT_BUILDING_BLOCK);
Robert at ID-Tasker
Legend
May 1, 2025