Copiar link para a área de transferência
Copiado
Hello All,
I need to anchor an object to a 2-column text frame so that the object appears to the left of the left column or to the right of the right column depending on which column the anchor is in? And if the anchor is moved to a different column when editing the text, the anchored object moves to the correct location. Is it possible to do this using a single object style?
The image shows a sample layout that I want to get.
Thanks!
I see what you mean, I hadn't thought of that. Here's an updated script to deal with that. It's a bit verbose but it'll keep me sane.
Note that instead of your paragraph style names "left anchor" and "right anchor" I used 'anchor left align' and 'anchor right align', which make more sense.
(function () {
var d = app.activeDocument;
var leftAlign = d.paragraphStyles.item ('anchor left align');
var rightAlign = d.paragraphStyles.item ('anchor right align');
var insideStyle = d.obj
...
Copiar link para a área de transferência
Copiado
That's not possible. You'd have to create an object style for that places the anchors in the outside margins and apply that style to all anchored frames. Then create an object style that places frames in the inside margins. Then you'd need a script that applies that inside style to anchored frames in column 2 on versos and in column 1 on rectos.
Here's a script that does that. It assumes two object styles, 'anchor inside' and 'anchor outside'. You can use other names if you prefer. You need to run it every time when anchors may have moved to a different column.
(function () {
var d = app.activeDocument;
var insideStyle = d.objectStyles.item ('anchor inside');
var outsideStyle = d.objectStyles.item ('anchor outside');
function inside (frame) {
if (frame.parentPage.side === PageSideOptions.LEFT_HAND
&& frame.parent.textColumns[0] == frame.parent.parentTextFrames[0].textColumns[1]) {
return true;
}
if (frame.parentPage.side === PageSideOptions.RIGHT_HAND
&& frame.parent.textColumns[0] == frame.parent.parentTextFrames[0].textColumns[0]) {
return true;
}
return false;
}
var frames = d.stories.everyItem().textFrames.everyItem().getElements();
for (var i = 0; i < frames.length; i++) {
if (inside (frames[i])) {
frames[i].appliedObjectStyle = insideStyle;
} else {
frames[i].appliedObjectStyle = outsideStyle;
}
}
}());
Copiar link para a área de transferência
Copiado
@Peter Kahrel I presume this would need to be re-run after any edits...
Copiar link para a área de transferência
Copiado
Yep, and I mentioned that 🙂
Copiar link para a área de transferência
Copiado
Thanks @Peter Kahrel
I also have this feature - in anchors that are on the left (on even and odd page), the text should be formatted on the right side, and in anchors on the right side - the text on the left side. Therefore, the internal anchors on the right and left pages have different styles.
I made the styles "left anchor" and "right anchor" with the desired text style in them, and I apply them manually.
Copiar link para a área de transferência
Copiado
I see what you mean, I hadn't thought of that. Here's an updated script to deal with that. It's a bit verbose but it'll keep me sane.
Note that instead of your paragraph style names "left anchor" and "right anchor" I used 'anchor left align' and 'anchor right align', which make more sense.
(function () {
var d = app.activeDocument;
var leftAlign = d.paragraphStyles.item ('anchor left align');
var rightAlign = d.paragraphStyles.item ('anchor right align');
var insideStyle = d.objectStyles.item ('anchor inside');
var outsideStyle = d.objectStyles.item ('anchor outside');
//--------------------------------------------------------
function positionFrame (frame) {
var side = frame.parentPage.side === PageSideOptions.LEFT_HAND
? 'left' : 'right';
var column = frame.parent.textColumns[0] == frame.parent.parentTextFrames[0].textColumns[0]
? 1 : 2;
if (side === 'left' && column === 1) {
frame.appliedObjectStyle = outsideStyle;
frame.texts[0].appliedParagraphStyle = rightAlign;
return;
}
if (side === 'left' && column === 2) {
frame.appliedObjectStyle = insideStyle;
frame.texts[0].appliedParagraphStyle = leftAlign;
return;
}
if (side === 'right' && column === 1) {
frame.appliedObjectStyle = insideStyle;
frame.texts[0].appliedParagraphStyle = rightAlign;
return;
}
if (side === 'right' && column === 2) {
frame.appliedObjectStyle = outsideStyle;
frame.texts[0].appliedParagraphStyle = leftAlign;
return;
}
}
//--------------------------------------------------------
var frames = d.stories.everyItem().textFrames.everyItem().getElements();
for (var i = 0; i < frames.length; i++) {
positionFrame (frames[i]);
}
}());
Copiar link para a área de transferência
Copiado
Encontre mais inspiração, eventos e recursos na nova comunidade da Adobe
Explore agora