Copy link to clipboard
Copied
For example, my layout only has one column.
However, my text box has three columns with a column spacing of 6 mm.
But the settings for each ID document may be different.
If frequent switching may cause errors,
I came up with a solution to set 3 and 6 in a paragraph style.
For example, the paragraph style is named: columnSeting@3@6
When I run the script, it automatically sets 3 as the number of columns and 6 as the spacing.
Are there any other better methods?
This makes a group and returns a Pstyle if they do not exist, or returns the existing Pstyle if it does
var ps = addParaStyleGroup(app.activeDocument,"myGroup","my@SpaceCol@7@3@")
$.writeln(ps.name)
//returns the style’s name my@SpaceCol@7@3@
/**
* Returns a ParagraphStyle named sn in a group named g
* @ param the document to add the group and style
* @ param the paragraphStyle group name
* @ param the paragraphStyle name
* @ returns the paragraph style named sn
*/
function addParaSty
Copy link to clipboard
Copied
This should be a very practical method.
It's much more convenient than modifying the JSON every time.
However, the style names are not fixed, so they are difficult to find. The only fixed part is that they start with “columnSeting@”
Copy link to clipboard
Copied
Thank you very much.
No need, I seem to have found the direction.
I went through all the paragraph styles.
Copy link to clipboard
Copied
I did it, but I have some doubts.
Not found the first time, why is it still 0 after creating a new style?
checkColSet();
alert(csp);
alert(cn);
Is the variable occupied? Do you need to clear the cache?
Below is the complete code:
//The reference mark is SpaceCol.
var colSetParStn = "my@SpaceCol@7@3@";
var myDoc = app.activeDocument;
//Reference settings
var myTemp = colSetParStn.replace(/^[^@]+@/, "").replace(/\.jsx$/, "").split('@');
//var changeTo = decodeURIComponent(myTemp[0]);
var startMark = myTemp[0];
//alert(startMark);
var myParas = myDoc.allParagraphStyles;
var csp = 0, cn = 0;
//First, check if there is a target paragraph style. If there is, read it.
checkColSet();
function checkColSet() {
for (var i = 0; i < myParas.length; i++) {
getParaName = myParas[i].name.replace(/^[^@]+@/, "").replace(/\.jsx$/, "").split('@');
if (startMark == getParaName[0]) {
csp = getParaName[1];
cn = getParaName[2];
}
}
}
//If csp is not present, cp remains 0. Create a new paragraph style.
if (cn == 0 || csp == 0) {
SetParGroup();
}
//Double-check
checkColSet();
alert(csp);
alert(cn);
function SetParGroup() {
var wn = [colSetParStn];
for (var i = 0; i < wn.length; i++) {
w = newParGroStyle(app.activeDocument, "myGroup", wn[i])
};
}
function newParGroStyle(d, g, n,) {
// Get the group by name
var group = d.paragraphStyleGroups.itemByName(g);
// If group exists, check or create style
if (!group.isValid)
group = d.paragraphStyleGroups.add({ name: g })
if (!group.paragraphStyles.itemByName(n).isValid)
group.paragraphStyles.add({ name: n });
}
Copy link to clipboard
Copied
Your script throws multiple errors— myParas, cn, cps, colSetParStn are not defined
Copy link to clipboard
Copied
Okay, no paragraph style updates.
Copy link to clipboard
Copied
I don’t understand what StartParGroup function does
function SetParGroup() {
var wn = [colSetParStn];
$.writeln(wn.length)
//if this function runs length always returns 1, so why the loop?
$.writeln(wn[0])
//returns "my@SpaceCol@7@3@", but only when wn.length = 1
for (var i = 0; i < wn.length; i++) {
w = newParGroStyle(app.activeDocument, "myGroup", wn[i])
};
}
Copy link to clipboard
Copied
Are you referring to SetParGroup()?
I would like to assign certain paragraph styles to specific groups.
First, iterate through all paragraph styles. If SpaceCol is present, read the content after @ as csp and cn.
If not, create a new paragraph style named my@SpaceCol@7@3@.
Before the second checkColSet() check, add the following again:
var myParas = myDoc.allParagraphStyles;
This refreshes the paragraph styles.
Copy link to clipboard
Copied
This makes a group and returns a Pstyle if they do not exist, or returns the existing Pstyle if it does
var ps = addParaStyleGroup(app.activeDocument,"myGroup","my@SpaceCol@7@3@")
$.writeln(ps.name)
//returns the style’s name my@SpaceCol@7@3@
/**
* Returns a ParagraphStyle named sn in a group named g
* @ param the document to add the group and style
* @ param the paragraphStyle group name
* @ param the paragraphStyle name
* @ returns the paragraph style named sn
*/
function addParaStyleGroup(d,g,sn){
//check if group exists if not make a group named g
if (d.paragraphStyleGroups.itemByName(g).isValid) {
g = d.paragraphStyleGroups.itemByName(g);
} else {
g = d.paragraphStyleGroups.add({name:g});
}
//check if a p style named sn exists if not make
if (g.paragraphStyles.itemByName(sn).isValid) {
return g.paragraphStyles.itemByName(sn);
} else {
return g.paragraphStyles.add({name:sn})
}
}
Copy link to clipboard
Copied
Hi rob day.
Thank you very much.
I've already achieved it using a clumsy method.
@7@3@It's not fixed, only my@SpaceCol is fixed.
You still need to iterate through all paragraph styles.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now