Copy link to clipboard
Copied
Hello -
I made an Adobe Illustrator Javascript,
To summarize it, it "copy-paste" some values/data from a .csv file.
With one of the textfield, I don't know why but the "All Caps" option/setting (from the "Character" palette is turn on.
I don't know only why that specific textfield.
tried already a lot of thinngs… But I dn't understand why.
Would it be possible to avoid it by turnning "off" that option via Javascript?
Can this option (so from the "Character" palette be "reach" via Javascript?
Below in this message I saw already some stuff, but nothing seems to work.
I tried it via:
var textRange_DC = textFrame_DC.textRange;
textRange_DC.characterAttributes.allCaps = false;
textRange_DC.characterAttributes.capitalization = Capitalization.NORMAL;
but it doesn't work,
After I tried something like:
// Try to turn off All Caps using the menu command
app.executeMenuCommand("allCaps");
// Try to change to lowercase and then back to original case
// First, store the original content
var originalContent_DC = textFrame_DC.contents;
// Change to lowercase
app.executeMenuCommand("lowercase");
But it didn't work neither…
May be via a temporary "action" ceated on the fly.
But then the question, which "parameter" is "All Caps"? Since they are 18 parameters (in a "handmade" action when I clic that option)
Stuff that I have found, but it doesn't seem toi help.
FontCapsOption.ALLCAPS | All Caps |
FontCapsOption.ALLSMALLCAPS | All Smallcaps |
FontCapsOption.NORMALCAPS | Normal Caps |
FontCapsOption.SMALLCAPS | Small Caps |
EDIT:
Wanted to also add. The above is a display change to the text. The text may internally be set as "Lorem Ipsum" but changed to display setting as All Caps would display as "LOREM IPSUM" while maintaining the internal text as "Lorem Ipsum". To access the Change case functionality you can either do a heavier coding approach to change the text contents or use the executeMenuCommand to access those commands.
https://ten-artai.com/illustrator-ccver-22-menu-commands-list/
app.executeMenuCommand("UpperCase Change Case Item")
app.executeMenuCommand("LowerCase Change Case Item")
app.executeMenuCommand("Title Case Change Case Item")
app.executeMenuCommand("Sentence case Change Case Item")
The reasons your initial code did not work are as follows:
Similar topics:
Here is the code to set the capit
...Copy link to clipboard
Copied
The reasons your initial code did not work are as follows:
Similar topics:
Here is the code to set the capitalization to its normal state.
/**
* @File set capitalization sample
* https://community.adobe.com/t5/illustrator-discussions/quot-all-caps-quot-option-turn-quot-on-quot-by-default-when-java-scripting-a-textfield-why-how-to/td-p/15495039
* @Version 1.0.0
* @author sttk3.com
*/
(function() {
if(app.documents.length <= 0) {return ;}
var doc = app.documents[0] ;
var sel = doc.selection ;
if(sel.length <= 0) {return ;}
var textFrame_DC = sel[0] ;
var textRange_DC = textFrame_DC.textRange ;
setCapitalization(textRange_DC, FontCapsOption.NORMALCAPS) ;
})() ;
/**
* set capitalization to text range
* @Param {TextRange} textRange - target TextRange
* @Param {FontCapsOption} dstCapitalization - Justification to apply
* @Returns {void}
*/
function setCapitalization(textRange, dstCapitalization) {
var appliedCharacterStyle = textRange.characterStyles[0] ;
var targetPropName = 'capitalization' ;
var styleCapitalization = appliedCharacterStyle[targetPropName] ;
var swapTable = {
'FontCapsOption.ALLCAPS': FontCapsOption.NORMALCAPS,
'FontCapsOption.NORMALCAPS': FontCapsOption.ALLCAPS,
'FontCapsOption.ALLSMALLCAPS': FontCapsOption.SMALLCAPS,
'FontCapsOption.SMALLCAPS': FontCapsOption.ALLSMALLCAPS
} ;
if(styleCapitalization === dstCapitalization) {
appliedCharacterStyle[targetPropName] = swapTable[dstCapitalization.toString()] ;
textRange[targetPropName] = dstCapitalization ;
appliedCharacterStyle[targetPropName] = styleCapitalization ;
} else {
textRange[targetPropName] = dstCapitalization ;
}
}
Copy link to clipboard
Copied
Hi sttk3 -
Super thx.
I managed to make it work w/ your help (of course).
Top, super thx.
enjoy your day
- Dimitri
Copy link to clipboard
Copied
Thank you for notifying, please select it as the Correct Answer once it's resolved.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now