Copy link to clipboard
Copied
Was attempting to modify the below snippet to also affect selected text frames (as opposed to only the selected text within one text frame), in order to affect the text within those frames to assign text attributes to them.
I attempted attaching .pageItem and .child etc but received ‘object’ oriented errors.
Ideally I want to attribute everything listed in the character panel to the selected text frames, in the below screenshot, (i.e. font family, font style name, font size, leading, kerning, tracking, etc.).
Any help is very much appreciated.
Cheers.
var sel = app.selection;
for(var n=0;n<sel.length;n++)
{
sel
.tracking=30; sel
.kerningMethod="Metrics"; };
The textFrame object doesn't have properties like tracking, kerning etc. You need to address a text object.
With one or more text frames, sel
However, I suggest that you use sel
Copy link to clipboard
Copied
The textFrame object doesn't have properties like tracking, kerning etc. You need to address a text object.
With one or more text frames, sel
However, I suggest that you use sel
More advice that you did not ask for: Your posted snippet assumes that the script user will have selected one or more text frames. With a small number of careful users, that should work just fine. But if you're dealing with a larger number of users, you might want to include some logic in your script to handle the situations where someone has selected the text inside a frame or a group or a collection of page objects that might contain graphics frames, rules, etc. I have some snippets that might help.
Bob
Copy link to clipboard
Copied
Will implement these leads.
Thank you.
Stay tuned.
I can say this will initially pertain to singular and/or groups of non-linked frames.
But being aware of broader applications may come in handy for future use.
Copy link to clipboard
Copied
Some snippets that might help:
if (app.selection[0].hasOwnProperty("baselineShift"))
is a quick way to determine if the user has clicked inside a text frame with the content tool. The actual selection could be a insertion point, character, word, line, etc., but they all have a baseline shift property. So if you want to operated on all of the text in that frame (plus anything that might overflow), get the parentStory. (Confession: I have stolen this snippet from someone else on this forum, but I forget who)
If the result is false, the user might have selected a single page object or a collection of page objects. You might want to loop through them, testing the constructor.name to find the textFrames. If you encounter a group, get allPageItems of the group and loop through that array to find the textFrames. Once you have the textFrames, it's a short jump to the parentStory.
Creative users can use the selection tools in surprising ways before running a script...
Bob
Copy link to clipboard
Copied
.parentStory saved the day.
From there on I was able to accomplish exactly what I needed, essentially getting rid of a object style (that affected the text frame and the text properties) and replacing said object style with a script instead.
Final script below fyi.
Thanks again, it’s really appreciated.
var sel = app.selection;
for(var n=0;n<sel.length;n++)
{
sel
.parentStory.properties = {
tracking:0,
kerningMethod:"Metrics",
pointSize:6,
leading:6,
baselineShift:0,
appliedFont:"Gotham Narrow",
fontStyle:"Medium",
fillColor:"Black",
fillTint:100,
horizontalScale:100,
verticalScale:100,
skew:0,
spaceAfter:0,
spaceBefore:0,
justification:Justification.CENTER_ALIGN,
skew:0,
allowArbitraryHyphenation:true,
hyphenateAcrossColumns:true,
hyphenateAfterFirst:1,
hyphenateBeforeLast:1,
hyphenateCapitalizedWords:true,
hyphenateLadderLimit:0,
hyphenateLastWord:true,
hyphenateWordsLongerThan:3,
hyphenation:true,
hyphenationZone:"0.1 in",
};
sel
.textFramePreferences.properties = { autoSizingReferencePoint: AutoSizingReferenceEnum.TOP_CENTER_POINT,
autoSizingType: AutoSizingTypeEnum.HEIGHT_ONLY,
insetSpacing: "0pt",
ignoreWrap:true,
useMinimumWidthForAutoSizing:true,
minimumWidthForAutoSizing:"0 in",
useFixedColumnWidth:true,
textColumnFixedWidth:".3367 in",
verticalJustification:VerticalJustification.TOP_ALIGN,
};
};