Skip to content

Instantly share code, notes, and snippets.

@sttk3
Created October 27, 2023 10:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sttk3/f223401c2eb5930687cabcd2d06bf535 to your computer and use it in GitHub Desktop.
Save sttk3/f223401c2eb5930687cabcd2d06bf535 to your computer and use it in GitHub Desktop.
記憶したフォントを選択しているテキストに適用するIllustrator用スクリプト。captureFont.jsxとセットで利用する
/**
* @file captureFont.jsxで記憶したフォントを選択しているテキストに適用する
* @version 1.0.0
* @author sttk3.com
* @copyright © 2023 sttk3.com
*/
//@target 'illustrator'
//@targetengine 'com.sttk3.attributes'
var globalTargetFont ;
(function() {
if(app.documents.length <= 0) {return ;}
var sel = getTextSelection() ;
if(sel.length <= 0) {return ;}
// 対象のフォントがなければ終了する
if(globalTargetFont == null) {return ;}
try {
for(var i = 0, len = sel.length ; i < len ; i++) {
sel[i].textFont = globalTargetFont ;
}
} catch(e) {
return ;
}
})() ;
/**
* selectionを常にtextRangeのArrayとして返す
* @return {Array<TextRange>} 選択なしの場合は[]
*/
function getTextSelection() {
var sel = app.selection ;
var selLength = sel.length ;
var res = [] ;
switch(sel.constructor.name) {
case 'Array' :
if(!sel[0]) {return res ;}
for(var i = 0 ; i < selLength ; i++) {
var itemType = sel[i].constructor.name ;
if(itemType == 'TextFrame') {
res.push(sel[i].textRange) ;
} else if(itemType == 'TextRange') {
res.push(sel[i]) ;
}
}
break ;
case 'TextRange' :
res.push(sel) ;
break ;
}
return res ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment