Created
August 21, 2024 00:45
-
-
Save UskeS/24375eb4dffec6fb9d86ca4c320609ab to your computer and use it in GitHub Desktop.
[Illustrator] Change text color to specific color swatch - Japanese Edition (original: Adobe Community)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// オリジナル版:https://community.adobe.com/t5/illustrator-discussions/change-text-to-specific-colour-swatch-illustrator-javascript/m-p/14810409?profile.language=en#M417576 | |
(function () { | |
if (0 === app.documents.length) { | |
return alert('Please open a document and try again.'); | |
} | |
var docRef = app.activeDocument; | |
var textFrame = docRef.selection[0]; | |
if ( undefined == textFrame || textFrame.typename !== 'TextFrame' ) { | |
return alert('Please select a text frame and try again.'); | |
} | |
var swatchGroups = docRef.swatchGroups; | |
for (var i = 0; i < swatchGroups.length; i++) { | |
var swatches = swatchGroups[i].getAllSwatches(); | |
swatchesLoop: | |
for (var j = 0; j < swatches.length; j++) { | |
switch (swatches[j].name) { | |
// 以下のcase文は除外 | |
case '[なし]': | |
case '[レジストレーション]': | |
case 'ホワイト': | |
case 'ブラック': | |
continue swatchesLoop; | |
default: | |
addSwatchNameToText(textFrame, swatches[j]); | |
break; | |
} | |
} | |
} | |
function addSwatchNameToText(text, swatch) { | |
var col = text.textRange.characters.add('\r' + swatch.name); | |
col.fillColor = swatch.color; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment