Illustrator用のExtendScriptです.
画像に合番を振ります.
目次 効果 コード
効果
Illustratorにおいて,各リンク・埋め込み画像に合番を振ります.
合番で対応する画像ファイル名がテキストファイルに書き出されます.(デフォルトではmacOSデスクトップ.必要に応じて変数saveDir
を書き換えればよい.)
コード
recursiveLayerUnlock (activeDocument);var placedItems = activeDocument.placedItems ;var rasterItems = activeDocument.rasterItems ;selectImages (placedItems);selectImages (rasterItems);var sel = activeDocument.selection ;for (var i = 0 ; i < sel.length ; i++){ makeRectangle (sel, i); putSequence (sel, i); listFileName (sel, i); } function recursiveLayerUnlock (l ){ for (var i = 0 ; i < l.layers .length ; i++){ l.layers [i].locked = false ; if (hasSubLayer (l)) { recursiveLayerUnlock (l.layers [i]); } } } function hasSubLayer (l ){ return l.layers .length > 0 } function selectImages (imgs ){ for (var i = 0 ; i < imgs.length ; i++){ try { imgs[i].locked = false ; imgs[i].selected = true ; }catch (e){} } } function makeRectangle (sel, i ){ var gb = sel[i].geometricBounds ; var x = gb[0 ]; var y = gb[1 ]; var w = gb[2 ] - x; var h = y - gb[3 ]; var rect = activeDocument.pathItems .rectangle (y, x, w, h); rect.filled = false ; rect.stroked = true ; rect.strokeWidth = 1 ; } function putSequence (sel, i ){ var tf = activeDocument.textFrames .add (); tf.contents = formatSeq (i); tf.paragraphs [0 ].size = 18 ; tf.top = calcMiddle (sel[i], tf); tf.left = calcCenter (sel[i]); tf.paragraphs [0 ].justification = Justification .CENTER ; } function formatSeq (i ){ return "(" + parseInt (i + 1 ) + ")" ; } function calcCenter (ph ){ return (ph.geometricBounds [0 ] + ph.geometricBounds [2 ])/2 ; } function calcMiddle (ph, tf ){ return (tf.geometricBounds [1 ] + tf.geometricBounds [3 ] + ph.geometricBounds [1 ] + ph.geometricBounds [3 ])/2 ; } function listFileName (sel, i ){ var ls = [] ls[i] = sel[i].file .fullName ; saveDir = Folder .desktop .fullName + "/" ; saveFilePath = saveDir + app.activeDocument .name + ".txt" ; for (var i in ls){textWriter (saveFilePath, parseInt (i + 1 ) + "\t" + sel[i].file .fullName );} } function textWriter (filepath, str ){ var fileObj = new File (filepath); fileObj.open ("a" ); fileObj.encoding = "UTF-8" ; fileObj.lineFeed = "Unix" ; fileObj.writeln (str); fileObj.close (); fileObj = null ; }