Skip to main content
Inspiring
February 23, 2022
질문

ExtendScript resolveメソッドについて

  • February 23, 2022
  • 2 답변들
  • 631 조회

toSource()メソッドを使うと

resolve("/document[@id=1])

等が戻ってきますが

このresolve()メソッドについて知りたいと思っています。

 

例えば、最初のスプレッドに名前が001のテキストフレームが有った場合

resolve("/document[@location=first]/spread[@location=first]/text-frame[@name=\"001\"]").contents = "test";

で内容を変更できます。

 

便利な使い方があるかもしれないと思ったのですが

InDesign Scripting SDKにも情報が無いようです。

 

 

 

 

 

이 주제는 답변이 닫혔습니다.

2 답변

Ten A
Community Expert
Community Expert
February 24, 2022

ajabonさんの言ってるのはこれかな?

 

alert(app.selection[0].resolve(AnchorPoint.CENTER_ANCHOR, CoordinateSpaces.PARENT_COORDINATES))

 

異なるコーディネートスペースでの座標値を取り出すのに利用するやつです。ここでは座標系を正規化するためのレゾルバとして機能します。

 

とりあえず、なんでもいいんでオブジェクトを選択した状態で以下を実行します。

 

 

var tgs = app.selection[0].toSource();
alert(tgs);
alert(eval(tgs));

 


選択したオブジェクトはtoSourceでresolveメソッドとXPathに落とされます。
そしてその結果をダイレクトにevalしちゃうと元のオブジェクト参照が得られます。resolveメソッドは単純にオブジェクトツリーの記述を解析して該当するオブジェクトを得るためのメソッドです。うまく使おうとするとオブジェクトのidを調べておいたりとなかなか回りくどい処理を書く必要があったりしますので、多くの場合ストレートにオブジェクトツリーを操作したほうが素直なコード構成になるでしょう。
InDesignのXPath自体の実装レベルは限定されたものなので、そういった意味でも使い勝手はよろしくないようにも思います。

 

alert(resolve('/document[@id=4]//story[@id=290]/character[130] to /document[@id=4]//story[@id=290]/character[138]'))…変なテストコード残したままだった(^-^;

Inspiring
February 24, 2022

>異なるコーディネートスペースでの座標値を取り出すのに利用する

 

というのは、InDesign Scripting SDKに載っている方ですね。


>resolveメソッドは単純にオブジェクトツリーの記述を解析して該当するオブジェクトを得るためのメソッドです。

 

なるほど!

 

テーブルのセルを指定するのに少し便利かもです。
例えば行が2、列が2のテーブルがあるとすると

// 範囲を指定する場合は()で囲む必要が有るよう
resolve("(/document[@location=last]/spread[@location=last]/text-frame[@location=last]/table[@location=last]/cell[@name=\"0:0\"] to /document[@location=last]/spread[@location=last]/text-frame[@location=last]/table[@location=last]/cell[@name=\"1:1\"])").contents = "test";

でセルの内容を変更

@locationにはfirst以外にlastも指定できるようです。

どこかに仕様が載っていると良いのですが

 

コミュニティのこちらの投稿
https://community.adobe.com/t5/indesign-discussions/get-parent-story-of-a-table-row-column-or-cell/td-p/10428734#11007574
Marc Autretさんのresolveメソッドの使い方は興味深いかもしれません。

Inspiring
February 25, 2022

少し調べてみました。

ドキュメントにテキストフレームが複数あるとして

// 全てのテキストフレーム(配列)
resolve("/document[@location=first]/text-frame");

// anyItem()
resolve("/document[@location=first]/text-frame[@location=any]");

// firstItem()
resolve("/document[@location=first]/text-frame[@location=first]");

// item(index)
var index = app.activeDocument.textFrames.firstItem().index;
resolve("/document[@location=first]/text-frame[" + index + "]");

// itemByID(id)
var id = app.activeDocument.textFrames.firstItem().id;
resolve("/document[@location=first]/text-frame[@id=" + id + "]");

// itemByName(name)
app.activeDocument.textFrames.firstItem().name = "test";
var name = app.activeDocument.textFrames.firstItem().name;
resolve("/document[@location=first]/spread[@location=first]/text-frame[@name=\"" + name + "\"]");

// itemByRange(from,to) 
// ()で囲まれる
var from = 0;
var to = -1;
resolve("(/document[@location=first]/text-frame[" + from + "] to /document[@location=first]/text-frame[" + to + "])");

// lastItem()
resolve("/document[@location=first]/text-frame[@location=last]");

// middleItem()
resolve("/document[@location=first]/text-frame[@location=middle]");

// nextItem(obj)
// objがapp.activeDocument.textflames.firstItem()とすると
resolve("/document[@location=first]/text-frame[@location=first]/text-frame[@location=next]");

// previousItem(obj)
// objがapp.activeDocument.textflames.lastItem()とすると
resolve("/document[@location=first]/text-frame[@location=last]/text-frame[@location=previous]");

 

ajabon grinsmith
Community Expert
Community Expert
February 23, 2022

別のCoodinateSpacesの座標を取得するのに使ったことがあります。