Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Anchoring an object to a 2-column text frame depending on which column the anchor is in

Community Beginner ,
Jul 14, 2025 Jul 14, 2025

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!

TOPICS
How to
555
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 15, 2025 Jul 15, 2025

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
...
Translate
Community Expert ,
Jul 14, 2025 Jul 14, 2025

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;
    }
  }

}());

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2025 Jul 14, 2025

@Peter Kahrel I presume this would need to be re-run after any edits...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2025 Jul 15, 2025

Yep, and I mentioned that 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 15, 2025 Jul 15, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2025 Jul 15, 2025

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]);
  }

}());
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2025 Jul 16, 2025
LATEST

Thanks @Peter Kahrel 

 

This will help me a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines