Skip to main content
Known Participant
June 26, 2023
Answered

Query tag need to place in the margin

  • June 26, 2023
  • 3 replies
  • 828 views

Dear Experts,

 

I believe I will get help with my request.

I found a script in our forum, and I slightly altered the characterstyle name.

My request is that my object style be applied to the anchor box; and showing error, could you possibly help?

My object style name is "AQ-sidebar"

My Character style name is "AQ"

Please see the attached file, after run the script

--------------------------

app.findTextPreferences = null;

app.findTextPreferences.appliedCharacterStyle = "AQ";

myText.appliedObjectStyle = myDoc.objectStyles.item ("AQ-sidebar");

var

mFound = app.activeDocument.findText(),

len = mFound.length,

currWidth, tarText, tarIP, currFrame, currGB,

old_VOrigin = app.activeDocument.viewPreferences.verticalMeasurementUnits,

old_HOrigin = app.activeDocument.viewPreferences.horizontalMeasurementUnits;

 

app.activeDocument.viewPreferences.horizontalMeasurementUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;

 

while (len-->0) {

tarText = mFound[len];

currWidth = tarText.lines[0].endHorizontalOffset - tarText.lines[0].horizontalOffset + 10;

tarIP = tarText.insertionPoints[-1];

currFrame = tarIP.textFrames.add();

setFrame (currFrame);

currGB = currFrame.geometricBounds;

currGB = [currGB[0], currGB[3] - currWidth, currGB[2], currGB[3]];

currFrame.geometricBounds = currGB;

tarText.texts[0].move(LocationOptions.AFTER,currFrame.texts[0]);

currFrame.parentStory.characters[-1].remove();

currFrame.fit(FitOptions.FRAME_TO_CONTENT);

}

app.activeDocument.viewPreferences.horizontalMeasurementUnits = old_HOrigin;

app.activeDocument.viewPreferences.verticalMeasurementUnits = old_VOrigin;

app.findTextPreferences = null;


function setFrame (mAnchored){

with (mAnchored) {

anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;

anchoredObjectSettings.anchorPoint = AnchorPoint.BOTTOM_RIGHT_ANCHOR;

anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;

anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE;

 

textFramePreferences.insetSpacing = [0,0,0,1];

textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;

}


}

---------------------

 

Thanks

kanagakumar

This topic has been closed for replies.
Correct answer Peter Kahrel

Well, that sounded a bit harsher than necessary, sorry. It's really quite simple. First, apply all the necessary settings to your object style 'AQ-sidebar' (anchored object; set the width, not the height; set auto size to height only, add a paragraph style, probably; and whatever else). Then all you need is this simple script:

 

(function () {
  app.findTextPreferences = null;
  app.findTextPreferences.appliedCharacterStyle = 
    app.documents[0].characterStyles.item("AQ");
  var ostyle = app.documents[0].objectStyles.item('AQ-sidebar');
  var AQs = app.documents[0].findText();
  var frame;
  for (var i = AQs.length-1; i >= 0; i--) {
    frame = AQs[i].insertionPoints[0].textFrames.add ({
      appliedObjectStyle: ostyle,
    });
    AQs[i].move (LocationOptions.AT_BEGINNING, frame);
  }
}());

 

P.

3 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
July 5, 2023

Well, that sounded a bit harsher than necessary, sorry. It's really quite simple. First, apply all the necessary settings to your object style 'AQ-sidebar' (anchored object; set the width, not the height; set auto size to height only, add a paragraph style, probably; and whatever else). Then all you need is this simple script:

 

(function () {
  app.findTextPreferences = null;
  app.findTextPreferences.appliedCharacterStyle = 
    app.documents[0].characterStyles.item("AQ");
  var ostyle = app.documents[0].objectStyles.item('AQ-sidebar');
  var AQs = app.documents[0].findText();
  var frame;
  for (var i = AQs.length-1; i >= 0; i--) {
    frame = AQs[i].insertionPoints[0].textFrames.add ({
      appliedObjectStyle: ostyle,
    });
    AQs[i].move (LocationOptions.AT_BEGINNING, frame);
  }
}());

 

P.

Known Participant
July 18, 2023

Dear Peter Kahrel

 

Please accept my heartfelt apologies for the delayed response.

Thank you for your script. It's working fine.

 

Thank you very much

KK

Peter Kahrel
Community Expert
Community Expert
July 4, 2023

Honestly, the script you showed is a total mess, it can't even be salvaged.

You should ask someone to do a new script for you.

 

P.

Known Participant
July 5, 2023

Thanks for your reply "Peter Kahrel"

 

OKay! i will do my best, Thank you once again.

 

KK

 

Loic.Aigon
Legend
June 26, 2023

What error message do you get? I just tried your script and did get the error message. Then the error was pretty meaningful.

I will leave it up to you but that's pure Javascript error that you have.

Known Participant
July 4, 2023

Dear Friends,

Can one one resolve this issue?

I have no idea for how to resolve this issue?

 

Thanks

kanagakumar.k