DTP駆け込み寺

[ 返信 ]

イラレスクリプトでテキストフレーム作成2

前スレッド(http://www.dtptemple.org/imgbbs/index.php?mode=thread&id=21011&page=1

スクリプトが完成しました。助言あっての完成です。
ありがとうございます!

ぶちぶちに切れたテキストを全選択してスクリプトを走らせる事で、選択した範囲の高さと幅を計算してテキストフレーム作成し、スタイルを維持したままフレーム内にテキストを流し込む。

app.executeMenuCommand('releaseMask');
app.executeMenuCommand('ungroup');

DOC = activeDocument;
SEL = DOC.selection;

RCT = SEL[0].visibleBounds;
x1 = RCT[0];
y1 = RCT[1];
x2 = RCT[2];
y2 = RCT[3];
for ( N=1 ; N<SEL.length ; N++ ) {
BND = SEL[N].visibleBounds;
if ( BND[0] < x1 ) x1 = BND[0] ;
if ( BND[1] > y1 ) y1 = BND[1] ;
if ( BND[2] > x2 ) x2 = BND[2] ;
if ( BND[3] < y2 ) y2 = BND[3] ;
}
RCT[0] = x1 ;
RCT[1] = y1 ;
RCT[2] = x2 ;
RCT[3] = y2 ;
W = x2 - x1 ;
H = y2 - y1 ;
Xa = RCT[0] ;

//テキストフレームを作成
var rectRef = DOC.pathItems.rectangle(RCT[3], RCT[0], W, H);
var areaTextRef = DOC.textFrames.areaText(rectRef,TextOrientation.HORIZONTAL,undefined,false);
areaTextRef.contents = "";

//テキストを格納
for (var i=0; i < SEL.length; i++){
SEL[i].textRange.move(areaTextRef, ElementPlacement.PLACEATBEGINNING);
SEL[i].remove();
SEL[i] = areaTextRef;
}
doc.selection = sel;

[21027] 柴犬 (2022/12/02 Fri 13:33)

  1. [21027] イラレスクリプトでテキストフレーム作成2 柴犬 2022/12/02 13:33