Copy link to clipboard
Copied
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
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.d
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Dear Friends,
Can one one resolve this issue?
I have no idea for how to resolve this issue?
Thanks
kanagakumar.k
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now