Copy link to clipboard
Copied
Hi,
The blwo script is not working to add Table of contents style. Can advise to me.
var doc = app.activeDocument;
var pGroups=doc.paragraphStyleGroups.item("Group_Style");
var tocStyle = doc.tocStyles.add({
name: "TOC"
});
var tocEntry = tocStyle.tocStyleEntries.add(pGroups.paragraphStyles[0]);
<Title renamed by MOD>
Copy link to clipboard
Copied
Not entirely sure - I'll throw my hat at it - usually putting through some alerts helps me narrow down where I'm going wrong
var doc = app.activeDocument;
// Check if the paragraph style group exists and is valid
var pGroups = doc.paragraphStyleGroups.itemByName("Group_Style");
if (pGroups.isValid) {
var tocStyle;
// Check if the TOC style already exists, to avoid duplication
try {
tocStyle = doc.tocStyles.itemByName("TOC");
if (!tocStyle.isValid) {
throw new Error("TOC style does not exist.");
}
} catch (e) {
tocStyle = doc.tocStyles.add({
name: "TOC"
});
}
// Ensure that there is at least one paragraph style in the group
if (pGroups.paragraphStyles.length > 0) {
// Add a TOC entry if the paragraph style is valid
var paragraphStyle = pGroups.paragraphStyles[0];
if (paragraphStyle.isValid) {
tocStyle.tocStyleEntries.add(paragraphStyle);
alert("TOC style added successfully with paragraph style: " + paragraphStyle.name);
} else {
alert("Invalid paragraph style.");
}
} else {
alert("No paragraph styles found in the group.");
}
} else {
alert("Paragraph style group 'Group_Style' does not exist.");
}
Copy link to clipboard
Copied
Hi Eugene
Kinldy check below
Copy link to clipboard
Copied
ok
maybe it's
tocStyle.tocStyleEntries.add(paragraphStyle.name);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now