我正在尝试选择一些文本并单击“小写字母”按钮。这里有一些尝试:
app.activeDocument.textFrames[0].texts.appliedCharacterStyle.capitalization = Capitalization.SMALL_CAPS;
不起作用:“对根样式的请求无效”
var myCharacterStyle = new CharacterStyle();
myCharacterStyle.capitalization = Capitalization.SMALL_CAPS;
app.activeDocument.textFrames[0].texts[0].applyCharacterStyle(myCharacterStyle);
不起作用:“方法'applyCharacterStyle'的参数'using'的值无效。应为CharacterStyle,但什么也没收到。”
我应该怎么做?
最佳答案
如果要更改默认的“ [无]”,则需要先创建新的字符样式
//First create a new character style
var newCharacterStyle = document.characterStyles.add(text.appliedCharacterStyle);
if(text.appliedCharacterStyle!=null){
newCharacterStyle.basedOn = text.appliedCharacterStyle;
}
text.appliedCharacterStyle = newCharacterStyle;
//then apply capitalization
newCharacterStyle.capitalization = Capitalization.SMALL_CAPS;