...

XML - Adobe

by user

on
Category: Documents
64

views

Report

Comments

Transcript

XML - Adobe
ADOBE® INDESIGN® CS6
ADOBE INDESIGN CS6
スクリプティングガイド:
VBSCRIPT
 2012 Adobe Systems Incorporated. All rights reserved.
Adobe® InDesign® CS6 スクリプティングガイド:VBScript
ドキュメントの更新ステータス
(ドキュメント全体。各章の更新ステータスについては、それぞれの章を参照してください)
CS6
更新
ドキュメント全体で CS5 から CS6 への変更およびバージョン 7.0 から 8.0 への変更。
If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is
furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any
such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note
that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user
license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as
a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or
inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law.
The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please
be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any
actual organization.
Adobe, the Adobe logo, Creative Suite, and InDesign are either registered trademarks or trademarks of Adobe Systems Incorporated
in the United States and/or other countries. Microsoft and Windows are either registered trademarks or trademarks of Microsoft
Corporation in the United States and/or other countries. Mac OS is a trademark of Apple Computer, Incorporated, registered in the
United States and other countries. All other trademarks are the property of their respective owners.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users. The Software
and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer
Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as
applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer
Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as
Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein.
Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose,
CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if
appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance
Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1
through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be
incorporated by reference.
目次
1
はじめに . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
このマニュアルに掲載されているスクリプトの使用方法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
スクリプトの構造について . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
詳細情報 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2
スクリプティング機能 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
スクリプトの環境設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
現在のスクリプトの取得 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
スクリプトのバージョン対応 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ターゲットの設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
コンパイル . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
インタープリターによる実行 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
13
13
13
DoScript メソッドの使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
DoScript へのパラメーターの渡し方 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
DoScript からの戻り値 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
DoScript を使用した取り消しの制御 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
スクリプトラベルの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
起動時におけるスクリプトの自動実行 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3
ドキュメント . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
ドキュメントの基本的な操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
新規ドキュメントの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ドキュメントを開く . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ドキュメントの保存 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ドキュメントを閉じる . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
19
19
20
21
基本的なページレイアウト . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページサイズとドキュメントの長さの定義 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
裁ち落としと印刷可能領域の定義 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページのマージンと段組の設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ペーストボードの外観の変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ガイドとグリッド . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
測定単位と定規の変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ドキュメントプリセットの定義と適用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
マスタースプレッドの設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XMP メタデータの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ドキュメントテンプレートの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
透かしの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
21
22
23
25
25
28
29
31
32
33
38
ページサイズとレイアウトの調整 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページの選択 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページのサイズ変更とフレーム調整 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページの変形 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
マスターページオーバーレイ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40
40
40
41
42
調整型レイアウトの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
柔軟性のあるレイアウトの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3
目次
4
ガイドベースのレイアウトへのガイドの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
オブジェクトベースのレイアウトへの制約の設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
代替レイアウトの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
コンテンツの収集とドロップ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
ドキュメントのプリント . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページ範囲を使用したプリント . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
print preferences の設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
プリントプリセットを使用したプリント . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
46
46
50
PDF としてのドキュメントの書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PDF の書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PDF 書き出しオプションの設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
グレースケール PDF の書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページ範囲の PDF 書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページごとの PDF 書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
インタラクティブ機能を使用した PDF の書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PDF フォームとしての書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
50
50
51
52
53
53
54
54
EPS としてのページの書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
すべてのページの EPS 書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページ範囲の EPS 書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ファイル名を指定した EPS 書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
56
56
56
57
EPub の書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
現在のドキュメントの書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
EPub 書き出しオプションの設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4
レイヤーの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
レイヤーオブジェクトモデルについて . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
レイヤーのスクリプト操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーの参照 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーの削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーの移動 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーの複製 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーの結合 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーへのページアイテムの割り当て . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
レイヤーのプロパティの設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
62
62
63
64
64
64
64
65
65
ページアイテムの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
ページアイテムの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
ページアイテムの形状 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
ページアイテムのグループ化 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
ページアイテムの複製と移動 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
複合パスの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
パスファインダー機能の使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページアイテムのシェイプの変換 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ページアイテムの配置 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70
71
72
73
73
ページアイテムの変形 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
transform メソッドの使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
変形マトリックスの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
座標スペース . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
変形の基点 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
位置の解決 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ポイントの変形 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74
74
75
77
78
80
80
目次
5
変形の繰り返し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
サイズ変更とフレーム調整 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
アーティクルの使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アーティクルリストの取得 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
新しいアーティクルの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アーティクルの削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アーティクルの順序変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アーティクルへの新規メンバーの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アーティクルのメンバーの順序変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アーティクルからのメンバーの削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
83
83
83
83
83
84
84
84
テキストと組版 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
テキストの入力と読み込み . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストフレームの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ストーリーとテキストフレーム . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストの置換 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
特殊文字の挿入 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
85
85
86
86
87
87
テキストの配置とテキスト読み込み環境設定の指定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
テキストの書き出しとテキスト書き出し環境設定の指定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
テキストオブジェクト . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキスト選択の操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストの移動とコピー . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストオブジェクトと反復処理 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
95
96
97
99
テキストフレームの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストフレームのリンク . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストフレームのリンク解除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ストーリーからのフレームの削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ストーリー内のすべてのフレームの分割 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
アンカー付きフレームの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストフレームをコンテンツに合わせる . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
100
100
100
101
102
102
103
テキストのフォーマット . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストデフォルトの設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
フォントの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
フォントの適用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストプロパティの変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストカラーの変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
スタイルの作成と適用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
スタイルの削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
段落スタイルや文字スタイルの読み込み . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
104
104
108
108
109
111
112
113
113
テキストの検索と変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
検索/変更の環境設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストの検索と変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
テキストフォーマットの検索と変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
grep の使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
字形検索の使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
113
114
114
115
115
117
表の操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
パステキストの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
自動修正の使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
脚注の追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
段抜きと段分割 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
目次
6
テキスト環境設定の指定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
リンクストーリーの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
リンクストーリーの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
リンクストーリーのオプションの変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
よくある質問 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
124
124
124
125
ユーザーインターフェイス . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
ダイアログボックスの概要 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
最初の InDesign ダイアログボックスの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
「Hello World」へのユーザーインターフェイスの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
さらに複雑なユーザーインターフェイスの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
ScriptUI の使用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
ScriptUI を使用したプログレスバーの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8
イベント . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
イベントスクリプトモデルについて . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
イベントプロパティとイベントの伝達について . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
イベントリスナーの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
「afterNew」イベントリスナーの例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
「beforePrint」イベントリスナーの例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
選択に関連するイベントリスナーの例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
「onIdle」イベントリスナーの例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
9
メニュー . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
メニューモデルについて . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
ローカライゼーションとメニュー名 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
スクリプトからのメニューアクションの実行 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
メニューやメニュー項目の追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
メニューとイベント . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
scriptMenuAction の操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
さらに複雑なメニュースクリプティングの例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
10
プリフライトの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
プリフライトプロファイルの調査 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
プリフライトプロファイルの一覧表示 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
プリフライトルールの一覧表示 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
プリフライトデータオブジェクトの一覧表示 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
154
155
155
155
プリフライトプロファイルの読み込み . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
プリフライトプロファイルの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
ルールの追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
プロファイルの処理 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
カスタムルール . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
使用可能なルール . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
ADBE_BlankPages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
ADBE_BleedSlug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
目次
7
ADBE_BleedTrimHazard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_Colorspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_CrossReferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_FontUsage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_ImageColorManagement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_ImageResolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_PageCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_PageSizeOrientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_ScaledGraphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_ScaledType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_SmallText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_SpotColorSetup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_StrokeRequirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_TextOverrides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADBE_TransparencyBlending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
162
163
163
163
163
164
164
164
165
165
165
165
165
166
166
ダイナミックドキュメントの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
ムービーとサウンドの読み込み . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
ボタンの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
マルチステートオブジェクトの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
アニメーションの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
基本的なアニメーション . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
タイミング設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
変形のアニメーション化 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
モーションプリセット . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
デザインオプション . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
キーフレーム . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
172
172
173
176
176
177
177
ページ効果の追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
12
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
概要 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
InDesign での XML スクリプティングの推奨事項 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
XML 要素のスクリプティング . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 環境設定の指定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 読み込み環境設定の指定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML の読み込み . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML タグの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML タグのロード . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML タグの保存 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 要素の作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 要素の移動 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 要素の削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 要素の複製 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 構造からのアイテムの削除 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML コメントの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 処理命令の作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 属性の操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ストーリーの操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML の書き出し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
180
180
180
181
181
181
181
182
182
182
182
182
183
183
183
184
184
レイアウトへの XML 要素の追加 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
XML 要素とページアイテムやテキストとの関連付け . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
既存レイアウトのマークアップ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
目次
8
XML 要素へのスタイルの適用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
XML 表の操作 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
13
XML ルール . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
概要 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
XML ルールを使用する利点 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
XML ルールのプログラミングモデル . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
XML ルールの例 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
サンプルドキュメントのセットアップ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
最初の XML ルール . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ルールを使用した XML 構造の変更 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ルールを使用した XML 要素の複製 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ルールと XML 属性 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
複数の一致ルールの適用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML 要素の検索 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ルールを使用した XML 要素の抽出 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ルールを使用したフォーマットの適用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XML ルールを使用したページアイテムの作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
199
199
200
204
205
206
207
208
211
212
216
XML ルールを使用した表の作成 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
XML ルールプロセッサーオブジェクトのスクリプティング . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
14
変更のトラック . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
変更のトラック . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
トラックされた変更への移動 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
トラックされた変更の適用と取り消し . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
トラックされた変更に関する情報 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
219
219
220
220
変更のトラックの環境設定 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
1
はじめに
章の更新ステータス
CS6
変更なし
このマニュアルでは、次の作業を行う方法について説明します。

Adobe® InDesign® のスクリプティング環境の操作

高度なスクリプティング機能の使用

ドキュメントに関連する基本的な作業(マスタースプレッドの設定、プリント、書き出しなど)

ページアイテム(長方形、楕円形、グラフィックの線、多角形、テキストフレーム、グループ)の操作

InDesign ドキュメントのテキストや書式の操作(テキストの検索と変更など)

ダイアログボックスなどのユーザーインターフェイスアイテムの作成

メニューのカスタマイズや追加と、メニューアクションの作成

ユーザーインターフェイスのイベントに対する応答

XML の操作(XML 要素の作成、XML の読み込み、レイアウトへの XML 要素の追加など)

XML ルール(InDesign で XML を高速かつ簡単に操作できる新しいスクリプティング機能)の適用
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。スクリプト環境に接続したり、
スクリプトエディターから InDesign スクリプトオブジェクトモデルを表示したりする方法については、
『Adobe InDesign スクリプティングチュートリアル』を参照してください。
このマニュアルに掲載されているスクリプトの使用方法
このマニュアルに掲載されているスクリプトのほとんどは、完全なスクリプトではありません。このマニュ
アルの説明内容に関連するスクリプトから特定部分のみを抜粋した、断片的なスクリプトです。このマニュ
アルに掲載されているスクリプト行をコピーして、スクリプトエディタに貼り付けることができますが、ス
クリプトを実行するには、さらに編集が必要になります。また、このマニュアルからコピーしたスクリプト
には、(マニュアルのレイアウトにより)改行などの文字が含まれている可能性があることに注意してくださ
い。このような文字が含まれていると、スクリプトを正常に実行できません。
このマニュアルに掲載されているすべてのスクリプトの Zip アーカイブは、InDesign のスクリプティング
ホームページ(http://www.adobe.com/jp/products/indesign/scripting/index.html)で入手できます。アーカイブ
をダウンロードして展開したら、該当するスクリプト言語に対応するフォルダーを、InDesign フォルダー内
の Scripts フォルダーの下にある Scripts Panel フォルダーに移動します。これで、InDesign のスクリプトパネル
からスクリプトを実行できます。
9
第 1 章 はじめに
スクリプトの構造について
10
スクリプトの構造について
サンプルスクリプトはすべて、main、mySetup、mySnippet、myTeardown(関数)などの共通のテンプレー
トを使用して記述されています。この記述方式は、自動化テストとパブリケーションを簡略化するためのも
のです。通常はスクリプトをこのように構築する必要はありません。スクリプト作成者の関心を引くと思わ
れるスクリプトの断片は、mySnippet 関数内に記述されています。
詳細情報
InDesign スクリプティングに関するユーザーフォーラム(http://www.adobeforums.com)でも、InDesign ス
クリプティングに関する情報が入手できます。このフォーラムでは、質問をしたり、質問に答えたり、新た
に作成したスクリプトを別のユーザーと共有したりできます。このフォーラムでは、多数のサンプルスクリ
プトが提供されています。
スクリプティング機能
2
章の更新ステータス
CS6
更新
12 ページの「スクリプトのバージョン対応」および 3 つの副節を、更新、修正および明確化しました。
この章では、InDesign のスクリプティング環境に関連するスクリプティングテクニックを紹介します。
InDesign のスクリプトモデルを構成するオブジェクトのほとんどは、アプリケーションのデフォルトやド
キュメントを操作するためのオブジェクトですが、この章ではまず、スクリプトそのものを制御する方法に
ついて説明します。
この章の内容は、次のとおりです。

ScriptPreferences オブジェクトとそのプロパティ

実行中のスクリプトへの参照の取得

以前のバージョンのスクリプトオブジェクトモデルに基づいたスクリプトの実行

DoScript メソッドを使用したスクリプトの実行

スクリプトラベルの操作

InDesign の起動時におけるスクリプトの自動実行
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、該当するスクリ
プト言語で InDesign のスクリプトを作成、インストール、実行する方法を理解しているものとして説明を行
います。
スクリプトの環境設定
ScriptPreferences オブジェクトには、InDesign でのスクリプトの実行方法に関連するオブジェクトやプロ
パティが用意されています。次の表に、ScriptPreferences オブジェクトの各プロパティの詳細を示します。
プロパティ
説明
EnableRedraw
スクリプトパネルからスクリプトを実行している最中の画面の再描画をオンま
たはオフにします。
ScriptsFolder
Scripts フォルダーへのパス。
ScriptsList
使用可能なスクリプトのリスト。このプロパティは、次に示すような配列の配
列を返します。
[[fileName, filePath], ...]
fileName はスクリプトファイルの名前を表し、filePath はスクリプトへのフ
ルパスを表します。この機能を使用すれば、目的のスクリプトがインストール
されているどうかを確認できます。
11
第 2 章 スクリプティング機能
現在のスクリプトの取得
プロパティ
説明
UserInteractionLevel
このプロパティは、ユーザーに表示する警告やダイアログボックスを制御しま
す。このプロパティを idUserInteractionLevels.idNeverInteract に設定する
と、警告やダイアログボックスは一切表示されなくなります。
idUserInteractionLevels.idInteractWithAlerts に設定すると、警告は有効
になりますが、ダイアログボックスは無効になります。
idUserInteractionLevels.idInteractWithAll に設定すると、警告とダイアロ
グボックスは通常どおりに表示されます。警告の表示をオフにする機能は、ス
クリプトでドキュメントを開く場合に便利です。InDesign では、フォントやリ
ンク先のグラフィックファイルが見つからないと警告が表示されることがあり
ます。このプロパティを idUserInteractionLevels.idNeverInteract に設定し
てからドキュメントを開き、スクリプトを終了する直前にプロパティを元に戻
せば(idUserInteractionLevels.idInteractWithAll に設定すれば)、警告が
表示されるのを避けられます。
Version
使用中のスクリプティング環境のバージョン。詳しくは、12 ページの「スクリ
プトのバージョン対応」を参照してください。このプロパティは、アプリケー
ションのバージョンと同じではないことに注意してください。
12
現在のスクリプトの取得
現在のスクリプトへの参照を取得するには、アプリケーションオブジェクトの ActiveScript プロパティを使
用します。このプロパティは、現在のスクリプトが保存されている場所を基準にしてファイルやフォルダー
を検索する場合に役立ちます。次のスクリプトにその例を示します(チュートリアルスクリプトの
ActiveScript より)。
Set myInDesign = CreateObject("InDesign.Application")
myActiveScript = myInDesign.ActiveScript
MsgBox ("The current script is: " & myActiveScript)
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
myParentFolder = myFileSystemObject.GetFile(myActiveScript).ParentFolder
MsgBox ("The folder containing the active script is: " & myParentFolder)
スクリプトエディタでスクリプトをデバッグしている場合は、ActiveScript プロパティを取得しようとする
とエラーが発生します。ActiveScript プロパティで返されるのは、スクリプトパレットから実行したスクリ
プトのみです。
スクリプトのバージョン対応
InDesign では、以前のバージョンの InDesign スクリプトオブジェクトモデルに基づいて作成されたスクリプ
トを実行できます。新しいバージョンの InDesign で古いスクリプトを実行する場合は、次の点に注意する必
要があります。

ターゲットの設定 - スクリプトを実行する InDesign のバージョン(現在のバージョン)をターゲットに
設定する必要があります。13 ページの「ターゲットの設定」に説明するとおり、ターゲットの設定方法
は言語によって異なります。

コンパイル - この段階では、スクリプトで使用されている名前が InDesign で認識できるスクリプト ID に
マッピングされます。13 ページの「コンパイル」に説明するとおり、コンパイルの方法は言語によって
異なります。

インタープリターによる実行 - この段階では、スクリプト ID が InDesign の適切なハンドラーに関連付け
られます。これにより InDesign は、以前のバージョンのスクリプトオブジェクトモデルに基づいて作成
されたスクリプトも正しく解釈できるようになります。そのためには、スクリプトでアプリケーション
のスクリプト環境設定に古いオブジェクトモデルを明示的に設定するか(13 ページの「インタープリ
第 2 章 スクリプティング機能
スクリプトのバージョン対応
13
ターによる実行」に示すとおり)、次のようにスクリプトパネル用のフォルダーからスクリプトを実行し
ます。
フォルダー
スクリプトの InDesign バージョン
Version 8.0 Scripts
CS6
Version 7.0 Scripts
CS5 および CS5.5
Version 6.0 Scripts
CS4
Version 5.0 Scripts
CS3
Version 2.0 Scripts
CS2
ターゲットの設定
スクリプトを実行する InDesign のバージョン(現在のバージョン)が、スクリプトでターゲットとして明示
的または暗黙的に設定されている必要があります。スクリプトパネルからスクリプトを実行すると暗黙的に
ターゲットが設定されます。
Visual Basic アプリケーションや VBScript で明示的にターゲットを設定するには、CreateObject メソッドを使
用します。
Rem
Set
Rem
Set
Rem
Set
Target InDesign CS6 Roman:
myApp = CreateObject("InDesign.Application.CS6")
Target InDesign CS6 J:
myApp = CreateObject("InDesign.Application.CS6_J")
Target the last version of InDesign that was launched:
myApp = CreateObject("InDesign.Application")
コンパイル
Visual Basic アプリケーションのコンパイルでは、以前のバージョンのタイプライブラリを参照してバージョ
ンの対応を行うことができます。以前のバージョンのタイプライブラリを生成するには、Application オブ
ジェクトの PublishTerminology メソッドを使用します。これによって、アプリケーションの環境設定フォル
ダー内の Scripting Support フォルダーにある、DOM のバージョンと同じ名前のフォルダーにタイプライブ
ラリが生成されます。例えば、CS5 用語説明を C:¥Documents and Settings¥< ユーザー名 >¥Application
Data¥Adobe¥InDesign¥Version 8.0-J¥ja_JP¥Scripting Support¥8.0 フォルダーに生成するには、次のように
します。
Set myApp = CreateObject("InDesign.Application")
Rem Publish the InDesign CS5 type library (version 7.0 DOM)
myApp.PublishTerminology(7.0)
VBScript はプリコンパイルされません。コンパイルでは、解釈に使用するように設定されている DOM のバー
ジョンに基づいて、対応するタイプライブラリが自動的に生成されて参照されます。
インタープリターによる実行
インタプリタで使用するスクリプトオブジェクトモデルのバージョンを取得したり設定したりするには、
InDesign アプリケーションオブジェクトの ScriptPreferences オブジェクトを使用します。デフォルトでは、
アプリケーションの現在のバージョンに設定されており、変更されるまでそのバージョンが使用されます。
例えば、スクリプトオブジェクトモデルのバージョンを CS5(7.0)に変更するには、次のようにします。
Set myInDesign = CreateObject("InDesign.Application")
Rem Set to 7.0 DOM
myInDesign.ScriptPreferences.Version = 7.0
第 2 章 スクリプティング機能
DoScript メソッドの使用
14
DoScript メソッドの使用
DoScript メソッドを使用すると、スクリプトの中で別のスクリプトを実行することができます。このメソッ
ドには、有効なスクリプトコードを表す文字列か、ディスク上のスクリプトファイルを指定できます。指定
するスクリプトは、現在のスクリプトと同じ言語であっても、異なる言語であってもかまいません。使用で
きる言語はプラットフォームによって異なります。Mac OS® の場合は AppleScript または JavaScript を実行で
きます。Windows® の場合は VBScript または JavaScript を実行できます。
DoScript メソッドは、次の様々な場合に利用できます。

使用したい機能が、メインのスクリプト言語ではサポートされておらず、別の言語でサポートされてい
る場合。例えば、VBScript にはファイルブラウザーやフォルダーブラウザーを表示する機能はありません
が、JavaScript にはこの機能が用意されています。AppleScript では三角関数(サインやコサイン)の計算
に時間がかかる場合がありますが、JavaScript では高速に処理できます。JavaScript では、Microsoft® Excel
スプレッドシートのセルの内容を照会することはできませんが、AppleScript や VBScript を使用すれば行
うことができます。どの場合も、別の言語で断片的なスクリプトコードを作成して DoScript メソッドで
実行すれば、メインのスクリプト言語の制約を回避することができます。

スクリプトを動的に生成して実行する場合。実行時にスクリプトの文字列を動的に生成して、DoScript
メソッドで実行することができます。この方法は、選択されている内容や作成するオブジェクトの属性
に基づいてダイアログボックスやパネルをカスタマイズしたい場合などに適しています。

オブジェクトにスクリプトを埋め込む場合。DoScript メソッドを使用すれば、オブジェクトの label プ
ロパティに文字列として保存されているスクリプトを実行することができます。このテクニックを利用
すると、特定のパラメーターに基づいてレイアウトプロパティを制御したり内容を更新したりするスク
リプトを、オブジェクト自体に埋め込むことができます。また、XML 要素にも、属性またはコンテンツ
としてスクリプトを埋め込むことができます。17 ページの「起動時におけるスクリプトの自動実行」を
参照してください。
DoScript へのパラメーターの渡し方
DoScript で実行するスクリプトにパラメーターを渡すには、次のようにします(チュートリアルスクリプト
の DoScriptParameters より)
。
Set myInDesign = CreateObject("InDesign.Application")
myJavaScript = "alert(""First argument: "" + arguments[0] + ""¥rSecond argument: "" +
arguments[1]);"
myInDesign.DoScript myJavaScript, idScriptLanguage.idJavascript, Array("Hello from DoScript",
"Your message here.")
myVBScript = "msgbox arguments(1), vbOKOnly, ""First argument: "" & arguments(0)"
myInDesign.DoScript myVBScript, idScriptLanguage.idVisualBasic, Array("Hello from DoScript",
"Your message here.")
DoScript からの戻り値
次のスクリプトは、DoScript で実行されるスクリプトから値を返す方法を示しています。この例では、文字
列として実行される JavaScript を使用していますが、スクリプトファイルも同様に使用できます。また、この
例で返す値は 1 つですが、配列を使用すると複数の値を返すことができます(完全なスクリプトについては、
DoScriptReturnValues スクリプトを参照してください)。
第 2 章 スクリプティング機能
DoScript を使用した取り消しの制御
15
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Set myDestinationPage = myDocument.Pages.Add(idLocationOptions.idAfter, myPage)
myPageIndex = myDestinationPage.Name
myID = myTextFrame.Id
myJavaScript = "var myDestinationPage = arguments[1];" & vbCr
myJavaScript = myJavaScript & "myID = arguments[0];" & vbCr
myJavaScript = myJavaScript & "var myX = arguments[2];" & vbCr
myJavaScript = myJavaScript & "var myY = arguments[3];" & vbCr
myJavaScript = myJavaScript & "var myPageItem =
app.documents.item(0).pages.item(0).pageItems.itemByID(myID);" & vbCr
myJavaScript = myJavaScript &
"myPageItem.duplicate(app.documents.item(0).pages.item(myDestinationPage));" & vbCr
Rem Create an array for the parameters we want to pass to the JavaScript.
myArguments = Array(myID, myPageIndex, 0, 0)
Set myDuplicate = myInDesign.DoScript(myJavaScript, idScriptLanguage.idJavascript, myArguments)
Rem myDuplicate now contains a reference to the duplicated text frame.
Rem Change the text in the duplicated text frame.
myDuplicate.contents = "Duplicated text frame."
別の方法として、アプリケーションの ScriptArgs オブジェクトを使用して別のスクリプトから値を取得する
方法があります(この名前は、「script arguments」を縮めたものです)。次のスクリプトにその例を示します
(完全なスクリプトについては、DoScriptScriptArgs を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
myJavaScript = "app.scriptArgs.setValue(""ScriptArgumentA"", ""This is the first script argument
value."");" & vbCr
myJavaScript = myJavaScript & "app.scriptArgs.setValue(""ScriptArgumentB"", ""This is the second
script argument value."");" & vbCr
myInDesign.DoScript myJavaScript, idScriptLanguage.idJavascript
myScriptArgumentA = myInDesign.ScriptArgs.GetValue("ScriptArgumentA")
myScriptArgumentB = myInDesign.ScriptArgs.GetValue("ScriptArgumentB")
MsgBox "ScriptArgumentA: " & myScriptArgumentA & vbCr & "ScriptArgumentB: " & myScriptArgumentB
myVBScript = "Set myInDesign = CreateObject(""InDesign.Application"")" & vbCr
myVBScript = myVBScript & "myInDesign.ScriptArgs.SetValue ""ScriptArgumentA"", ""This is the
first script argument value.""" & vbCr
myVBScript = myVBScript & "myInDesign.ScriptArgs.SetValue ""ScriptArgumentB"", ""This is the
second script argument value."""
myInDesign.DoScript myVBScript, idScriptLanguage.idVisualBasic
myScriptArgumentA = myInDesign.ScriptArgs.GetValue("ScriptArgumentA")
myScriptArgumentB = myInDesign.ScriptArgs.GetValue("ScriptArgumentB")
MsgBox "ScriptArgumentA: " & myScriptArgumentA & vbCr & "ScriptArgumentB: " & myScriptArgumentB
DoScript を使用した取り消しの制御
InDesign では、ほとんどすべてのアクションを取り消すことができます。ただし、行ったアクションのほと
んどすべてがディスクに書き出されるので、犠牲も伴います。ユーザーインターフェイスのツールを使用し
た通常の作業では、取り消しによって問題が発生することはありません。しかし、短時間に何千ものアク
ションの実行が可能であるスクリプトの場合、ディスクへのアクセスが絶えず繰り返されているので、パ
フォーマンスに深刻な影響を与える場合があります。
DoScript メソッドには、このパフォーマンスの問題を解決するために 2 つのパラメーターが用意されてお
り、InDesign の取り消し動作に関してスクリプトの実行方法を制御することができます。次の例で、これら
のパラメーターを示します。
第 2 章 スクリプティング機能
スクリプトラベルの操作
16
Rem Given a script "myVBScript" and an array of parameters "myParameters"...
myInDesign.DoScript myVBScript, idScriptLanguage.idVisualBasic, myParameters,
idUndoModes.idFastEntireScript, "Script Action"
Rem idUndoModes can be:
Rem idUndoModes.idAutoUnto: Add no events to the Undo queue.
Rem idUndoModes.idEntireScript: Put a single event in the Undo queue.
Rem idUndoModes.idFastEntireScript: Put a single event in the Undo queue.
Rem idUndoModes.idScriptRequest: Undo each script action as a separate event.
Rem The last parameter is the text that appears in the Undo menu item.
スクリプトラベルの操作
InDesign の多くのスクリプトオブジェクトには、label プロパティが用意されています。例えば、ページア
イテム(長方形、楕円形、グループ、多角形、テキストフレーム、グラフィックの線)、テーブルのセル、ド
キュメント、ストーリー、ページなどのオブジェクトでは、label プロパティが使用できます。このプロパ
ティには、大量のテキストを保存することができます。
ページアイテムのラベルは、スクリプトラベルパネルを使用して表示、入力、編集できます(次の図を参照。
このパネルを表示するには、ウィンドウ/ユーティリティ/スクリプトラベルを選択します)。また、スクリ
プトを使用して、オブジェクトにラベルを追加したり、スクリプトのラベルを読み取ったりすることもでき
ます。ストーリー、ページ、段落スタイルなどの多くのオブジェクトは、スクリプトラベルパネルを使用し
てラベルを設定したり表示したりすることはできません。
label プロパティには、タブ区切りやカンマ区切りのテキスト、HTML、XML など、あらゆる形式のテキスト
データを含めることができます。スクリプトもテキストであるため、label プロパティに保存することができ
ます。
名前を持つアイテム(段落スタイル、カラー、レイヤーなど)がその name を使用して参照できるように、
ページアイテムはその label を使用して参照することができます。label プロパティを使用してアイテムを参
照する例を、次のスクリプトに示します(完全なスクリプトについては、ScriptLabel を参照してください)。
Set myDocument = myInDesign.Documents.Add
Set myPage = myDocument.Pages.Item(1)
myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
Rem Create 10 random page items.
For i = 1 To 10
myX1 = myGetRandom(0, myPageWidth, False)
myY1 = myGetRandom(0, myPageHeight, False)
myX2 = myGetRandom(0, myPageWidth, False)
myY2 = myGetRandom(0, myPageHeight, False)
Set myRectangle = myPage.Rectangles.Add
myRectangle.GeometricBounds = Array(myY1, myX1, myY2, myX2)
If myGetRandom(0, 1, True) > 0 Then
myRectangle.Label = "myScriptLabel"
End If
Next
Count = 0
For i = 1 To myPage.PageItems.Count
第 2 章 スクリプティング機能
起動時におけるスクリプトの自動実行
17
If myPage.PageItems.Item(i).Label = "myScriptLabel" Then
Count = Count + 1
End If
Next
MsgBox ("Found " & CStr(Count) & " page items with the label.")
Rem This function gets a random number in the range myStart to myEnd.
Function myGetRandom(myStart, myEnd, myInteger)
Rem Here's how to generate a random number from a given range:
Rem Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
If myInteger = True Then
myGetRandom = Int(((myEnd - myStart + 1) * Rnd) + myStart)
Else
myGetRandom = ((myEnd - myStart + 1) * Rnd) + myStart
End If
End Function
また、label プロパティがサポートされているオブジェクトでは、カスタムラベルもサポートされています。
スクリプトでカスタムラベルを設定するには、InsertLabel メソッドを使用します。カスタムラベルを抽出
するには、ExtractLabel メソッドを使用します。次のスクリプトにその例を示します(チュートリアルスク
リプトの CustomLabel より)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Set myPage = myDocument.Pages.Item(1)
myDocument.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myDocument.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
Set myRectangle = myPage.Rectangles.Add
myRectangle.GeometricBounds = Array(72, 72, 144, 144)
Rem Insert a custom label using insertLabel. The first parameter is the
Rem name of the label, the second is the text to add to the label.
myRectangle.InsertLabel "CustomLabel", "This is some text stored in a custom label."
Rem Extract the text from the label and display it in an message box.
myString = myRectangle.ExtractLabel("CustomLabel")
MsgBox ("Custom label contained: " + myString)
起動時におけるスクリプトの自動実行
InDesign の起動時にスクリプトを自動実行させるには、Scripts フォルダーの下にあるスタートアップ用の
フォルダーである Startup Scripts フォルダーにスクリプトファイルを保存します(詳しくは、『Adobe
InDesign スクリプティングチュートリアル』の「スクリプトのインストール」を参照してください)。
ドキュメント
3
章の更新ステータス
CS6
変更
この章で説明する作業実行方法のリストを更新しました。
42 ページの「調整型レイアウトの作成」という節の追加。
46 ページの「コンテンツの収集とドロップ」という節の追加。
52 ページの「グレースケール PDF の書き出し」という副節の追加。
54 ページの「PDF フォームとしての書き出し」という副節の追加。
古い情報となった CS5 の新機能に関する言及を、40 ページの「ページサイズとレイアウトの調整」、40 ページの「ページのサイズ
変更とフレーム調整」および 41 ページの「ページの変形」から削除。
InDesign で行う作業の多くは、ドキュメントに関連する作業です。例えば、ドキュメントの作成、保存、プ
リント、書き出しを行ったり、ドキュメントにページアイテム、カラー、スタイル、テキストなどを配置し
たりします。ドキュメントに関連する作業のほとんどは、InDesign スクリプティングを使用して自動化でき
ます。
この章では、次の作業を行う方法について説明します。


基本的なドキュメント管理作業

新規ドキュメントの作成

ドキュメントのオープン

ドキュメントの保存

ドキュメントのクローズ
基本的なページレイアウト操作

ページサイズやドキュメントの長さの設定

裁ち落としと印刷可能領域の定義

ページの段組やマージンの指定

ペーストボードの外観の変更

ガイドやグリッドの使用

測定単位や定規の原点の変更

ドキュメントプリセットの定義と適用

マスターページ(マスタースプレッド)の設定

テキストフォーマットのデフォルトの設定

XMP メタデータ(ファイルに関する情報)の追加

ドキュメントテンプレートの作成

透かしの作成

ページ別に異なるサイズの適用(複数のページサイズ)
18
第 3 章 ドキュメント
ドキュメントの基本的な操作
19

様々なデバイスまたはサイズや方向の異なるドキュメントに対応するための、ページに対する柔軟なレ
イアウトフォーマットの適用

ドキュメントのプリント

Adobe PDF としてのドキュメントの書き出し

EPS としてのドキュメントのページごとの書き出し

ePub ファイルとしてのドキュメントの書き出し
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。
ドキュメントの基本的な操作
ドキュメントのオープン、クローズ、保存といった操作は、ドキュメントに対する最も基本的な操作です。
ここでは、スクリプティングでこれらの操作を実行する方法について説明します。
新規ドキュメントの作成
新規ドキュメントを作成する方法を、次のスクリプトに示します (完全なスクリプトについては、
MakeDocument を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
ドキュメントプリセットを使用してドキュメントを作成するには、Add メソッドのオプションのパラメー
ターを使用して、ドキュメントプリセットを指定します。次のスクリプトにその例を示します (完全なスク
リプトについては、MakeDocumentWithPreset を参照してください)。
Rem Creates a new document using the specified document preset.
Set myInDesign = CreateObject("InDesign.Application")
Rem Replace "myDocumentPreset" in the following line with the name
Rem of the document preset you want to use.
Set myDocument = myInDesign.Documents.Add(True,
myInDesign.DocumentPresets.Item("myDocumentPreset"))
ドキュメントウィンドウを表示せずにドキュメントを作成することもできます。次のスクリプトにその例を
示します(チュートリアルスクリプトの MakeDocumentWithParameters より)
。
Rem
Set
Rem
Rem
Set
Rem
Set
Creates a new document using the specified document preset.
myInDesign = CreateObject("InDesign.Application")
Replace "myDocumentPreset" in the following line with the name
of the document preset you want to use.
myDocument = myInDesign.Documents.Add(False)
To show the window:
myWindow = myDocument.Windows.Add
スクリプトの処理によっては、ドキュメントウィンドウを非表示にすることで実行速度がより速くなること
があります。
ドキュメントを開く
既存のドキュメントを開く方法を、次のスクリプトに示します (完全なスクリプトについては、
OpenDocument を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Open("c:¥myTestDocument.indd")
第 3 章 ドキュメント
ドキュメントの基本的な操作
20
、
Open メソッドの showing window パラメーターを false に設定すると(デフォルトでは true になっています)
ドキュメントが表示されないように(非表示に)なります。スクリプトのパフォーマンスを向上させたい場
合は、この方法を利用したいと思うでしょう。非表示のドキュメントを表示するには、新規ウィンドウを作
成します。次のスクリプトにその例を示します(チュートリアルスクリプトの OpenDocumentInBackground
より)。
Rem
Rem
Set
Set
Rem
Rem
Rem
Rem
Set
Opens an existing document in the background, then shows the document.
You'll have to fill in your own file path.
myInDesign = CreateObject("InDesign.Application")
myDocument = myInDesign.Open("c:¥myTestDocument.indd", False)
At this point, you can do things with the document without showing
the document window. In some cases, scripts will run faster when
the document window is not visible.
When you want to show the hidden document, create a new window.
myLayoutWindow = myDocument.Windows.Add
ドキュメントの保存
InDesign のユーザーインターフェイスでは、ファイルを保存するにはファイル/保存を選択し、別の名前で
ファイルを保存するにはファイル/別名で保存を選択します。InDesign スクリプティングで同じ処理を行う
には、Save メソッドを使用します。次のスクリプトにその例を示します(チュートリアルスクリプトの
SaveDocument より)
。
Rem If the active document has been changed since it was last saved, save it.
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.ActiveDocument.Modified = True Then
myInDesign.ActiveDocument.Save
End If
Save メソッドには、オプションのパラメーターが 2 つあります。最初のパラメーター(to)には、保存先の
ファイルを指定します。2 つ目のパラメーター(stationery)は、true に設定するとドキュメントがテンプ
レートとして保存されます。次のスクリプトにその例を示します(チュートリアルスクリプトの
SaveDocumentAs より)。
Rem If the active document has not been saved (ever), save it.
Set myInDesign = CreateObject("InDesign.Application")
If myDocument.Saved = False Then
Rem If you do not provide a file name,
Rem InDesign displays the Save dialog box.
myInDesign.ActiveDocument.Save "c:¥myTestDocument.indd"
End If
ドキュメントをテンプレートとして保存することもできます。次のスクリプトにその例を示します(チュー
トリアルスクリプトの SaveAsTemplate より)
。
Rem Save the active document as a template.
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.ActiveDocument.Saved = True Then
Rem Convert the file name to a string.
myFileName = myInDesign.ActiveDocument.FullName
Rem If the file name contains the extension ".indd",
Rem change it to ".indt".
If InStr(1, myFileName, ".indd") <> 0 Then
myFileName = Replace(myFileName, ".indd", ".indt")
End If
Else
Rem If the document has not been saved, then give it a
Rem default file name/file path.
myFileName = "c:¥myTestDocument.indt"
End If
myInDesign.ActiveDocument.Save myFileName, True
第 3 章 ドキュメント
基本的なページレイアウト
21
ドキュメントを閉じる
Close メソッドはドキュメントを閉じます。次のスクリプトにその例を示します(チュートリアルスクリプ
トの CloseDocument より)。
Set myInDesign = CreateObject("InDesign.Application")
myInDesign.ActiveDocument.Close
Rem Note that you could also use:
Rem myInDesign.Documents.Item(1).Close
Close メソッドには、最大で 2 つのオプションパラメーターを指定できます。次のスクリプトにその例を示
します(チュートリアルスクリプトの CloseWithParameters より)
。
Rem Use idSaveOptions.idYes to save the document,idSaveOptions.idNo
Rem to close the document without saving, or idSaveOptions.idAsk to
Rem display a prompt. If you use idSaveOptions.idYes, you'll need to
Rem provide a reference to a file to save to in the second parameter Rem(SavingIn).
Set myInDesign = CreateObject("InDesign.Application")
Rem If the file has not been saved, display a prompt.
If myInDesign.ActiveDocument.Saved <> True Then
myInDesign.ActiveDocument.Close idSaveOptions.idAsk
Rem Or, to save to a specific file name:
Rem myFile = "c:¥myTestDocument.indd"
Rem myInDesign.ActiveDocument.Close idSaveOptions.idYes, myFile
Else
Rem If the file has already been saved, save it.
myInDesign.ActiveDocument.Close idSaveOptions.idYes
End If
開いているすべてのドキュメントを保存せずに閉じることもできます。次のスクリプトにその例を示します
(チュートリアルスクリプトの CloseAll より)。
Set myInDesign = CreateObject("InDesign.Application")
For myCounter = myInDesign.Documents.Length To 1 Step -1
myInDesign.Documents.Item(myCounter).Close idSaveOptions.idNo
Next
基本的なページレイアウト
それぞれのドキュメントでは、デフォルトのページサイズ、割り当てられたページ数、裁ち落としと印刷可
能領域、段組とマージンによって、コンテンツを配置するための領域が定義されます。これらのパラメー
ターはすべて、スクリプティングで操作することができます。次の各節でその例を示します。
ページサイズとドキュメントの長さの定義
InDesign のユーザーインターフェイスで新規ドキュメントを作成するときには、デフォルトのページサイズ、
ページ数、ページの方向、見開きページにするかどうかなどを指定できます。InDesign スクリプティングで
ドキュメントを作成するには Documents.Add メソッドを使用しますが、上記のような設定は指定できません。
ドキュメントを作成した後で、DocumentPreferences オブジェクトを使用して設定を行います。次のスクリ
プトにその例を示します(チュートリアルスクリプトの DocumentPreferences より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
With myDocument.DocumentPreferences
.PageHeight = "800pt"
.PageWidth = "600pt"
.PageOrientation = idPageOrientation.idLandscape
.PagesPerDocument = 16
End With
第 3 章 ドキュメント
基本的なページレイアウト
22
注意 : Application オブジェクトにも、DocumentPreferences というオブジェクトがあります。このオブジェ
クトのプロパティを設定することで、ページの高さや幅などのアプリケーションデフォルトを設定できます。
また、個別のページサイズを設定することもできます。詳しくは、「ページサイズとレイアウトの調整」を参
照してください。
裁ち落としと印刷可能領域の定義
InDesign で使用される裁ち落としまたは印刷可能領域という用語は、プリントしたり PDF に書き出したりす
ることが可能な、ページマージンの外部の領域のことを表します。一般に、こうした領域は、ページ枠から
はみ出して配置されるオブジェクトがある場合や(裁ち落とし)、ジョブ情報やドキュメント情報を含めてお
きたい場合に(印刷可能領域)使用されます。この 2 つの領域は、プリントしたり書き出したりするかどう
かを、ページ枠とは独立に設定することができます。例えば、ドキュメントの最終プリントでは、印刷可能
領域に配置した情報を除外してプリントすることができます。新規ドキュメントの裁ち落としと印刷可能領
域を設定する方法を、次のスクリプトに示します (完全なスクリプトについては、BleedAndSlug を参照して
ください)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Rem The bleed and slug properties belong to the DocumentPreferences object.
With myDocument.DocumentPreferences
Rem Bleed
.DocumentBleedBottomOffset = "3p"
.DocumentBleedTopOffset = "3p"
.DocumentBleedInsideOrLeftOffset = "3p"
.DocumentBleedOutsideOrRightOffset = "3p"
Rem Slug
.SlugBottomOffset = "18p"
.SlugTopOffset = "3p"
.SlugInsideOrLeftOffset = "3p"
.SlugRightOrOutsideOffset = "3p"
End With
この例のように、裁ち落としの距離がすべて等しい場合は、代わりに DocumentBleedUniformSize プロパ
ティを使用することもできます。次のスクリプトにその例を示します(チュートリアルスクリプトの
UniformBleed より)。
Rem Create a new document.
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Rem The bleed properties belong to the documentPreferences object.
With myDocument.DocumentPreferences
Rem Bleed
.DocumentBleedTopOffset = "3p"
.DocumentBleedUniformSize = True
End With
印刷可能領域の距離がすべて等しい場合は、DocumentSlugUniformSize プロパティが使用できます。次のス
クリプトにその例を示します(チュートリアルスクリプトの UniformSlug より)。
Rem Create a new document.
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Rem The slug properties belong to the documentPreferences object.
With myDocument.DocumentPreferences
Rem Slug:
.SlugTopOffset = "3p"
.DocumentSlugUniformSize = True
End With
裁ち落としや印刷可能領域は、幅や高さを設定できるだけでなく、その領域を表すガイドのカラーも設定で
きます。このプロパティは、DocumentPreferences オブジェクトではなく、PasteboardPreferences オブジェ
第 3 章 ドキュメント
基本的なページレイアウト
23
クトに用意されています。次のスクリプトにその例を示します(チュートリアルスクリプトの
BleedSlugGuideColors より)
。
Set myInDesign = CreateObject("InDesign.Application")
With myInDesign.ActiveDocument.PasteboardPreferences
Rem Any of InDesign's guides can use the UIColors constants...
.BleedGuideColor = idUIColors.idCuteTeal
.SlugGuideColor = idUIColors.idCharcoal
Rem ...or you can specify an array of RGB values
Rem(with values from 0 to 255)
Rem .BleedGuideColor = Array(0, 198, 192)
Rem .SlugGuideColor = Array(192, 192, 192)
End With
ページのマージンと段組の設定
ドキュメントの各ページでは、それぞれ独自のマージンや段組を設定することができます。InDesign スクリ
プティングでは、各ページの MarginPreferences オブジェクトのプロパティを使用して、それらを設定でき
ます。次のサンプルスクリプトでは、新規ドキュメントを作成してから、マスタースプレッドのすべての
ページに対してマージンと段組を設定しています (完全なスクリプトについては、PageMargins を参照して
ください)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
With myDocument.Pages.Item(1).MarginPreferences
.ColumnCount = 3
Rem columnGutter can be a number or a measurement string.
.ColumnGutter = "1p"
.Top = "4p"
.Bottom = "6p"
Rem When document.documentPreferences.facingPages = true,
Rem "left" means inside "right" means outside.
.Left = "6p"
.Right = "4p"
End With
特定のページのマージンを設定するには、そのページの margin preferences を使用します。次のスクリプトに
その例を示します(チュートリアルスクリプトの PageMarginsForOnePage より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
With myDocument.Pages.Item(1).MarginPreferences
.ColumnCount = 3
Rem columnGutter can be a number or a measurement string.
.ColumnGutter = "1p"
.Top = "4p"
.Bottom = "6p"
Rem When document.documentPreferences.facingPages = true,
Rem "left" means inside "right" means outside.
.Left = "6p"
.Right = "4p"
End With
InDesign では、対応するマージンの合計よりも小さなページは作成できません。つまり、ページの幅は、左
右のページマージンの合計よりも大きくする必要があり、ページの高さは、上下のマージンの合計よりも大
きくする必要があります。InDesign のユーザーインターフェイス(新規ドキュメントダイアログボックス)
を使用して非常に小さなページ(新聞に掲載する広告など)を作成する場合は、ドキュメントのデフォルト
のページマージンフィールドに新しい値を入力することで、正しいマージンサイズが簡単に設定できます。
しかし、スクリプティングで小さなページを作成する場合は、このように簡単にはいきません。なぜなら、
ドキュメントの作成時には、アプリケーションのデフォルトの margin preferences が適用されるからです。こ
のマージンは、マスターページを含む、ドキュメント内のすべてのページに適用されます。ドキュメントの
margin preferences を変更した場合、影響を受けるのは新規ページのみで、既存のページには影響はありませ
第 3 章 ドキュメント
基本的なページレイアウト
24
ん。設定しようとしたページの高さや幅が、既存のどのページの対応するマージンの合計よりも小さい場合、
ページサイズは変更されません。
これを解決するには、2 つの方法があります。1 つは、既存のページのマージンを設定してからページサイズ
を変更する方法です。次のスクリプトにその例を示します(チュートリアルスクリプトの
PageMarginsForSmallPages より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
myDocument.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myDocument.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
With myDocument.MarginPreferences
.Top = 0
.Left = 0
.Bottom = 0
.Right = 0
.ColumnCount = 1
.ColumnGutter = 0
End With
Rem The following assumes that your default document contains a single page.
With myDocument.Pages.Item(1).MarginPreferences
.Top = 0
.Left = 0
.Bottom = 0
.Right = 0
.ColumnCount = 1
.ColumnGutter = 0
End With
Rem The following assumes that your default master spread contains two pages.
With myDocument.MasterSpreads.Item(1).Pages.Item(1).MarginPreferences
.Top = 0
.Left = 0
.Bottom = 0
.Right = 0
.ColumnCount = 1
.ColumnGutter = 0
End With
With myDocument.MasterSpreads.Item(1).Pages.Item(2).MarginPreferences
.Top = 0
.Left = 0
.Bottom = 0
.Right = 0
.ColumnCount = 1
.ColumnGutter = 0
End With
myDocument.DocumentPreferences.PageHeight = "1p"
myDocument.DocumentPreferences.PageWidth = "6p"
もう 1 つは、アプリケーションのデフォルトの margin preferences を変更してからドキュメントを作成する方
法です。次のスクリプトにその例を示します(チュートリアルスクリプトの ApplicationPageMargins より)
。
第 3 章 ドキュメント
基本的なページレイアウト
25
Set myInDesign = CreateObject("InDesign.Application")
With myInDesign.MarginPreferences
Rem Save the current application default margin preferences.
myY1 = .Top
myX1 = .Left
myY2 = .Bottom
myX2 = .Right
Rem Set the application default margin preferences.
.Top = 0
.Left = 0
.Bottom = 0
.Right = 0
End With
Rem Create a new example document to demonstrate the change.
Set myDocument = myInDesign.Documents.Add
myDocument.DocumentPreferences.PageHeight = "1p"
myDocument.DocumentPreferences.PageWidth = "6p"
Rem Reset the application default margin preferences to their former state.
With myInDesign.MarginPreferences
.Top = myY1
.Left = myX1
.Bottom = myY2
.Right = myX2
End With
ペーストボードの外観の変更
ペーストボードとは、InDesign のページやスプレッドの周囲にある領域のことです。この領域は、ページア
イテムや作業メモを一時的に置いておく場所として利用できます。ペーストボードのサイズやカラーは、ス
クリプティングを使用して変更することができます。PreviewBackgroundColor プロパティを使用することで、
プレビューモードでのペーストボードのカラーを設定できます。次のスクリプトにその例を示します
(チュートリアルスクリプトの PasteboardPreferences より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
With myDocument.PasteboardPreferences
Rem You can use either a number or a measurement
Rem string to set the space above/below.
.MinimumSpaceAboveAndBelow = "12p"
Rem You can set the preview background color (which you'll only see
Rem in Preview mode) to any of the predefined UIColor constants...
.PreviewBackgroundColor = idUIColors.idGrassGreen
Rem ...or you can specify an array of RGB values (with values from 0 to 255)
Rem .PreviewBackgroundColor = Array(192, 192, 192)
End With
ガイドとグリッド
ガイドやグリッドを使用すると、ドキュメントページにオブジェクトを簡単に配置できるようになります。
他のユーザーに提供するテンプレートを作成する場合は、これらのアイテムを適切に配置することで、ユー
ザーの作業効率を高めることができます。
ガイドの定義
InDesign のガイドを使用すれば、ドキュメントページでオブジェクトを簡単に配置できるようになります。
ガイドを使用する方法を、次のスクリプトに示します (完全なスクリプトについては、Guides を参照してく
ださい)
。
第 3 章 ドキュメント
基本的なページレイアウト
26
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
With myDocument.Pages.Item(1)
Set myMarginPreferences = .MarginPreferences
Rem Place guides at the margins of the page.
With .Guides.Add
.Orientation = idHorizontalOrVertical.idVertical
.Location = myMarginPreferences.Left
End With
With .Guides.Add
.Orientation = idHorizontalOrVertical.idVertical
.Location = (myPageWidth - myMarginPreferences.Right)
End With
With .Guides.Add
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = myMarginPreferences.Top
End With
With .Guides.Add
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = (myPageHeight - myMarginPreferences.Bottom)
End With
Rem Place a guide at the vertical center of the page.
With .Guides.Add
.Orientation = idHorizontalOrVertical.idVertical
.Location = (myPageWidth / 2)
End With
Rem Place a guide at the horizontal center of the page.
With .Guides.Add
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = (myPageHeight / 2)
End With
End With
水平方向のガイドは、指定のページにのみ表示するか、スプレッド内のすべてのページにまたがって表示す
るかを設定できます。InDesign スクリプティングでは、FitToPage プロパティを使用してこの設定を制御でき
ます。このプロパティは、垂直方向のガイドには適用されません。
スクリプティングでも、ユーザーインターフェイスを使用した場合と同様に、ガイドのレイヤー、カラー、
表示/非表示を変更できます。次のスクリプトにその例を示します(チュートリアルスクリプトの
GuideOptions より)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
With myDocument.Pages.Item(1)
Set myMarginPreferences = .MarginPreferences
Rem Place guides at the margins of the page.
With .Guides.Add
.Orientation = idHorizontalOrVertical.idVertical
.Location = myMarginPreferences.Left
End With
With .Guides.Add
.Orientation = idHorizontalOrVertical.idVertical
.Location = (myPageWidth - myMarginPreferences.Right)
End With
With .Guides.Add
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = myMarginPreferences.Top
End With
第 3 章 ドキュメント
基本的なページレイアウト
27
With .Guides.Add
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = (myPageHeight - myMarginPreferences.Bottom)
End With
Rem Place a guide at the vertical center of the page.
With .Guides.Add
.Orientation = idHorizontalOrVertical.idVertical
.Location = (myPageWidth / 2)
End With
Rem Place a guide at the horizontal center of the page.
With .Guides.Add
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = (myPageHeight / 2)
End With
End With
ガイドの作成には、スプレッドやマスタースプレッドの CreateGuides メソッドを使用することもできます。
次のスクリプトにその例を示します(チュートリアルスクリプトの CreateGuides より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Rem Parameters (all optional): row count, column count, row gutter,
Rem column gutter,guide color, fit margins, remove existing, layer.
Rem Note that the createGuides method does not take an RGB array
Rem for the guide color parameter.
myDocument.Spreads.Item(1).CreateGuides 4, 4, "1p", "1p", idUIColors.idGray, True, True,
myDocument.Layers.Item(0)
grid preferences の設定
ドキュメントグリッドやベースライングリッドのプロパティを制御するには、GridPreferences オブジェク
トのプロパティを設定します。次のスクリプトにその例を示します(チュートリアルスクリプトの
DocumentAndBaselineGrid より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Rem Set the document measurement units to points.
myDocument.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myDocument.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
Rem Set up grid preferences.
With myDocument.GridPreferences
.BaselineStart = 56
.BaselineDivision = 14
.BaselineGridShown = True
.HorizontalGridlineDivision = 14
.HorizontalGridSubdivision = 5
.VerticalGridlineDivision = 14
.VerticalGridSubdivision = 5
.DocumentGridShown = True
End With
ガイドやグリッドへのスナップ
ドキュメントのグリッドやガイドのスナップ設定は、すべて GuidePreferences オブジェクトや
GridPreferences オブジェクトのプロパティとして用意されています。ガイドやグリッドのスナッププロパ
ティを設定する方法を、次のスクリプトに示します (完全なスクリプトについては、GuideGridPreferences を
参照してください)。
第 3 章 ドキュメント
基本的なページレイアウト
28
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.ActiveDocument
With myDocument.guidePreferences
.GuidesInBack = True;
.GuidesLocked = False;
.GuidesShown = True;
.GuidesSnapTo = True;
End With
With myDocument.gridPreferences {
.DocumentGridShown = False;
.DocumentGridSnapTo = True;
//Objects "snap" to the baseline grid when
//guidePreferences.guideSnapTo is set to true.
.BaselineGridShown = True;
End With
}
測定単位と定規の変更
これまでのサンプルスクリプトでは、測定文字列(特定の測定単位を InDesign に使用させるための文字列。
例えば、8.5 インチの場合は「8.5i」)を使用してきました。これは、スクリプトの実行時に別の測定単位系が
使用されている可能性を考慮しているためです。
スクリプトで使用する測定単位系を指定するには、ドキュメントの ViewPreferences オブジェクトを使用し
ます。次のスクリプトにその例を示します(チュートリアルスクリプトの ViewPreferences より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.ActiveDocument
With myDocument.ViewPreferences
Rem Measurement unit choices are:
Rem * idMeasurementUnits.idAgates
Rem * idMeasurementUnits.idPicas
Rem * idMeasurementUnits.idPoints
Rem * idMeasurementUnits.idInches
Rem * idMeasurementUnits.idInchesDecimal
Rem * idMeasurementUnits.idMillimeters
Rem * idMeasurementUnits.idCentimeters
Rem * idMeasurementUnits.idCiceros
Rem * idMeasurementUnits.idCustom
Rem If you set the the vertical or horizontal measurement units
Rem to idMeasurementUnits.idCustom, you can also set a custom
Rem ruler increment (in points) using:
Rem .HorizontalCustomPoints = 15
Rem .VerticalCustomPoints = 15
Rem Set horizontal and vertical measurement units to points.
.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
.VerticalMeasurementUnits = idMeasurementUnits.idPoints
End With
スクリプト全体で特定の測定単位系を使用する場合は、スクリプトの先頭で測定単位を変更し、スクリプト
の最後で元の測定単位に戻します。次のスクリプトにその例を示します(チュートリアルスクリプトの
ResetMeasurementUnits より)
。
第 3 章 ドキュメント
基本的なページレイアウト
29
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.ActiveDocument
With myDocument.ViewPreferences
myOldXUnits = .HorizontalMeasurementUnits
myOldYUnits = .VerticalMeasurementUnits
.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
.VerticalMeasurementUnits = idMeasurementUnits.idPoints
End With
Rem At this point, you can perform any series of script actions that
Rem depend on the measurement units you've set. At the end of the
Rem script, reset the units to their original state.
With myDocument.ViewPreferences
.HorizontalMeasurementUnits = myOldXUnits
.VerticalMeasurementUnits = myOldYUnits
End With
ドキュメントプリセットの定義と適用
InDesign のドキュメントプリセットを使用すれば、よく使用するドキュメント設定情報(ページサイズ、
ページマージン、段組、裁ち落としと印刷可能領域など)を保存して、適用することができます。新規ド
キュメントを作成する際には、ドキュメントプリセットに基づいてドキュメントを作成することができます。
既存の値をコピーしてプリセットを作成する
既存のドキュメントの設定をサンプルとして使用してドキュメントプリセットを作成するには、ドキュメン
トプリセットで使用したいドキュメント設定プロパティが含まれているドキュメントを開き、その後で次の
スクリプトを実行します(チュートリアルスクリプトの DocumentPresetByExample より)
。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.ActiveDocument
Rem If the document preset "myDocumentPreset" does not
Rem already exist, create it.
Rem Disable normal error handling.
Err.Clear
On Error Resume Next
Set myDocumentPreset = myInDesign.DocumentPresets.Item("myDocumentPreset")
Rem If the document preset did not exist, the above line
Rem generates an error. Handle the error.
If (Err.Number <> 0) Then
Set myDocumentPreset = myInDesign.DocumentPresets.Add
myDocumentPreset.Name = "myDocumentPreset"
Err.Clear
End If
Rem Restore normal error handling.
On Error GoTo 0
Rem Fill in the properties of the document preset with the corresponding
Rem properties of the active document.
With myDocumentPreset
Rem Note that the following gets the page margins
rem from the margin preferences of the document to get the margin
Rem preferences from the active page, replace "myDocument" with
Rem "myInDesign.activeWindow.activePage" in the following six lines
Rem (assuming the active window is a layout window).
.Left = myDocument.MarginPreferences.Left
.Right = myDocument.MarginPreferences.Right
.Top = myDocument.MarginPreferences.Top
.Bottom = myDocument.MarginPreferences.Bottom
.ColumnCount = myDocument.MarginPreferences.ColumnCount
.ColumnGutter = myDocument.MarginPreferences.ColumnGutter
.DocumentBleedBottomOffset =
myDocument.DocumentPreferences.DocumentBleedBottomOffset
第 3 章 ドキュメント
基本的なページレイアウト
30
.DocumentBleedTopOffset =
myDocument.DocumentPreferences.DocumentBleedTopOffset
.DocumentBleedInsideOrLeftOffset =
myDocument.DocumentPreferences.DocumentBleedInsideOrLeftOffset
.DocumentBleedOutsideOrRightOffset =
myDocument.DocumentPreferences.DocumentBleedOutsideOrRightOffset
.FacingPages = myDocument.DocumentPreferences.FacingPages
.PageHeight = myDocument.DocumentPreferences.PageHeight
.PageWidth = myDocument.DocumentPreferences.PageWidth
.PageOrientation = myDocument.DocumentPreferences.PageOrientation
.PagesPerDocument = myDocument.DocumentPreferences.PagesPerDocument
.SlugBottomOffset = myDocument.DocumentPreferences.SlugBottomOffset
.SlugTopOffset = myDocument.DocumentPreferences.SlugTopOffset
.SlugInsideOrLeftOffset =
myDocument.DocumentPreferences.SlugInsideOrLeftOffset
.SlugRightOrOutsideOffset =
myDocument.DocumentPreferences.SlugRightOrOutsideOffset
End With
End If
ドキュメントプリセットの作成
明示的に値を指定してドキュメントプリセットを作成するには、次のスクリプトを実行します(チュートリ
アルスクリプトの DocumentPreset より)
。
On Error Resume Next
Set myDocumentPreset = myInDesign.DocumentPresets.Item("myDocumentPreset")
If Err.Number <> 0 Then
Set myDocumentPreset = myInDesign.DocumentPresets.Add
myDocumentPreset.Name = "myDocumentPreset"
Err.Clear
End If
On Error GoTo 0
Rem Fill in the properties of the document preset.
With myDocumentPreset
.PageHeight = "9i"
.PageWidth = "7i"
.Left = "4p"
.Right = "6p"
.Top = "4p"
.Bottom = "9p"
.ColumnCount = 1
.DocumentBleedBottomOffset = "3p"
.DocumentBleedTopOffset = "3p"
.DocumentBleedInsideOrLeftOffset = "3p"
.DocumentBleedOutsideOrRightOffset = "3p"
.FacingPages = True
.PageOrientation = idPageOrientation.idPortrait
.PagesPerDocument = 1
.SlugBottomOffset = "18p"
.SlugTopOffset = "3p"
.SlugInsideOrLeftOffset = "3p"
.SlugRightOrOutsideOffset = "3p"
End With
第 3 章 ドキュメント
基本的なページレイアウト
31
マスタースプレッドの設定
基本的なドキュメントページのサイズ、印刷可能領域、裁ち落としを設定したら、ドキュメントのマスター
スプレッドを定義するのが一般的です。次のスクリプトにその例を示します (完全なスクリプトについては、
MasterSpread を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Set up the first master spread in a new document.
Set myDocument = myInDesign.Documents.Add
Rem Set up the document.
With myDocument.DocumentPreferences
.PageHeight = "11i"
.PageWidth = "8.5i"
.FacingPages = True
.PageOrientation = idPageOrientation.idPortrait
End With
Rem Set the document's ruler origin to page origin. This is very important
Rem --if you don't do this, getting objects to the correct position on the
Rem page is much more difficult.
myDocument.ViewPreferences.RulerOrigin = idRulerOrigin.idPageOrigin
With myDocument.MasterSpreads.Item(1)
Rem Set up the left page (verso).
With .Pages.Item(1)
With .MarginPreferences
.ColumnCount = 3
.ColumnGutter = "1p"
.Bottom = "6p"
Rem "left" means inside "right" means outside.
.Left = "6p"
.Right = "4p"
.Top = "4p"
End With
Rem Add a simple footer with a section number and page number.
With .TextFrames.Add
.GeometricBounds = Array("61p", "4p", "62p", "45p")
.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idSectionMarker
.InsertionPoints.Item(1).Contents = idSpecialCharacters.idEmSpace
.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idAutoPageNumber
.Paragraphs.Item(1).Justification = idJustification.idLeftAlign
End With
End With
Rem Set up the right page (recto).
With .Pages.Item(2)
With .MarginPreferences
.ColumnCount = 3
.ColumnGutter = "1p"
.Bottom = "6p"
Rem "left" means inside "right" means outside.
.Left = "6p"
.Right = "4p"
.Top = "4p"
End With
Rem Add a simple footer with a section number and page number.
With .TextFrames.Add
第 3 章 ドキュメント
基本的なページレイアウト
32
.GeometricBounds = Array("61p", "6p", "62p", "47p")
.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idAutoPageNumber
.InsertionPoints.Item(1).Contents = idSpecialCharacters.idEmSpace
.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idSectionMarker
.Paragraphs.Item(1).Justification = idJustification.idRightAlign
End With
End With
End With
ドキュメントページにマスタースプレッドを適用するには、ドキュメントページの AppliedMaster プロパ
ティを使用します。次のスクリプトにその例を示します(チュートリアルスクリプトの ApplyMaster より)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Assumes that the active document has a master page named "B-Master"
Rem and at least two pages.
myInDesign.ActiveDocument.Pages.Item(2).AppliedMaster =
myInDesign.ActiveDocument.MasterSpreads.Item("B-Master")
同じプロパティを使用して、マスタースプレッドページにマスタースプレッドを適用します。次のスクリプ
トにその例を示します(チュートリアルスクリプトの ApplyMasterToMaster より)
。
Rem Assumes that the default master spread name is "A-Master".
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Rem Create a new master spread.
Set myBMaster = myDocument.MasterSpreads.Add
myBMaster.NamePrefix = "B"
myBMaster.BaseName = "Master"
Rem Apply master spread "A" to the first page of the new master spread.
myInDesign.ActiveDocument.MasterSpreads.Item("B-Master").Pages.Item(1).AppliedMaster =
myInDesign.ActiveDocument.MasterSpreads.Item("A-Master")
XMP メタデータの追加
メタデータとは、ファイルの内容や作成元などの属性を示す情報のことです。InDesign のユーザーインター
フェイスでは、ファイル情報ダイアログボックス(ファイル/ファイル情報を選択)を使用して、メタデー
タの入力、編集、表示を行います。このメタデータには、ドキュメントの作成日、修正日、作成者、著作権
のステータスなどがあります。こうした情報はすべて、XMP(Adobe Extensible Metadata Platform)を使用し
て保存されます。XMP は、ドキュメントにメタデータを埋め込むためのオープンスタンダードです。
XMP について詳しくは、http://partners.adobe.com/public/developer/xmp/sdk に掲載されている XMP の仕様を
参照してください。
InDesign スクリプティングでも、ドキュメントに XMP 情報を追加することができます。ドキュメントのすべ
ての XMP プロパティは、ドキュメントの metadataPreferences オブジェクトに含まれています。ドキュメン
トの標準 XMP データを入力する例を次に示します。
この例では、XMP 情報を拡張する方法も示されています。ドキュメントにメタデータを添付する必要があり、
そのデータが metadata preferences オブジェクトで定義されているカテゴリーに該当しない場合は、独自のメ
。(完全なスクリプトについては、MetadataExample
タデータコンテナを作成できます(この例では email)
を参照してください)
第 3 章 ドキュメント
基本的なページレイアウト
33
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
With myDocument.MetadataPreferences
.Author = "Adobe"
.CopyrightInfoURL = "http://www.adobe.com"
.CopyrightNotice = "This document is copyrighted."
.CopyrightStatus = idCopyrightStatus.idYes
.Description = "Example of xmp metadata scripting in InDesign CS"
.DocumentTitle = "XMP Example"
.JobName = "XMP_Example_2004"
.Keywords = Array("animal", "mineral", "vegetable")
Rem The metadata preferences object also includes the read-only
Rem creator, format, creationDate, modificationDate, and serverURL properties that are
Rem automatically entered and maintained by InDesign.
Rem Create a custom XMP container, "email"
.CreateContainerItem "http://ns.adobe.com/xap/1.0/", "email"
.SetProperty "http://ns.adobe.com/xap/1.0/", "email/*[1]", "[email protected]"
End With
ドキュメントテンプレートの作成
次の例では、新規ドキュメントを作成し、裁ち落としと印刷可能領域を定義し、ドキュメントの XMP メタ
データに情報を追加し、マスターページを設定し、ページフッターを追加し、印刷可能領域の表にジョブ情
報を追加しています (完全なスクリプトについては、DocumentTemplate を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Set the application measurement unit defaults to points.
myInDesign.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myInDesign.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
Rem Set the application default margin preferences.
With myInDesign.MarginPreferences
Rem Save the current application default margin preferences.
myY1 = .Top
myX1 = .Left
myY2 = .Bottom
myX2 = .Right
Rem Set the application default margin preferences.
Rem Document baseline grid will be based on 14 points, and
Rem all margins are set in increments of 14 points.
.Top = 14 * 4
.Left = 14 * 4
.Bottom = 74
.Right = 14 * 5
End With
Rem Make a new document.
Set myDocument = myInDesign.Documents.Add
myDocument.DocumentPreferences.PageWidth = "7i"
myDocument.DocumentPreferences.PageHeight = "9i"
myDocument.DocumentPreferences.PageOrientation = idPageOrientation.idPortrait
Rem At this point, we can reset the application default margins
Rem to their original state.
With myInDesign.MarginPreferences
.Top = myY1
.Left = myX1
.Bottom = myY2
.Right = myX2
End With
Rem Set up the bleed and slug areas.
With myDocument.DocumentPreferences
Rem Bleed
.DocumentBleedBottomOffset = "3p"
.DocumentBleedTopOffset = "3p"
.DocumentBleedInsideOrLeftOffset = "3p"
.DocumentBleedOutsideOrRightOffset = "3p"
第 3 章 ドキュメント
基本的なページレイアウト
Rem Slug
.SlugBottomOffset = "18p"
.SlugTopOffset = "3p"
.SlugInsideOrLeftOffset = "3p"
.SlugRightOrOutsideOffset = "3p"
End With
Rem Create a color.
Err.Clear
On Error Resume Next
Rem If the color does not already exist, InDesign will generate an error.
Set myColor = myDocument.Colors.Item("PageNumberRed")
If Err.Number <> 0 Then
Set myColor = myDocument.Colors.Add
myColor.Name = "PageNumberRed"
myColor.colorModel = idColorModel.idProcess
myColor.ColorValue = Array(20, 100, 80, 10)
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
Rem Next, set up some default styles.
Rem Create up a character style for the page numbers.
Err.Clear
On Error Resume Next
Rem If the character style does not already exist, InDesign generates an error.
Set myCharacterStyle = myDocument.CharacterStyles.Item("page_number")
If Err.Number <> 0 Then
Set myCharacterStyle = myDocument.CharacterStyles.Add
myCharacterStyle.Name = "page_number"
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
myDocument.CharacterStyles.Item("page_number").FillColor =
myDocument.Colors.Item("PageNumberRed")
Rem Create up a pair of paragraph styles for the page footer text.
Rem These styles have only basic formatting.
Err.Clear
On Error Resume Next
Rem If the paragraph style does not already exist, InDesign generates an error.
Set myParagraphStyle = myDocument.ParagraphStyles.Item("footer_left")
If Err.Number <> 0 Then
Set myParagraphStyle = myDocument.ParagraphStyles.Add
myParagraphStyle.Name = "footer_left"
myParagraphStyle.PointSize = 11
myParagraphStyle.Leading = 14
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
Err.Clear
On Error Resume Next
Rem If the paragraph style does not already exist, InDesign generates an error.
Set myParagraphStyle = myDocument.ParagraphStyles.Item("footer_right")
If Err.Number <> 0 Then
Set myParagraphStyle = myDocument.ParagraphStyles.Add
myParagraphStyle.Name = "footer_right"
myParagraphStyle.BasedOn = myDocument.ParagraphStyles.Item("footer_left")
myParagraphStyle.Justification = idJustification.idRightAlign
myParagraphStyle.PointSize = 11
myParagraphStyle.Leading = 14
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
34
第 3 章 ドキュメント
Rem Create a layer for guides.
Err.Clear
On Error Resume Next
Set myLayer = myDocument.Layers.Item("GuideLayer")
If Err.Number <> 0 Then
Set myLayer = myDocument.Layers.Add
myLayer.Name = "GuideLayer"
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
Rem Create a layer for the footer items.
Err.Clear
On Error Resume Next
Set myLayer = myDocument.Layers.Item("Footer")
If Err.Number <> 0 Then
Set myLayer = myDocument.Layers.Add
myLayer.Name = "Footer"
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
Rem Create a layer for the slug items.
Err.Clear
On Error Resume Next
Set myLayer = myDocument.Layers.Item("Slug")
If Err.Number <> 0 Then
Set myLayer = myDocument.Layers.Add
myLayer.Name = "Slug"
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
Rem Create a layer for the body text.
Err.Clear
On Error Resume Next
Set myLayer = myDocument.Layers.Item("BodyText")
If Err.Number <> 0 Then
Set myLayer = myDocument.Layers.Add
myLayer.Name = "BodyText"
Err.Clear
End If
Rem restore normal error handling
On Error GoTo 0
With myDocument.ViewPreferences
.RulerOrigin = idRulerOrigin.idPageOrigin
.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
.VerticalMeasurementUnits = idMeasurementUnits.idPoints
End With
Rem Document baseline grid and document grid
With myDocument.GridPreferences
.BaselineStart = 56
.BaselineDivision = 14
.BaselineGridShown = False
.HorizontalGridlineDivision = 14
.HorizontalGridSubdivision = 5
.VerticalGridlineDivision = 14
.VerticalGridSubdivision = 5
.DocumentGridShown = False
End With
基本的なページレイアウト
35
第 3 章 ドキュメント
基本的なページレイアウト
Rem Document XMP information.
With myDocument.MetadataPreferences
.Author = "Olav Martin Kvern"
.CopyrightInfoURL = "http:rem www.adobe.com"
.CopyrightNotice = "This document is not copyrighted."
.CopyrightStatus = idCopyrightStatus.idNo
.Description = "Example 7 x 9 book layout"
.DocumentTitle = "Example"
.JobName = "7 x 9 book layout template"
.Keywords = Array("7 x 9", "book", "template")
.CreateContainerItem "http://ns.adobe.com/xap/1.0/", "email"
.SetProperty "http://ns.adobe.com/xap/1.0/", "email/*[1]", "[email protected]"
End With
Rem Set up the master spread.
With myDocument.MasterSpreads.Item(1)
With .Pages.Item(1)
Rem Left and right are reversed for left-hand pages (becoming "inside" and "outside"-Rem this is also true in the InDesign user interface).
myTopMargin = .MarginPreferences.Top
myBottomMargin = myDocument.DocumentPreferences.PageHeight - .MarginPreferences.Bottom
myRightMargin = myDocument.DocumentPreferences.PageWidth - .MarginPreferences.Left
myLeftMargin = .MarginPreferences.Right
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idVertical
.Location = myLeftMargin
End With
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idVertical
.Location = myRightMargin
End With
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = myTopMargin
.FitToPage = False
End With
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = myBottomMargin
.FitToPage = False
End With
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = myBottomMargin + 14
.FitToPage = False
End With
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idHorizontal
.Location = myBottomMargin + 28
.FitToPage = False
End With
Set myLeftFooter = .TextFrames.Add
36
第 3 章 ドキュメント
基本的なページレイアウト
37
myLeftFooter.ItemLayer = myDocument.Layers.Item("Footer")
myLeftFooter.GeometricBounds = Array(myBottomMargin + 14, .MarginPreferences.Right,
myBottomMargin + 28, myRightMargin)
myLeftFooter.ParentStory.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idSectionMarker
myLeftFooter.ParentStory.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idEmSpace
myLeftFooter.ParentStory.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idAutoPageNumber
myLeftFooter.ParentStory.Characters.Item(1).AppliedCharacterStyle =
myDocument.CharacterStyles.Item("page_number")
myLeftFooter.ParentStory.Paragraphs.Item(1).ApplyStyle
myDocument.ParagraphStyles.Item("footer_left"), False
Rem Slug information.
myDate = Date
With myDocument.MetadataPreferences
myString = "Author:" & vbTab & .Author & vbTab & "Description:" & vbTab & .Description
& vbCrLf & _
"Creation Date:" & vbTab & myDate & vbTab & "Email Contact" & vbTab &
.GetProperty("http://ns.adobe.com/xap/1.0/", "email/*[1]")
End With
Set myLeftSlug = .TextFrames.Add
myLeftSlug.ItemLayer = myDocument.Layers.Item("Slug")
myLeftSlug.GeometricBounds = Array(myDocument.DocumentPreferences.PageHeight + 36,
.MarginPreferences.Right, myDocument.DocumentPreferences.PageHeight + 144, myRightMargin)
myLeftSlug.Contents = myString
myLeftSlug.ParentStory.Texts.Item(1).ConvertToTable
Rem Body text master text frame.
Set myLeftFrame = .TextFrames.Add
myLeftFrame.ItemLayer = myDocument.Layers.Item("BodyText")
myLeftFrame.GeometricBounds = Array(.MarginPreferences.Top, .MarginPreferences.Right,
myBottomMargin, myRightMargin)
End With
With .Pages.Item(2)
myTopMargin = .MarginPreferences.Top
myBottomMargin = myDocument.DocumentPreferences.PageHeight - .MarginPreferences.Bottom
myRightMargin = myDocument.DocumentPreferences.PageWidth - .MarginPreferences.Right
myLeftMargin = .MarginPreferences.Left
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idVertical
.Location = myLeftMargin
End With
With .Guides.Add
.ItemLayer = myDocument.Layers.Item("GuideLayer")
.Orientation = idHorizontalOrVertical.idVertical
.Location = myRightMargin
End With
Set myRightFooter = .TextFrames.Add
myRightFooter.ItemLayer = myDocument.Layers.Item("Footer")
myRightFooter.GeometricBounds = Array(myBottomMargin + 14, .MarginPreferences.Left,
myBottomMargin + 28, myRightMargin)
myRightFooter.ParentStory.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idAutoPageNumber
myRightFooter.ParentStory.InsertionPoints.Item(1).Contents =
idSpecialCharacters.idEmSpace
myRightFooter.ParentStory.InsertionPoints.Item(1).Contents =
第 3 章 ドキュメント
基本的なページレイアウト
38
idSpecialCharacters.idSectionMarker
myRightFooter.ParentStory.Characters.Item(-1).AppliedCharacterStyle =
myDocument.CharacterStyles.Item("page_number")
myRightFooter.ParentStory.Paragraphs.Item(1).ApplyStyle
myDocument.ParagraphStyles.Item("footer_right"), False
Rem Slug information.
Set myRightSlug = .TextFrames.Add
myRightSlug.ItemLayer = myDocument.Layers.Item("Slug")
myRightSlug.GeometricBounds = Array(myDocument.DocumentPreferences.PageHeight + 36,
myLeftMargin, myDocument.DocumentPreferences.PageHeight + 144, myRightMargin)
myRightSlug.Contents = myString
myRightSlug.ParentStory.Texts.Item(1).ConvertToTable
Rem Body text master text frame.
Set myRightFrame = .TextFrames.Add
myRightFrame.ItemLayer = myDocument.Layers.Item("BodyText")
myRightFrame.GeometricBounds = Array(.MarginPreferences.Top, .MarginPreferences.Left,
myBottomMargin, myRightMargin)
myRightFrame.PreviousTextFrame = myLeftFrame
End With
End With
Rem Add section marker text--this text will appear in the footer.
myDocument.Sections.Item(1).Marker = "Section 1"
Rem When you link the master page text frames, one of the frames
Rem sometimes becomes selected. Deselect it.
myInDesign.Select idNothingEnum.idNothing
透かしの作成
InDesign や InDesign Server では、スクリプトを使用してドキュメントに透かしを適用することができます。
現時点では、InDesign に透かしを操作するユーザーインターフェイスは存在しません。
ドキュメントの透かし環境設定は、スクリプトを使用した次の 2 種類の方法で設定できます。

アプリケーションレベルの watermark preferences が設定されている場合、InDesign で作成するすべての
新規ドキュメントに、この透かし環境設定が適用されます。この設定は、既存のドキュメントには影響
を与えません。

ドキュメントレベルの watermark preferences は、該当のドキュメントにのみ適用されます。ドキュメン
トの watermark preferences を設定したり変更したりすると、ドキュメントの以前の透かし環境設定が上
書きされます。
ドキュメントレベルおよびアプリケーションレベルの透かし環境設定は、いずれもドキュメントを閉じるか
アプリケーションを終了してから、スクリプトで変更されるまで保持されます。
ドキュメントオブジェクトとアプリケーションオブジェクトの両方に、同じ透かし環境設定のグループがあ
ります。
第 3 章 ドキュメント
基本的なページレイアウト
39
watermark preferences の設定
アプリケーションレベルで透かしを設定する方法を、次のスクリプトに示します。このコードの実行後は、
作成するドキュメントのすべてに透かしが適用されます (アプリケーションの環境設定を指定する完全なス
クリプトについては、ApplicationWatermark を参照してください)。
myInDesign.watermarkPreferences.watermarkVisibility = true
myInDesign.watermarkPreferences.watermarkDoPrint = true
myInDesign.watermarkPreferences.watermarkDrawInBack = true
myInDesign.watermarkPreferences.watermarkText = "Confidential"
myInDesign.watermarkPreferences.watermarkFontFamily = "Arial"
myInDesign.watermarkPreferences.watermarkFontStyle = "Bold"
myInDesign.watermarkPreferences.watermarkFontPointSize = 72
myInDesign.watermarkPreferences.watermarkFontColor = idUIColors.idRed
myInDesign.watermarkPreferences.watermarkOpacity = 60
myInDesign.watermarkPreferences.watermarkRotation = -45
myInDesign.watermarkPreferences.watermarkHorizontalPosition =
idWatermarkHorizontalPositionEnum.idWatermarkHCenter
myInDesign.watermarkPreferences.watermarkHorizontalOffset = 0
myInDesign.watermarkPreferences.watermarkVerticalPosition =
idWatermarkVerticalPositionEnum.idWatermarkVCenter
myInDesign.watermarkPreferences.watermarkVerticalOffset = 0
アプリケーションではなくドキュメントを参照するようにすると、同じ環境設定をドキュメントオブジェク
トに適用できます (ドキュメントの環境設定を指定する完全なスクリプトについては、DocumentWatermark
を参照してください)。
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkVisibility = true
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkDoPrint = true
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkDrawInBack = true
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkText = "Confidential"
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkFontFamily = "Arial"
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkFontStyle = "Bold"
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkFontPointSize = 72
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkFontColor =
idUIColors.idRed
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkOpacity = 60
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkRotation = -45
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkHorizontalPosition =
idWatermarkHorizontalPositionEnum.idWatermarkHCenter
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkHorizontalOffset = 0
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkVerticalPosition =
idWatermarkVerticalPositionEnum.idWatermarkVCenter
myInDesign.Documents.Item(1).WatermarkPreferences.watermarkVerticalOffset = 0
透かしの無効化
透かしのアプリケーション設定をオフにすると、新規ドキュメントの透かし設定はデフォルトではオンにな
らなくなります。ただし、個々のドキュメントに透かしを設定することは可能です。アプリケーションレベル
の透かしをオフにする方法を、次のスクリプトに示します。
Rem Given a reference to the InDesign application object "myInDesign"...
myInDesign.WatermarkVisibility = False
個々のドキュメントの透かしは、いつでもオフにすることができます。次のスクリプトにその例を示します。
Rem Given a reference to the InDesign application object "myInDesign"...
myInDesign.Documents.Item(1).WatermarkVisibility = False
第 3 章 ドキュメント
ページサイズとレイアウトの調整
40
ページサイズとレイアウトの調整
InDesign では、1 つの InDesign ドキュメント内で別々のページサイズを設定できます。デフォルトのページサ
イズの設定について詳しくは、「ページサイズとドキュメントの長さの定義」を参照してください。
また、個々のページに変形を適用することもできます。
ページの選択
ページをサイズ変更したりページに変形を適用するには、まずページを選択する必要があります。InDesign
のユーザーインターフェイスでページを選択するには、ツールパネルのページツールを使用します。また、
スクリプトを使用してページを選択することもできます。次のスクリプトにその例を示します (完全なスク
リプトについては、PageSelect を参照してください)。
Rem Given a document with four pages (1, 2, 3, 4)...
Set myDocument = myInDesign.ActiveDocument
Set myPages = myDocument.Pages
Rem Select page 2 and 3.
myPages.Item(2).Select()
myPages.Item(3).select(idSelectionOptions.idAddTo)
Rem Select last page.
Call myDocument.Select(myPages.Item(-1), idSelectionOptions.idAddTo)
ページのサイズ変更とフレーム調整
スクリプトを使用して、ページ上のページアイテムをサイズ変更したり、フレームを調整したりできます。
また、サイズ変更やフレーム調整の操作を複数のページに適用して各ページをサイズ変更することもできま
す。
注意:最小のページサイズは、ページのマージンによって決まります。詳しくは、「ページのマージンと段組
の設定」を参照してください。
resize メソッドを使用してページをサイズ変更する方法を、次のスクリプトに示します (完全なスクリプト
については、PageResize を参照してください)。
Rem Given a document with four pages (1, 2, 3, 4)...
Set myDocument = myInDesign.ActiveDocument
Set myPages = myDocument.Pages
Rem Resize page to two times bigger
Call myPages.Item(2).Resize(idCoordinateSpaces.idInnerCoordinates, _
idAnchorPoint.idCenterAnchor, _
idResizeMethods.idMultiplyingCurrentDimensionsBy, _
Array(2, 2))
Rem Resize page to 400 points width and 600 points height.
Call myPages.item(3).Resize(idCoordinateSpaces.idInnerCoordinates, _
idAnchorPoint.idCenterAnchor, _
idResizeMethods.idReplacingCurrentDimensionsWith, _
Array(400, 600))
フレーム調整を行うと、ページのバウンディングボックスが変更されます。そのため、フレーム調整を使用
して、バウンディングボックスを大きくしたり小さくしたりすることで、ページをサイズ変更できます。
reframe メソッドを使用してページをサイズ変更する方法を、次のスクリプトに示します (完全なスクリプ
トについては、PageReframe を参照してください)。
第 3 章 ドキュメント
ページサイズとレイアウトの調整
41
Rem Given a document with four pages (1, 2, 3, 4)...
Set myDocument = myInDesign.ActiveDocument
Set myPages = myDocument.Pages
Rem Make the page one inch wider and one inch higher.
Set myPage = myPages.Item(2)
myBounds = myPage.Bounds
myY1 = myBounds(0)
myX1 = myBounds(1)
myY2 = myBounds(2)+72
myX2 = myBounds(3)+72
Call myPage.Reframe(idCoordinateSpaces.idInnerCoordinates, _
Array(Array(myX1, myY1), _
Array(myX2, myY2)))
ページの変形
オブジェクトの形状を変更する操作は、変形と呼ばれます。transform メソッドで、ページ上のページアイテ
ムを回転、拡大・縮小、シアーおよび移動(平行移動)して、ページ上で使用できます。変形アーキテク
チャの技術的な詳細については、「ページアイテムの変形」を参照してください。
ページを変形するには:
1.
変形マトリックスを作成します。
2.
この変形マトリックスを transform メソッドを使用してページに適用します。
スクリプトを使用してページを変形する方法を、次のスクリプトに示します (完全なスクリプトについて
は、PageTransform を参照してください)。
Rem Given a document with four pages (1, 2, 3, 4)...
Set myDocument = myInDesign.ActiveDocument
Set myPages = myDocument.Pages
Rem Rotate a page around its center point.
Set myRotateMatrix = myInDesign.TransformationMatrices.Add(, , , 27)
myTransform myPages.Item(1), myRotateMatrix
Rem Scale a page around its center point.
Set myScaleMatrix = myInDesign.TransformationMatrices.Add(0.8, 0.8)
myTransform myPages.Item(2), myScaleMatrix
Rem Shear a page around its center point.
Set myShearMatrix = myInDesign.TransformationMatrices.Add(, , 30)
myTransform myPages.Item(3), myShearMatrix
Function myTransform(myPage, myTransformationMatrix)
myPage.Transform idCoordinateSpaces.idPasteboardCoordinates, _
idAnchorPoint.idCenterAnchor, _
myTransformationMatrix
End Function
第 3 章 ドキュメント
調整型レイアウトの作成
42
マスターページオーバーレイ
ページには複数のサイズが設定できるため、ページとそのマスターページで別々のサイズを設定することが
できます。適用されているマスターを検出するだけでなく、ページでは、マスターページがどのようにペー
ジ上に描画されるかを定めるマトリックスも維持されます。これをマスターページオーバーレイと呼びます。
ツールパネルのページツールを使用してページを選択するときに、コントロールパネルの「マスターページ
オーバーレイを表示」チェックボックスをオンにすると、マスターページの配置仕様を確認できます。オー
バーレイは、マウスで移動することができます。これは、マスターオーバーレイのマトリックスに変形を適
用することで実現しています。ユーザーインターフェイスからは平行移動(x および y の移動)のみ可能です
が、スクリプトではその他の操作も実行できます。マスターページオーバーレイを変形する方法を、次のス
クリプトに示します (完全なスクリプトについては、MasterPageTransform を参照してください)。
Rem Given a document with four pages (1, 2, 3, 4)...
Set myDocument = myInDesign.ActiveDocument
Set myPages = myDocument.Pages
Rem Rotate master page overlay around its top-left corner.
Set myRotateMatrix = myInDesign.TransformationMatrices.Add(, , , 27)
myPages.Item(1).MasterPageTransform = myRotateMatrix
Rem Scale master page overlay around its top-left corner.
Set myScaleMatrix = myInDesign.TransformationMatrices.Add(0.5, 0.5)
myPages.Item(2).MasterPageTransform = myScaleMatrix
Rem Shear master page overlay around its top-left corner.
Set myShearMatrix = myInDesign.TransformationMatrices.Add(, , 30)
myPages.Item(3).MasterPageTransform = myShearMatrix
Rem Translate master page overlay 1 inch right and 2 inches down.
Set myTranslateMatrix = myInDesign.TransformationMatrices.Add(, , , , 72, 144)
myPages.Item(4).MasterPageTransform = myTranslateMatrix
調整型レイアウトの作成
InDesign のレイアウト調整ワークフローを使用して作成した基本レイアウトは、異なる方向、サイズ、縦横
比、またはまったく異なるデバイスクラスに簡単に適応させることができます。基本レイアウトの作成方法
は、プリント用ドキュメントのレイアウトを作成する場合と同じです。このワークフローには主に 2 つの機
能が関連しています。レイアウトに柔軟性を与えるリキッドレイアウトと、様々な方向およびデバイスクラ
ス用の代替レイアウトを作成する代替レイアウト作成という機能です。
柔軟性のあるレイアウトの作成
レイアウトルールを使用して作成した 1 セットの物理的なページで構成される InDesign ファイルは、サイズ
や方向が異なるデバイス上でも、そのコンテンツがそれぞれのデバイスに適した状態で表示されます。必要
であれば、サイズおよび方向ごとにページの外観を指定できます。次のスクリプト例に、その方法を示しま
す (完全なスクリプトについては、LiquidLayout を参照してください)。
第 3 章 ドキュメント
Set doc = myInDesign.Documents.Add
Set myPage = doc.Pages.item(1)
REM Set layout policy to LayoutRuleOptions.OBJECT_BASED
myPage.LayoutRule = idLayoutRuleOptions.idOBJECTBASED
REM Create a text frame on the first page.
Set myTextFrame = myPage.TextFrames.Add
myTextFrame.GeometricBounds=myGetBounds(doc, myPage)
myTextFrame.Contents="This is object-based LayoutRule sample doc."
REM Create a rectangle
Set myItem = myPage.Rectangles.Add
myItem.GeometricBounds=Array(20,20,70,70)
myItem.VerticalLayoutConstraints = _
Array(idDimensionsConstraints.idFlexibleDimension, _
idDimensionsConstraints.idFlexibleDimension, _
idDimensionsConstraints.idFlexibleDimension)
myItem.HorizontalLayoutConstraints = _
Array(idDimensionsConstraints.idFixedDimension, _
idDimensionsConstraints.idflexibleDimension, _
idDimensionsConstraints.idFlexibleDimension)
Set doc2 = myInDesign.Documents.Add()
Set myPage2 = doc2.Pages.item(1)
REM Set layout rule to LayoutRuleOptions.SCALE
myPage2.LayoutRule = idLayoutRuleOptions.idSCALE
REM Create a text frame on the first page.
Set myTextFrame2 = myPage2.TextFrames.Add
myTextFrame2.GeometricBounds=myGetBounds(doc2, myPage2)
myTextFrame2.Contents="This is scale LayoutRule sample doc."
Set myItem2 = myPage2.Rectangles.Add
myItem2.GeometricBounds=Array(20,20,70,70)
Set doc3 = myInDesign.Documents.Add
Set myPage3 = doc3.Pages.item(1)
REM Set layout rule to LayoutRuleOptions.RECENTER
myPage3.LayoutRule = idLayoutRuleOptions.idRECENTER
REM Create a text frame on the first page.
Set myTextFrame3 = myPage3.TextFrames.Add
myTextFrame3.GeometricBounds=myGetBounds(doc3, myPage3)
myTextFrame3.Contents="This is recenter LayoutRule sample doc."
Set myItem3 = myPage3.Rectangles.Add
myItem3.GeometricBounds=Array(20,20,70,70)
Set doc4 = myInDesign.Documents.Add
Set myPage4 = doc4.Pages.item(1)
REM Set layout rule to LayoutRuleOptions.GUIDE_BASED
myPage4.LayoutRule = idLayoutRuleOptions.idGUIDEBASED
REM Create a text frame on the first page.
Set myTextFrame4 = myPage4.TextFrames.Add
myTextFrame4.GeometricBounds=myGetBounds(doc4, myPage4)
myTextFrame4.Contents="This is guide-based LayoutRule sample doc."
Set myItem4 = myPage4.Rectangles.Add
myItem4.GeometricBounds=Array(20,20,70,70)
with doc4
With .Guides.Add
.GuideType=idGuideTypeOptions.idLIQUID
調整型レイアウトの作成
43
第 3 章 ドキュメント
調整型レイアウトの作成
44
.Location=20
.Orientation=idHorizontalOrVertical.idHorizontal
End With
End With
Set doc5 = myInDesign.Documents.Add
Set myPage5 = doc5.Pages.item(1)
REM Set layout rule to LayoutRuleOptions.USE_MASTER
myPage5.LayoutRule = idLayoutRuleOptions.idUSEMASTER
REM Create a text frame on the first page.
Set myTextFrame5 = myPage5.TextFrames.Add
myTextFrame5.GeometricBounds=myGetBounds(doc5, myPage5)
myTextFrame5.Contents="This is master page LayoutRule sample doc."
Set myItem5 = myPage5.Rectangles.Add
myItem5.GeometricBounds=Array(20,20,70,70)
ガイドベースのレイアウトへのガイドの追加
ガイドベースのレイアウトルールにガイドスライスを追加する方法を、次のスクリプト例に示します (完全
なスクリプトについては、AddGuides を参照してください)。
Set myDocument = myInDesign.Documents.Add
Rem Create a text frame on the current page.
Set myPage = myDocument.Pages.Item(1)
Rem Set layout policy
Rem Use guide slicing to resize objects on the page as it resizes.
myPage.LayoutRule = idLayoutRuleOptions.idGUIDEBASED
Set myTextFrame = myPage.TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myPage)
myTextFrame.Contents = "This is guide-based LayoutRule sample doc."
Set myItem = myPage.Rectangles.Add
myItem.GeometricBounds = Array(20, 20, 70, 70)
With myDocument
Set myGuide = .Guides.Add
myGuide.GuideType = idGuideTypeOptions.idLIQUID
myGuide.Location = 20
myGuide.orientation = idHorizontalOrVertical.idHorizontal
End With
第 3 章 ドキュメント
調整型レイアウトの作成
45
オブジェクトベースのレイアウトへの制約の設定
オブジェクトベースのレイアウトルールに制約を設定する方法を、次のスクリプト例に示します (完全なス
クリプトについては、SetConstraints を参照してください)。
Set myDocument = myInDesign.Documents.Add
Rem Create a text frame on the current page.
Set myPage = myDocument.Pages.Item(1)
Rem Set layout rule
Rem Use guide slicing to resize objects on the page as it resizes.
myPage.LayoutRule = idLayoutRuleOptions.idOBJECTBASED
Set myTextFrame = myPage.TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myPage)
myTextFrame.Contents = "This is object-based layoutRule sample doc."
Set myItem = myPage.Rectangles.Add
myItem.GeometricBounds = Array(20, 20, 70, 70)
myItem.VerticalLayoutConstraints = _
Array(idDimensionsConstraints.idFlexibleDimension, _
idDimensionsConstraints.idFlexibleDimension, _
idDimensionsConstraints.idFlexibleDimension)
myItem.HorizontalLayoutConstraints = _
Array(idDimensionsConstraints.idFlexibleDimension, _
idDimensionsConstraints.idFlexibleDimension, _
idDimensionsConstraints.idFlexibleDimension)
代替レイアウトの作成
代替レイアウト作成は、コンテンツが含まれている既存ページの範囲を取得し、そのコンテンツのリンク付
きコピーを、同じドキュメント内の新しいページセット上に自動的に作成します。これは、方向およびデバ
イスクラスごとに異なるレイアウトを作成する必要がある場合に使用します (完全なスクリプトについて
は、CreateAlternateLayout を参照してください)。
Set myDoc = myInDesign.Documents.Add
With myDoc.DocumentPreferences
.facingPages=false
.pagesPerDocument=1
.pageWidth=1024
.pageHeight=768
End With
REM Reposition and resize objects on the page as it resizes.
myDoc.Pages.item(1).LayoutRule = idLayoutRuleOptions.idOBJECTBASED
With myDoc
Set myItem = .Pages.Item(1).Rectangles.Add
myItem.GeometricBounds=Array(50,50,100,100)
End With
REM create alternate layout
myDoc.CreateAlternateLayout myDoc.Spreads, "new layout", _
myDoc.DocumentPreferences.PageHeight, _
myDoc.DocumentPreferences.PageWidth, _
true, true, _
idLayoutRuleOptions.idPRESERVEEXISTING
第 3 章 ドキュメント
コンテンツの収集とドロップ
46
コンテンツの収集とドロップ
コンテンツドロッパーを使用すると、プリント用にデザインしたファイルからコンテンツをコピーし、別の
ドキュメントに貼り付けることができます。
スクリプトを使用してドキュメント内のコンテンツを収集する方法を、次のスクリプトに示します (完全な
スクリプトについては、ContentCollectorAndPlacer を参照してください)。
REM Invoke load with full parameters
contentPlacer.load myPage.Rectangles, true, true, true, true
収集したコンテンツを別のドキュメントに配置する方法を、次のスクリプトに示します (完全なスクリプト
については、ContentCollectorAndPlacer を参照してください)。
REM Invoke Page.contentPlace with full parameters
myPage1.ContentPlace myPage.Rectangles, _
true, _
true, _
true, _
Array(0, 0, 40, 40), _
myDocument1.ActiveLayer, _
true
ドキュメントのプリント
次のスクリプトでは、現在の print preferences を使用して、アクティブなドキュメントをプリントします
(完全なスクリプトについては、PrintDocument を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Rem The PrintOut method has two optional parameters:
Rem PrintDialog--if true, display the Print dialog box
Rem Using--the printer preset to use. The following line
Rem prints the document using the default settings and
Rem without displaying the Print dialog box.
myInDesign.ActiveDocument.PrintOut False
ページ範囲を使用したプリント
プリントするページの範囲を指定するには、プリントを行う前に、ドキュメントの print preferences オブ
ジェクトの PageRange プロパティを設定します。次のスクリプトにその例を示します(チュートリアルスク
リプトの PrintPageRange より)。
Rem Prints a page range from the active document.
Rem The page range can be either idPageRange.idAllPages or a page range string.
Rem A page number entered in the page range must correspond to a page
Rem name in the document (i.e., not the page index). If the page name is
Rem not found, InDesign will display an error message.
myInDesign.ActiveDocument.PrintPreferences.PageRange = "1-3, 6, 9"
myInDesign.ActiveDocument.PrintOut False
print preferences の設定
print preferences オブジェクトに保持されているプロパティは、プリントダイアログボックスの各パネルに
含まれているオプションに対応しています。スクリプティングで print preferences を設定する方法を、次のス
クリプトに示します (完全なスクリプトについては、PrintPreferences を参照してください)。
第 3 章 ドキュメント
ドキュメントのプリント
Rem PrintPreferences.vbs
Rem An InDesign CS6 VBScript
Rem Sets the print preferences of the active document.
Set myInDesign = CreateObject("InDesign.Application")
With myInDesign.ActiveDocument.PrintPreferences
Rem Properties corresponding to the controls in the General panel
Rem of the Print dialog box.
Rem ActivePrinterPreset is ignored in this example--we'll set our own
Rem print preferences.
Rem printer can be either a string (the name of the printer) or
Rem idPrinter.idPostscriptFile.
.Printer = idPrinter.idPostscriptFile
Rem If the printer property is the name of a printer, then the ppd property
Rem is locked (and will return an error if you try to set it).
On Error Resume Next
Rem ppd = "AGFA-SelectSet5000SF"
If Err.Number <> 0 Then
Err.Clear
End If
Rem If the printer property is set to Printer.postscript file, the copies
Rem property is unavailable. Attempting to set it will generate an error.
Rem.Copies = 1
Rem If the printer property is set to Printer.postscript file, or if the
Rem selected printer does not support collation, then the collating
Rem property is unavailable. Attempting to set it will generate an error.
Rem collating = false
.ReverseOrder = False
Rem pageRange can be either PageRange.allPages or a page range string.
.PageRange = idPageRange.idAllPages
.PrintSpreads = False
.PrintMasterPages = False
Rem If the printer property is set to Printer.postScript file, then
Rem the printFile property contains the file path to the output file.
Rem printFile = "/c/test.ps"
.Sequence = idSequences.idAll
Rem If trapping is set to either idTrapping.idApplicationBuiltIn
Rem or idTrapping.idAdobeInRIP,
Rem then setting the following properties will produce an error.
If (.ColorOutput = idColorOutputModes.idInRIPSeparations) Or _
(.ColorOutput = idColorOutputModes.idSeparations) Then
If .Trapping = idTrapping.idOff Then
.PrintBlankPages = False
.PrintGuidesGrids = False
.PrintNonprinting = False
End If
End If
Rem----------------------------------------------------------------------Rem Properties corresponding to the controls in the Setup panel
Rem of the Print dialog box.
Rem----------------------------------------------------------------------.PaperSize = idPaperSizes.idCustom
Rem Page width and height are ignored if paperSize is not PaperSizes.custom.
Rem .PaperHeight = 1200
Rem .PaperWidth = 1200
.PrintPageOrientation = idPrintPageOrientation.idPortrait
.PagePosition = idPagePositions.idCentered
.PaperGap = 0
.PaperOffset = 0
.PaperTransverse = False
.ScaleHeight = 100
.ScaleWidth = 100
.ScaleMode = idScaleModes.idScaleWidthHeight
.ScaleProportional = True
Rem If trapping is set to either idTrapping.idApplicationBuiltIn or
Rem idTrapping.idAdobeInRIP,then setting the following properties will
Rem produce an error.
47
第 3 章 ドキュメント
ドキュメントのプリント
If (.ColorOutput = idColorOutputModes.idInRIPSeparations) Or _
(.ColorOutput = idColorOutputModes.idSeparations) Then
If .Trapping = idTrapping.idOff Then
.TextAsBlack = False
.Thumbnails = False
Rem The following properties is not needed because thumbnails
Rem is set to false.
Rem thumbnailsPerPage = 4
.Tile = False
Rem The following properties are not needed
Rem because tile is set to false.
Rem .TilingOverlap = 12
Rem .TilingType = TilingTypes.auto
End If
End If
Rem----------------------------------------------------------------------Rem Properties corresponding to the controls in the Marks and Bleed
Rem panel of the Print dialog box.
Rem----------------------------------------------------------------------Rem Set the following property to true to print all printer's marks.
Rem allPrinterMarks = true
.UseDocumentBleedToPrint = False
Rem If useDocumentBleedToPrint = false then setting any of
Rem the bleed properties will result in an error.
Rem Get the bleed amounts from the document's bleed and add a bit.
.BleedBottom = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedBottomOffset + 3
.BleedTop = myInDesign.ActiveDocument.
DocumentPreferences.DocumentBleedTopOffset + 3
.BleedInside = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedInsideOrLeftOffset + 3
.BleedOutside = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedOutsideOrRightOffset + 3
Rem If any bleed area is greater than zero, then print the bleed marks.
If ((.BleedBottom = 0) And (.BleedTop = 0) And (.BleedInside = 0) _
And (.BleedOutside = 0)) Then
.BleedMarks = True
Else
.BleedMarks = False
End If
.ColorBars = True
.CropMarks = True
.IncludeSlugToPrint = False
.MarkLineWeight = idMarkLineWeight.idP125pt
.MarkOffset = 6
Rem .MarkType = MarkTypes.default
.PageInformationMarks = True
.RegistrationMarks = True
Rem----------------------------------------------------------------------Rem Properties corresponding to the controls in the
Rem Output panel of the Print dialog box.
Rem----------------------------------------------------------------------.Negative = True
.ColorOutput = idColorOutputModes.idSeparations
Rem Note the lowercase "i" in "Builtin"
.Trapping = idTrapping.idApplicationBuiltin
.Screening = "175 lpi/2400 dpi"
.Flip = idFlip.idNone
Rem The following options are only applicable if trapping is set to
Rem idTrapping.idAdobeInRIP.
If .Trapping = idTrapping.idAdobeInRIP Then
.PrintBlack = True
.PrintCyan = True
.PrintMagenta = True
48
第 3 章 ドキュメント
ドキュメントのプリント
.PrintYellow = True
End If
Rem Only change the ink angle and frequency when you want to override the
Rem screening set by the screening specified by the screening property.
Rem .BlackAngle = 45
Rem .BlackFrequency = 175
Rem .CyanAngle = 15
Rem .CyanFrequency = 175
Rem .MagentaAngle = 75
Rem .MagentaFreqency = 175
Rem .YellowAngle = 0
Rem .YellowFrequency = 175
Rem The following properties are not needed (because colorOutput
Rem is set to separations).
Rem .CompositeAngle = 45
Rem .CompositeFrequency = 175
Rem .SimulateOverprint = false
Rem----------------------------------------------------------------------Rem Properties corresponding to the controls in the Graphics
Rem panel of the Print dialog box.
Rem----------------------------------------------------------------------.SendImageData = idImageDataTypes.idAllImageData
.FontDownloading = idFontDownloading.idComplete
Err.Clear
On Error Resume Next
.DownloadPPDFonts = True
.DataFormat = idDataFormat.idBinary
.PostScriptLevel = idPostScriptLevels.idLevel3
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
Rem----------------------------------------------------------------------Rem Properties corresponding to the controls in the Color
Rem Management panel of the Print dialog box.
Rem----------------------------------------------------------------------Rem If the UseColorManagement property of myInDesign.ColorSettings is false,
Rem attempting to set the following properties will return an error.
Err.Clear
On Error Resume Next
.SourceSpace = SourceSpaces.useDocument
.Intent = RenderingIntent.useColorSettings
.CRD = ColorRenderingDictionary.useDocument
.Profile = Profile.postscriptCMS
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
Rem----------------------------------------------------------------------Rem Properties corresponding to the controls in the
Rem Advanced panel of the Print dialog box.
Rem-----------------------------------------------------------------------
49
第 3 章 ドキュメント
PDF としてのドキュメントの書き出し
50
.OPIImageReplacement = False
.OmitBitmaps = False
.OmitEPS = False
.OmitPDF = False
Rem The following line assumes that you have a flattener
Rem preset named "high quality flattener".
Err.Clear
On Error Resume Next
.FlattenerPresetName = "high quality flattener"
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.IgnoreSpreadOverrides = False
End With
プリントプリセットを使用したプリント
プリントプリセットを使用してドキュメントをプリントするには、print コマンドでプリントプリセットを
指定します。
PDF としてのドキュメントの書き出し
InDesign スクリプティングでは、ページレイアウトドキュメントから PDF ファイルを作成する処理を完全に
制御できます。
PDF の書き出し
次のスクリプトでは、現在の PDF 書き出しオプションを使用して、現在のドキュメントを PDF として書き出
しています (完全なスクリプトについては、ExportPDF を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
myInDesign.ActiveDocument.Export idExportFormat.idPDFType, "c:¥myTestDocument.pdf", False
次のスクリプトでは、PDF 書き出しプリセットを使用して PDF を書き出しています (完全なスクリプトにつ
いては、ExportPDFWithPreset を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
myInDesign.ActiveDocument.Export idExportFormat.idPDFType, "c:¥myTestDocument.pdf", False,
myInDesign.PDFExportPresets.Item("[Press]")
第 3 章 ドキュメント
PDF としてのドキュメントの書き出し
51
PDF 書き出しオプションの設定
次のスクリプトでは、PDF 書き出しオプションを設定してから、書き出しを行っています (完全なスクリプ
トについては、ExportPDFWithOptions を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
With myInDesign.PDFExportPreferences
Rem Basic PDF output options.
.PageRange = idPageRange.idAllPages
.AcrobatCompatibility = idAcrobatCompatibility.idAcrobat6
.ExportGuidesAndGrids = False
.ExportLayers = False
.ExportNonprintingObjects = False
.ExportReaderSpreads = False
.GenerateThumbnails = False
On Error Resume Next
.IgnoreSpreadOverrides = False
.IncludeICCProfiles = True
On Error GoTo 0
.IncludeBookmarks = True
.IncludeHyperlinks = True
.IncludeSlugWithPDF = False
.IncludeStructure = False
.InteractiveElementsOption = idInteractiveElementsOptions.idDoNotInclude
Rem Setting subsetFontsBelow to zero disallows font subsetting
Rem set subsetFontsBelow to some other value to use font subsetting.
.SubsetFontsBelow = 0
Rem Bitmap compression/sampling/quality options
Rem (note the additional "s" in "compression").
.ColorBitmapCompression = idBitmapCompression.idZip
.ColorBitmapQuality = idCompressionQuality.idEightBit
.ColorBitmapSampling = idSampling.idNone
Rem ThresholdToCompressColor is not needed in this example.
Rem ColorBitmapSamplingDPI is not needed when
Rem ColorBitmapSampling is set to none.
.GrayscaleBitmapCompression = idBitmapCompression.idZip
.GrayscaleBitmapQuality = idCompressionQuality.idEightBit
.GrayscaleBitmapSampling = idSampling.idNone
Rem ThresholdToCompressGray is not needed in this
Rem example.
Rem GrayscaleBitmapSamplingDPI is not needed when
Rem GrayscaleBitmapSampling is set to none.
.MonochromeBitmapCompression = idBitmapCompression.idZip
.MonochromeBitmapSampling = idSampling.idNone
Rem ThresholdToCompressMonochrome is not needed in this example.
Rem MonochromeBitmapSamplingDPI is not needed when
Rem MonochromeBitmapSampling is set to none.
Rem Other compression options.
.CompressionType = idPDFCompressionType.idCompressNone
.CompressTextAndLineArt = True
.CropImagesToFrames = True
第 3 章 ドキュメント
PDF としてのドキュメントの書き出し
52
.OptimizePDF = True
Rem Printers marks and prepress options.
Rem Get the bleed amounts from the document's bleed.
.BleedBottom = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedBottomOffset
.BleedTop = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedTopOffset
.BleedInside = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedInsideOrLeftOffset
.BleedOutside = myInDesign.ActiveDocument.DocumentPreferences.
DocumentBleedOutsideOrRightOffset
Rem If any bleed area is greater than zero, then export the bleed marks.
If ((.BleedBottom = 0) And (.BleedTop = 0) And (.BleedInside = 0) And
(.BleedOutside = 0)) Then
.BleedMarks = True
Else
.BleedMarks = False
End If
.ColorBars = True
Rem ColorTileSize and GrayTileSize are only used when
Rem the export format is set to JPEG2000.
Rem .ColorTileSize = 256
Rem .GrayTileSize = 256
.CropMarks = True
.OmitBitmaps = False
.OmitEPS = False
.OmitPDF = False
.PageInformationMarks = True
.PageMarksOffset = 12
.PDFColorSpace = idPDFColorSpace.idUnchangedColorSpace
.PDFMarkType = idMarkTypes.idDefault
.PrinterMarkWeight = idPDFMarkWeight.idP125pt
.RegistrationMarks = True
On Error Resume Next
.SimulateOverprint = False
On Error GoTo 0
.UseDocumentBleedWithPDF = True
Rem Set viewPDF to true to open the PDF in Acrobat or Adobe Reader.
.ViewPDF = False
End With
Rem Now export the document. You'll have to fill in your own file path.
myInDesign.ActiveDocument.Export idExportFormat.idPDFType, "c:¥myTestDocument.pdf", False
グレースケール PDF の書き出し
カラーを含む InDesign ドキュメントは、カラー PDF またはグレースケール PDF に書き出すことができます。
前述の 51 ページの「PDF 書き出しオプションの設定」節のスクリプトを変更し、グレースケールでの書き出
しを行うには、idPDFColorSpace オプションを、idUnchangedColorSpace から gray に変更します。次に例を示
します。
With app.pdfExportPreferences
.PDFColorSpace = idPDFColorSpace.idGRAY
End With
(カラーが含まれている小さいドキュメントを作成し、グレースケールで PDF に書き出す他のスクリプトに
ついては、GreyscalePDFforIDS を参照してください)。
第 3 章 ドキュメント
PDF としてのドキュメントの書き出し
53
ページ範囲の PDF 書き出し
指定したページ範囲を PDF として書き出す方法を、次のスクリプトに示します (完全なスクリプトについて
は、ExportPageRangeAsPDF を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Enter the names of the pages you want to export in the following line.
Rem Note that the page name is not necessarily the index of the page in the
Rem document (e.g., the first page of a document whose page numbering starts
Rem with page 21 will be "21", not 1).
myInDesign.PDFExportPreferences.PageRange = "1-3, 6, 9"
Rem Fill in your own file path.
myFile = "c:¥myTestFile.pdf"
myInDesign.ActiveDocument.Export idExportFormat.idPDFType, myFile, False
ページごとの PDF 書き出し
次のスクリプトでは、ドキュメントの各ページを個別の PDF ファイルとして書き出しています (完全なスク
リプトについては、ExportEachPageAsPDF を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
If myInDesign.Documents.Count <> 0 Then
Set myDocument = myInDesign.ActiveDocument
Rem VBScript doesn't have a native "get folder" statement, so we'll use
Rem InDesign's JavaScript to display a folder browser.
myJavaScript = "myFolder = Folder.selectDialog(""Choose a Folder"");
myFolderName = myFolder.fsName;"
Rem Run the string "myJavaScript" as a JavaScript
myFolderName = myInDesign.DoScript(myJavaScript,
idScriptLanguage.idJavascript)
If myFileSystemObject.FolderExists(myFolderName) Then
myExportPages myInDesign, myDocument, myFolderName
End If
End If
Function myExportPages(myInDesign, myDocument, myFolderName)
myDocumentName = myDocument.Name
Set myDialog = myInDesign.Dialogs.Add
With myDialog
.Name = "ExportPages"
With .DialogColumns.Add
With .DialogRows.Add
With .StaticTexts.Add
.StaticLabel = "Base Name:"
End With
Set myBaseNameField = .TextEditboxes.Add
myBaseNameField.EditContents = myDocumentName
myBaseNameField.MinWidth = 160
End With
End With
End With
myResult = myDialog.Show
If myResult = True Then
myBaseName = myBaseNameField.EditContents
Rem Remove the dialog box from memory.
myDialog.Destroy
For myCounter = 1 To myDocument.Pages.Count
第 3 章 ドキュメント
PDF としてのドキュメントの書き出し
54
myPageName = myDocument.Pages.Item(myCounter).Name
myInDesign.PDFExportPreferences.PageRange = myPageName
Rem Generate a file path from the folder name,
Rem the base document name, and the page name.
Rem Replace the colons in the page name (e.g., "Sec1:1") wtih
Rem underscores.
myPageName = Replace(myPageName, ":", "_")
myFilePath = myFolderName & "¥" & myBaseName & "_" &
myPageName & ".pdf"
myDocument.Export idExportFormat.idPDFType, myFilePath, False
Next
Else
myDialog.Destroy
End If
End Function
インタラクティブ機能を使用した PDF の書き出し
次のスクリプトは、インタラクティブ機能を使用したドキュメントを PDF として書き出します (完全なスク
リプトについては、ExportInteractivePDF を参照してください)。
Rem Given a document "myDocument," add page transitions...
For myCounter = 1 To myDocument.Spreads.Count
myDocument.Spreads.Item(myCounter).PageTransitionType =
idPageTransitionTypeOptions.idWipeTransition
myDocument.Spreads.Item(myCounter).PageTransitionDirection =
idPageTransitionDirectionOptions.idDown
myDocument.Spreads.Item(myCounter).PageTransitionDuration =
idPageTransitionDurationOptions.idMedium
Next
myInDesign.InteractivePDFExportPreferences.FlipPages = True
myInDesign.InteractivePDFExportPreferences.FlipPagesSpeed = 5
myInDesign.InteractivePDFExportPreferences.OpenInFullScreen = True
myInDesign.InteractivePDFExportPreferences.InteractivePDFInteractiveElementsOption =
idInteractivePDFInteractiveElementsOptions.idIncludeAllMedia
Rem Export the document to PDF.
Rem You'll have to fill in your own file path.
myDocument.Export idExportFormat.idInteractivePDF, "C:¥InteractivePDF.pdf", False
PDF フォームとしての書き出し
フォームフィールドを含む PDF を作成するには、PDF として保存した InDesign ドキュメントを Acrobat で開
いてフォームフィールドを適用するか、テキストフィールド、ラジオボタン、署名フィールドなどを直接
InDesign 上で適用し、Acrobat での編集作業を必要としない状態で PDF にフォームとして書き出します。
次のスクリプトでは、フォーム要素を InDesign ドキュメントに適用し、ドキュメントを PDF フォームとして
書き出しています (完全なスクリプトについては、ExportInteractivePDFForm を参照してください)。
第 3 章 ドキュメント
PDF としてのドキュメントの書き出し
Set myPage = myDocument.Pages.Item(1)
REM Create a textframe as firstname label
Set myTextFrame = myPage.TextFrames.Add
myTextFrame.GeometricBounds = Array(15, 15, 20, 35)
myTextFrame.Contents = "FirstName: "
REM Create a textbox as firstname input box
Set myTextBox = myPage.TextBoxes.Add
myTextBox.GeometricBounds = Array(15, 40, 20, 75)
REM Create another textframe as lastname label
Set myTextFrame1 = myPage.TextFrames.Add
myTextFrame1.GeometricBounds = Array(30, 15, 25, 35)
myTextFrame1.Contents = "LastName: "
REM Create another textbox as lastname input box
Set myTextBox = myPage.TextBoxes.Add
myTextBox.GeometricBounds = Array(30, 40, 25, 75)
REM Create a TextFrame to introduce the following checkbox
Set myTextFrame2 = myPage.TextFrames.Add
myTextFrame2.GeometricBounds = Array(15, 80, 20, 95)
myTextFrame2.Contents = "Hobby: "
REM Create some CheckBoxes
Set myCheckBox = myPage.CheckBoxes.Add
myCheckBox.GeometricBounds = Array(15, 100, 20, 105)
myCheckBox.Name = "Football "
Set myTextFrame3 = myPage.TextFrames.Add
myTextFrame3.GeometricBounds = Array(15, 107, 20, 125)
myTextFrame3.Contents = "Football "
Set myCheckBox1 = myPage.CheckBoxes.Add
myCheckBox1.GeometricBounds = Array(15, 130, 20, 135)
myCheckBox1.Name = "Basketball "
Set myTextFrame4 = myPage.TextFrames.Add
myTextFrame4.GeometricBounds = Array(15, 137, 20, 160)
myTextFrame4.Contents = "Basketball "
Set myCheckBox2 = myPage.CheckBoxes.Add
myCheckBox2.GeometricBounds = Array(15, 165, 20, 170)
myCheckBox2.Name = "Pingpong "
Set myTextFrame5 = myPage.TextFrames.Add
myTextFrame5.GeometricBounds = Array(15, 172, 20, 193)
myTextFrame5.Contents = "Pingpong "
REM Create a button for submit
Set submitButton = myPage.Buttons.Add
submitButton.GeometricBounds = Array(45, 15, 35, 35)
submitButton.Name = "Submit"
REM Fill contents to the button
Set myRightArrow1 = submitButton.States.Item(1).Polygons.Add
myRightArrow1.fillColor = myDocument.Colors.Item("Green")
myRightArrow1.Paths.Item(1).EntirePath = Array(Array(15, 35),Array(35,40),Array(15, 45))
REM Add the Rollover state.
Set myRolloverState1 = submitButton.States.Add
REM Add a shadow to the polygon in the Rollover state.
Set myRolloverArrow1 = myRolloverState1.Polygons.Add
myRolloverArrow1.fillColor = myDocument.Colors.Item("Green")
myRolloverArrow1.Paths.Item(1).EntirePath = Array(Array(15, 35),Array(35,40),Array(15, 45))
Set myFillTransparencySettings1 = myRolloverArrow1.FillTransparencySettings
myFillTransparencySettings1.DropShadowSettings.Mode = idShadowMode.idDrop
myFillTransparencySettings1.DropShadowSettings.Angle = 90
myFillTransparencySettings1.DropShadowSettings.XOffset = 0
myFillTransparencySettings1.DropShadowSettings.YOffset = 0
myFillTransparencySettings1.DropShadowSettings.Size = 6
REM Add a shadow to the polygon in the Click state.
Set myClickState1 = submitButton.States.Add
Set myClickArrow1 = myClickState1.Polygons.Add
myClickArrow1.FillColor = myDocument.Colors.Item("Blue")
myClickArrow1.Paths.Item(1).EntirePath = Array(Array(15, 35),Array(35,40),Array(15,45))
REM Set the behavior for the button.
Set SubmitForm = submitButton.SubmitFormBehaviors.Add
SubmitForm.BehaviorEvent = idBehaviorEvents.idMouseUp
55
第 3 章 ドキュメント
EPS としてのページの書き出し
56
REM Create a button for print
Set printButton = myPage.Buttons.Add
printButton.GeometricBounds = Array(45, 40, 35, 60)
REM Fill contents to the button
Set myRightArrow2 = printButton.States.Item(1).Polygons.Add
myRightArrow2.fillColor = myDocument.Colors.Item("Red")
myRightArrow2.Paths.Item(1).EntirePath = Array(Array(40, 35),Array(60,40),Array(40, 45))
REM Add the Rollover state.
Set myRolloverState2 = printButton.States.Add
REM Add a shadow to the polygon in the Rollover state.
Set myRolloverArrow2 = myRolloverState2.Polygons.Add
myRolloverArrow2.FillColor = myDocument.Colors.Item("Red")
myRolloverArrow2.Paths.Item(1).EntirePath = Array(Array(40, 35),Array(60,40),Array(40, 45))
Set myFillTransparencySettings2 = myRolloverArrow2.FillTransparencySettings
myFillTransparencySettings2.DropShadowSettings.Mode = idShadowMode.idDrop
myFillTransparencySettings2.DropShadowSettings.Angle = 90
myFillTransparencySettings2.DropShadowSettings.XOffset = 0
myFillTransparencySettings2.DropShadowSettings.YOffset = 0
myFillTransparencySettings2.DropShadowSettings.Size = 6
REM Add a shadow to the polygon in the Click state.
Set myClickState2 = printButton.States.Add
Set myClickArrow2 = myClickState2.Polygons.Add
myClickArrow2.FillColor = myDocument.Colors.Item("Blue")
myClickArrow2.Paths.Item(1).EntirePath = Array(Array(40, 35),Array(60,40),Array(40,45))
REM Set the behavior for the button.
Set PrintForm = printButton.PrintFormBehaviors.Add
PrintForm.BehaviorEvent = idBehaviorEvents.idMouseUp
REM Export the document to PDF.
myDocument.Export idExportFormat.idInteractivePDF, "C:¥SubmitForm.pdf", False
EPS としてのページの書き出し
ドキュメントを EPS として書き出すと、ファイルの各ページが個別の EPS グラフィックとして保存されます
(1 つの EPS には 1 ページしか書き出せないようになっています)。複数のページを書き出した場合、ファイル
名にはページのインデックスが付加されます。ドキュメント内のページのインデックスが、ページの名前に
なるとは限りません(ページが含まれているセクションのセクションオプションによって定義されます)。
すべてのページの EPS 書き出し
次のスクリプトでは、アクティブなドキュメントのページが、1 つまたは複数の EPS ファイルに書き出され
ます (完全なスクリプトについては、ExportAsEPS を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
myFile = "c:¥myTestFile.eps"
myInDesign.ActiveDocument.Export idExportFormat.idEPSType, myFile, False
ページ範囲の EPS 書き出し
EPS として書き出すページを制御するには、書き出しを行う前に、EPS export preferences の page range プロ
パティに、書き出すページのページ範囲を示す文字列を指定します (完全なスクリプトについては、
ExportPageRangeAsEPS を参照してください)。
第 3 章 ドキュメント
EPS としてのページの書き出し
57
Set myInDesign = CreateObject("InDesign.Application")
Rem Enter the name of the page you want to export in the following line.
Rem Note that the page name is not necessarily the index of the page in the
Rem document (e.g., the first page of a document whose page numbering starts
Rem with page 21 will be "21", not 1).
myInDesign.EPSExportPreferences.PageRange = "1-3, 6, 9"
Rem Fill in your own file path.
myFile = "c:¥myTestFile.eps"
myInDesign.ActiveDocument.Export idExportFormat.idEPSType, myFile, False
ファイル名を指定した EPS 書き出し
次のスクリプトでは、前述の例と比べてファイル名を細かく制御しながら各ページを EPS として書き出して
います (完全なスクリプトについては、ExportEachPageAsEPS を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
If myInDesign.Documents.Count <> 0 Then
Set myDocument = myInDesign.ActiveDocument
Rem VBScript doesn't have a native "get folder" statement, so we'll use
Rem InDesign's JavaScript to display a folder browser.
myJavaScript = "myFolder = Folder.selectDialog(""Choose a Folder"");
myFolderName = myFolder.fsName;"
Rem Run the string "myJavaScript" as a JavaScript
myFolderName = myInDesign.DoScript(myJavaScript,
idScriptLanguage.idJavascript)
If myFileSystemObject.FolderExists(myFolderName) Then
myExportEPSPages myInDesign, myDocument, myFolderName
End If
End If
Function myExportEPSPages(myInDesign, myDocument, myFolderName)
myDocumentName = myDocument.Name
Set myDialog = myInDesign.Dialogs.Add
With myDialog
.Name = "ExportPages"
With .DialogColumns.Add
With .DialogRows.Add
With .StaticTexts.Add
.StaticLabel = "Base Name:"
End With
Set myBaseNameField = .TextEditboxes.Add
myBaseNameField.EditContents = myDocumentName
myBaseNameField.MinWidth = 160
End With
End With
End With
myResult = myDialog.Show
If myResult = True Then
myBaseName = myBaseNameField.EditContents
Rem Remove the dialog box from memory.
myDialog.Destroy
For myCounter = 1 To myDocument.Pages.Count
第 3 章 ドキュメント
EPub の書き出し
58
myPageName = myDocument.Pages.Item(myCounter).Name
myInDesign.EPSExportPreferences.PageRange = myPageName
Rem Generate a file path from the folder name, the base document
Rem name, and the page name.
Rem Replace the colons in the page name (e.g., "Sec1:1") with
Rem underscores.
myPageName = Replace(myPageName, ":", "_")
myFilePath = myFolderName & "¥" & myBaseName & "_" & _
myPageName & ".eps"
myDocument.Export idExportFormat.idEPSType, myFilePath, False
Next
Else
myDialog.Destroy
End If
End Function
EPub の書き出し
InDesign スクリプティングでは、ページレイアウトドキュメントから EPub ファイルを作成する処理を完全に
制御できます。
現在のドキュメントの書き出し
次のスクリプトでは、デフォルトのオプションを使用して、現在のドキュメントを EPub として書き出して
います (完全なスクリプトについては、ExportEPub を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
myDocument.Export idExportFormat.idEPUB, "C:¥test¥ExportEPub.epub", False
EPub ファイルの作成をユーザーがさらに細かく制御できるようにするには、3 番目のパラメーターに true を
指定します。これにより、EPub 書き出しオプションダイアログボックスが表示されます。
EPub 書き出しオプションの設定
次のスクリプトでは、EPub 書き出しオプションを設定してから、書き出しを行っています (完全なスクリ
プトについては、ExportEPubWithOptions を参照してください)。
Rem Sets EPub export options, then exports the active document as EPub.
With myDocument.EPubExportPreferences
Rem Apply image alignment to anchored object settings.
.ApplyImageAlignmentToAnchoredObjectSettings = False
Rem The unit of space.
.SpaceUnit = idSpaceUnitType.idCssEm
Rem The unit of margin.
.MarginUnit = idSpaceUnitType.idCssEm
Rem Bottom margin of the epub.
.BottomMargin = 5
Rem Left margin of the epub.
.LeftMargin = 5
Rem Right margin of the epub.
.RightMargin = 5
Rem Top margin of the epub.
.TopMargin = 5
Rem If true, break InDesign document into smaller pieces when generating epub.
.BreakDocument = False
Rem The bullet export option.
.BulletExportOption = idBulletListExportOption.idAsText
第 3 章 ドキュメント
EPub の書き出し
.CSSExportOption = idStyleSheetExportOption.idEmbeddedCSS
.CustomImageSizeOption = idImageSizeOption.idSizeRelativeToPageWidth
.EmbedFont = True
.EpubCover = idEpubCover.idFirstPage
Rem This will take effect only when EpubCover is set to idExternalImage.
Rem .CoverImageFile = "C:¥conver.jpg"
.EpubPublisher = "Adobe Devtech"
Rem The export order.
.ExportOrder = idExportOrder.idLayoutOrder
Rem If true, output foornoteimmediately after its paragraph.
.FootnoteFollowParagraph = False
Rem If true, export epub in XHTML format. Otherwise, in DTBook format.
.Format = True
.GIFOptionsInterlaced = True
.GIFOptionsPalette = idGIFOptionsPalette.idWindowsPalette
Rem The epub unique identifier, like ISBN.
.Id = "123"
Rem Ignore object level image conversion settings.
.IgnoreObjectConversionSettings = True
Rem Alignment applied to images.
.ImageAlignment = idImageAlignmentType.idAlignCenter
Rem The file format to use for converted images.
Rem Valid only when copy optimized images and/or copy formatted images is true.
.ImageConversion = idImageConversion.idAutomatic
.ImageExportResolution = idImageResolution.idPpi150
Rem Image page break settings to be used with objects.
.ImagePageBreak = idImagePageBreakType.idPageBreakAfter
Rem Space After applied to images.
.ImageSpaceAfter = 2
Rem Space Before applied to images.
.ImageSpaceBefore = 2
Rem If true, include CSS definition.
.IncludeCSSDefinition = True
Rem If true, output document metadata into epub.
.IncludeDocumentMetadata = True
.JPEGOptionsFormat = idJPEGOptionsFormat.idBaselineEncoding
.JPEGOptionsQuality = idJPEGOptionsQuality.idHigh
Rem The PNG compression level.
.Level = 5
.NumberedListExportOption = idNumberedListExportOption.idAsText
Rem If true, format image based on layout appearence.
59
第 3 章 ドキュメント
EPub の書き出し
.PreserveLayoutAppearence = True
Rem If true, output local style override.
.PreserveLocalOverride = True
.StripSoftReturn = True
Rem If true, image page break settings will be used in objects.
.UseImagePageBreak = True
Rem Use InDesign TOC style to generate epub TOC.
.UseTocStyle = True
.ViewDocumentAfterExport = False
End With
myDocument.Export idExportFormat.idEPUB, "C:¥test¥ExportEPubWithOptions.epub", False
60
レイヤーの操作
4
章の更新ステータス
CS6
変更なし
InDesign のレイヤーは、レイアウト内のオブジェクトの重なり順を制御する上で重要な役割を果たします。
レイヤーは、互いに上へと重ね合わせられている複数枚の透明な水平面と考えることができます。また、同
じ種類のコンテンツを特定のレイヤーや一連のレイヤーに配置して、レイヤーを構成用のツールとして使用
することもできます。
ドキュメントには 1 つ以上のレイヤーを含めることができますが、各ドキュメントには少なくとも 1 つのレ
イヤーが含まれます。レイヤーはドキュメントと同じ幅で、特定のページやスプレッドに関連付けられるこ
とはありません。
この章では、InDesign レイアウトのレイヤーに関連するスクリプティングテクニックと、レイヤーに関する
一般的な操作について説明します。
レイヤーオブジェクトモデルについて
次の図に、レイヤーオブジェクトモデルを示します。図を参照するにあたって、次の点に注意してください。

図は、ドキュメントのオブジェクト階層におけるレイヤーの位置と内容に焦点を合わせています。スク
リプトでレイヤーの中身を操作するその他の方法についてすべてを図式化しようとしていません(例え
ば、レイヤーオブジェクト内にテキストフレームオブジェクトがあることがわかりますが、ストーリー
やテキストオブジェクト、ページ、スプレッドからもテキストフレームオブジェクトへの参照を取得す
ることができます)。

オブジェクト名は JavaScript 形式のものですが、オブジェクト階層はすべてのスクリプト言語で同じで
す。

左側の列にレイヤーの基本的なプロパティを、右側にレイヤーオブジェクトに含めることができるオブ
ジェクトを示しています。
重要な点として、ページアイテムのコレクションと AllPageItems のコレクションの違いに注意してくださ
い。ページアイテムのコレクションは、レイヤー内の最上位レベルのページアイテムのみが含まれたコレク
ションです。例えば、ページアイテムがグループに含まれている場合、PageItems のコレクションにこのペー
ジアイテムは現れません。これに対し、AllPageItems のコレクションは、レイヤーに割り当てられたすべて
のページアイテムが統合されたコレクションです。オブジェクト階層における位置は関係ありません。レイ
ヤー上のグループに含まれるページアイテムは、AllPageItems のコレクションには現れます。
同様に、AllGraphics プロパティには、オブジェクト階層における位置にかかわらず、レイヤーに割り当て
られたページアイテムに含まれているすべてのグラフィックが含まれます。
61
第 4 章 レイヤーの操作
レイヤーのスクリプト操作
62
レイヤーのスクリプト操作
InDesign のユーザーインターフェイスでは、レイヤーパネルを使用して、レイヤーの追加、削除、並べ替え、
複製、結合を行います。また、レイヤーパネルのレイヤープロキシをドラッグ&ドロップして、選択してい
るページアイテムを割り当てるレイヤーを変更することもできます (オブジェクトをレイヤーに割り当てる
方法について詳しくは、InDesign ヘルプを参照してください)。ここでは、InDesign スクリプティングでこれ
らの操作を実行する方法について説明します。
レイヤーの作成
新規レイヤーを作成する方法を、次のスクリプトに示します (完全なスクリプトについては、AddLayer を参
照してください)。
Rem Given a document "myDocument"...
Set myLayer = myDocument.Layers.Add()
新規レイヤーを作成した場合、ドキュメント内のすべてのレイヤーの一番上に配置されます。
第 4 章 レイヤーの操作
レイヤーのスクリプト操作
63
レイヤーの参照
InDesign スクリプティングでは、いくつかの方法でレイヤーオブジェクトを参照できます。ここでは、レイ
ヤーを参照する一般的な方法について説明します。
アクティブなレイヤーの取得
アクティブなレイヤーとは、新しいオブジェクトが作成されるレイヤーです。スクリプトを使用してアク
ティブなレイヤーを取得できます。次のスクリプトにその例を示します (完全なスクリプトについては、
ActiveLayer を参照してください)。
Rem Given a document "myDocument"...
Set myDocument = myInDesign.Documents.Item(1)
Set myLayer = myDocument.ActiveLayer
レイヤーインデックスによるレイヤーの参照
ドキュメントのレイヤーコレクションに含まれるレイヤーのインデックスを使用して、レイヤーへの参照を
取得できます。レイヤーのインデックスを使用して、レイヤーに対して繰り返し処理を行う方法を、次のス
クリプトに示します (完全なスクリプトについては、HideOtherLayers を参照してください)。
Rem Given a document "myDocument"...
Set myTargetLayer = myDocument.ActiveLayer
For myCounter = 1 to myDocument.Layers.Count
Rem If the layer is not the target layer, hide it.
If myDocument.Layers.Item(myCounter).Name <> myTargetLayer.Name Then
myDocument.Layers.Item(myCounter).Visible = False
End If
Next
ドキュメントのレイヤーコレクションに含まれるレイヤーを参照するときには、負の数も使用できます。レ
イヤー -1 は、コレクション内の最後(一番下)のレイヤーを参照します。
レイヤー名によるレイヤーの参照
レイヤーの名前を使用してレイヤーへの参照を取得することもできます。次のスクリプトにその例を示しま
す (完全なスクリプトについては、LayerName を参照してください)。
Rem Given a reference to the InDesign Application object "myInDesign"...
Set myLayer = myInDesign.Documents.Item(1).Layers.Item("Text Layer")
相対参照の使用
あるレイヤーを基準として、PreviousItem メソッドを使用してその上のレイヤーを参照したり、NextItem メ
ソッドを使用してその下のレイヤーを参照したりできます。次のスクリプトにその例を示します (完全なス
クリプトについては、RelativeLayerReferences を参照してください)。いずれのメソッドも、参照レイヤーをパ
ラメーターで指定します。
Rem Given a document "myDocument"...
Set myLayer = myDocument.Layers.Item(5)
myDocument.activeLayer = myLayer
Set myNextLayer = myDocument.Layers.NextItem(myLayer)
Set myPreviousLayer = myDocument.Layers.PreviousItem(myLayer)
myString = "The layer below the target layer is " & myNextLayer.name & VBCr
myString = myString & "The layer above the target layer is " & myPreviousLayer.name
MsgBox(myString)
第 4 章 レイヤーの操作
レイヤーのスクリプト操作
64
PreviousItem および NextItem メソッドで、指定したレイヤー(次または前のレイヤー)が存在しなかった
場合、無効なレイヤーの参照が返されます。エラーは発生しません。
範囲内のレイヤーの参照
一連のレイヤーを参照するには、ItemByRange メソッドを使用します。範囲内のレイヤーへの参照を取得した
後、範囲内のすべてのレイヤーのプロパティを設定する方法を、次のスクリプトに示します (完全なスクリ
プトについては、HideLayersAbove を参照してください)。
Rem Given a document "myDocument"...
Set myLayer = myDocument.Layers.Item(5)
myDocument.ActiveLayer = myLayer
Rem Now hide all of the layers above the current layer.
Set myLayers = myDocument.Layers.ItemByRange(1, myTargetLayer.Index - 1)
Rem Iterate through the range of layers.
For myCounter = 1 To myLayers.Count
myLayers.Item(myCounter).Visible = False
Next
レイヤーの削除
特定のドキュメントからレイヤーを削除するには、Delete メソッドを使用します。次のスクリプトにその例
を示します (完全なスクリプトについては、DeleteLayer を参照してください)。ドキュメント内の最後に
残ったレイヤーは削除できません。
Rem Given a document "myDocument" containing a layer named "Delete This Layer"...
Set myLayer = myDocument.Layers.Item("Delete This Layer")
myLayer.Delete()
レイヤーの移動
ドキュメント内のレイヤーの重なり順を変更するには、move メソッドを使用します。次のスクリプトにその
例を示します (完全なスクリプトについては、MoveLayer を参照してください)。
Rem Given a document "myDocument" containing at least two layers...
Set myLayerA = myDocument.Layers.Item(1)
Set myLayerB = myDocument.Layers.ITem(2)
myLayerA.Move idLocationOptions.idAfter,myLayerB
レイヤーの複製
レイヤーのコピーを作成するには、duplicate メソッドを使用します。次のスクリプトにその例を示します
(完全なスクリプトについては、DuplicateLayer を参照してください)。
Rem Given a layer "myLayer"...
Set myNewLayer = myLayer.Duplicate()
レイヤーの結合
2 つ以上のレイヤーを、レイヤーに割り当てられているページアイテムも含めて 1 つのレイヤーに結合する
方法を、次のスクリプトに示します (完全なスクリプトについては、MergeLayers を参照してください)。
Rem Given the layers "myLayer1" and "myLayer2"...
myLayer1.Merge(myLayer2)
第 4 章 レイヤーの操作
レイヤーのスクリプト操作
65
レイヤーへのページアイテムの割り当て
レイヤーにページアイテムを割り当てるには、ページアイテムを作成するときにレイヤーを参照するか(す
べてのページアイテムの add メソッドは、レイヤーをパラメーターで指定できます)、既存のページアイテム
の ItemLayer プロパティを設定します。この両方の方法で、レイヤーにページアイテムを割り当てる方法を、
次のスクリプトに示します (完全なスクリプトについては、AssignPageItemsToLayers を参照してください)。
Rem Given a reference to a page "myPage," and a document "myDocument,"
Rem create a text frame on a layer named "TextFrames"
Set myTextFrame = myPage.TextFrames.Add(myDocument.Layers.Item("TextFrames"))
myTextFrame.geometricBounds = Array(72, 72, 144, 144)
Rem Create a rectangle on the current target layer.
Set myRectangle = myPage.Rectangles.Add
myRectangle.geometricBounds = Array(72, 144, 144, 216)
Rem Move the rectangle to a specific layer.
myRectangle.ItemLayer = myDocument.Layers.Item("Rectangles")
Rem Create a series of ovals.
For myCounter = 72 To 172 Step 10
Set myOval = myPage.Ovals.Add
myOval.geometricBounds = Array(216, myCounter, 226, myCounter + 10)
Next
Rem Move all of the ovals on the page to a specific layer.
For myCounter = 1 To myPage.Ovals.Count
myPage.Ovals.Item(myCounter).ItemLayer = myDocument.Layers.Item("Ovals")
Next
レイヤーのプロパティの設定
レイヤーのプロパティは、レイヤーのレイヤー名、カラー、表示/非表示などの属性を制御します。ここで
は、レイヤーのプロパティを操作する方法について説明します。
レイヤーの基本的なプロパティの設定
レイヤーの基本的なプロパティには、レイヤーの名前、レイヤーのハイライトカラー、レイヤーの表示/非
表示、レイヤー上のテキストオブジェクトがテキストの回り込み設定を無視するかどうかの設定などがあり
ます。これらの基本的なレイヤーのプロパティを設定する方法を、次のスクリプトに示します (完全なスク
リプトについては、BasicLayerProperties を参照してください)。
Rem Given a document "myDocument"...
Set myLayer = myDocument.Layers.Add
myLayer.Name = "myLayer"
myLayer.LayerColor = idUIColors.idCHARCOAL
myLayer.IgnoreWrap = False
myLayer.Visible = True
レイヤーガイドの操作
ページアイテムと同じように、特定のレイヤーにガイドを割り当てることができます。レイヤーのガイドは、
表示/非表示を選択でき、さらにロックをかけたり解除したりすることもできます。レイヤーのガイドを操
第 4 章 レイヤーの操作
レイヤーのスクリプト操作
66
作する方法を、次のスクリプトに示します (完全なスクリプトについては、LayerGuides を参照してくださ
い)
。
Rem
Rem
Set
Rem
For
Given a document "myDocument" and a page "myPage" containing at least one guide...
Create a new layer.
myLayer = myDocument.Layers.Add
Move all of the guides on the page to the new layer.
myCounter = 1 to myPaqe.Guides.Count
myPage.Guides.Item(myCounter).ItemLayer = myLayer
Next
myLayer.LockGuides = True
myLayer.ShowGuides = True
レイヤーのプリントと表示/非表示の制御
レイヤー上のオブジェクトのプリントと表示/非表示を制御できます。次のスクリプトにその例を示します
(完全なスクリプトについては、LayerControl を参照してください)。
Rem Given a document "myDocument" containing layers named "Background,"
Rem "Language A,", "Language B," and "Language C," export the "Background"
Rem layer and each "Language" layer to PDF as separate PDF files...
Set myFileSystemObject = New FileSystemObject
Set myFolder = myFileSystemObject.GetSpecialFolder(TemporaryFolder)
myPath = myFolder.ParentFolder.ParentFolder.Path & "¥Desktop¥"
For myCounter = 1 To 3
Select Case myCounter
Case 1:
myVersion = "Language A"
Case 2:
myVersion = "Language B"
Case 3:
myVersion = "Language C"
End Select
For myLanguageCounter = 1 To myDocument.Layers.Count
If myDocument.Layers.Item(myLanguageCounter).name = myVersion Or
myDocument.Layers.Item(myLanguageCounter).name = "Background" Then
myDocument.Layers.Item(myLanguageCounter).Visible = True
myDocument.Layers.Item(myLanguageCounter).Printable = True
Else
myDocument.Layers.Item(myLanguageCounter).Visible = False
myDocument.Layers.Item(myLanguageCounter).Printable = False
End If
Next
myFilePath = myPath & myVersion & ".pdf"
myDocument.Export idExportFormat.idPDFType, myFilePath
Next
レイヤーのロック
レイヤーにはロックをかけることができます。ロックをかけると、レイヤー上のページアイテムは編集でき
なくなります。レイヤーのロックをかける方法と解除する方法を、次のスクリプトに示します (完全なスク
リプトについては、LockLayersBelow を参照してください)。
Rem
Set
Set
For
Given a document "myDocument"...
myTargetLayer = myDocument.ActiveLayer
myLayers = myDocument.Layers.ItemByRange(myDocument.Layers.Count, myTargetLayer.Index + 1)
myCounter = 1 To myLayers.Count
myLayers.Item(myCounter).Locked = True
Next
5
ページアイテムの操作
章の更新ステータス
CS6
変更なし
この章では、InDesign レイアウトに表示されるページアイテム(長方形、楕円形、グラフィックの線、多角
形、テキストフレーム、ボタン、グループなど)に関連するスクリプティングテクニックを紹介します。
この章の内容は、次のとおりです。

ページアイテムの作成

ページアイテムの形状

パスとパスポイントの操作

グループの作成

ページアイテムの複製と移動

ページアイテムの変形

アーティクルの使用
ページアイテムの作成
InDesign レイアウトのページアイテムは階層的に配置され、なんらかのコンテナオブジェクト内に表示され
ます。例えば、スプレッド、ページ、その他のページアイテム、グループおよびテキスト文字はすべて、
ページアイテムを格納できるコンテナオブジェクトです。InDesign スクリプトオブジェクトモデルにあるコ
ンテナのこの階層は、InDesign のユーザーインターフェイスの階層と同じです。つまり、あるページ上で長
方形ツールをドラッグして長方形を作成する操作は、そのページが、作成する長方形のコンテナ(親)にな
るよう指定していることになります。楕円形を多角形の中に貼り付ける操作は、多角形が楕円形の親になる
よう指定していることになります。多角形は親でもありますが、その親であるページにとっては子オブジェ
クトとなります。
MakeRectangle スクリプトに示すように、一般に、新しいページアイテムの作成は簡単です。ページアイテ
ムを作成するには、そのページアイテムを格納するオブジェクトを指定します。
Rem Given a page "myPage", create a new rectangle at the default size and location
myPage.Rectangles.Add
前述のスクリプトでは、新規ドキュメントの最初のページに新しい長方形が作成されます。この長方形は、
デフォルトの位置(ページの左上隅付近)に、デフォルトのサイズ(1 辺が約 10 ポイントの正方形)で表示
されます。MakeRectangleWithProperties スクリプトに示すように、長方形の移動や大きさの変更は、いずれ
もその境界線のプロパティに新しい値を指定することで実行されます。
Rem Given a page "myPage", create a new rectangle and specify its size and location...
Set myRectangle = myPage.Rectangles.Add
myRectangle.GeometricBounds = Array(72, 72, 144, 144)
67
第 5 章 ページアイテムの操作
ページアイテムの作成
68
ページアイテムの種類
「汎用的な」ページアイテムは作成できない点に注意することが重要です。特定の種類(長方形、楕円形、グ
ラフィックの線、多角形、テキストフレームまたはボタン)のページアイテムを作成する必要があります。
ページアイテムの種類は、そのページアイテムの形状を変更したときにも、変化することに注意してくださ
い。例えば、長方形は常に、4 つのパスポイントと 90° の内角を備えた閉じた単一のパスで構成されていま
す。しかし、1 つのパスポイントの位置を変更したり、別のパスを追加したりすると、ページアイテムの種類
は多角形に変化します。パスを開いて、4 つのパスポイントの 2 つを削除すると、ページアイテムの種類はグ
ラフィックの線に変化します。長方形、楕円形、グラフィックの線、多角形などの種類は、次の要素のみで
定義されます。

オブジェクトにあるパスの数。複数のパスがあるページアイテムは多角形です。

オブジェクトの最初のパスにあるポイントの数と位置。
ページアイテムの種類を判断するには、次の例を使用します。
myPageItemType = TypeName(myPageItem)
前述の結果は、ページアイテムの種類を表す文字列になります。
ページアイテムの種類の取得
汎用的なページアイテムへの参照があるときに、そのページアイテムの種類を確認する場合は、TypeName
を使用して特定の種類を取得します。
Rem Given a generic page item "myPageItem"...
myType = TypeName(myPageItem)
MsgBox myType
ページアイテムの参照
特定のコンテナ(ドキュメント、レイヤー、ページ、スプレッド、グループ、テキストフレーム、ページア
イテムなど)の内部にあるページアイテムを参照する場合は、コンテナオブジェクトの PageItems コレク
ションを使用します。これによって、オブジェクトの内部にある最上レベルのページアイテムのコレクショ
ンを参照できます。次に例を示します。
Rem Given a reference to InDesign "myInDesign"...
SSet myPageItems = myInDesign.Documents.Item(1).Pages.Item(1).PageItems
結果のコレクション(myPageItems)に含まれないものとしては、グループ内部のオブジェクト(コレク
ションにグループが格納されている場合)、他のページアイテムの内部にあるオブジェクト(コレクションに
親ページアイテムが格納されている場合)またはテキストフレーム内のページアイテムがあります。他の
ページアイテムの内部にネストされているアイテムなど、所定のコンテナにあるすべてのアイテムについて
参照を取得するには、AllPageItems プロパティを使用します。
Rem Given a reference to InDesign "myInDesign"...
Set myAllPageItems = myInDesign.Documents.Item(1).Pages.Item(1).AllPageItems
結果のコレクション(myAllPageItems)には、階層内の位置に関係なく、ページ上のすべてのオブジェクト
が含まれます。
ページアイテムを参照するもう 1 つの方法は、そのアイテムの label プロパティを使用する方法です。これ
は、他のオブジェクトの name プロパティ(段落スタイルやレイヤーなど)を使用するのと同じです。次のス
クリプトに、ラベルが myLabel に設定されているページアイテムの配列を取得する例を示します。
Rem Given a reference to InDesign "myInDesign"...
Set myPageItems = myInDesign.Documents.Item(1).Pages.Item(1).PageItems.Item("myLabel")
ページ上のページアイテムに指定されたラベルがない場合は、空の配列が返されます。
第 5 章 ページアイテムの操作
ページアイテムの作成
69
ページアイテムの形状
ページアイテムに関する作業を行うときは、InDesign のページアイテムの位置とシェイプの指定において、
定規と測定値がどのように相互に機能するかを理解している必要があります。InDesign のユーザーインター
フェイスのコントロールパネルを使用する場合、InDesign の座標系を既に理解していると想定されますが、
要約を簡潔に示しておきます。

オブジェクトは、定規に表示される座標との相対位置で形成されます。

原点をドラッグしたり、定規の基点を変更して原点の位置を変更したりすると、定規の座標は変化しま
す。

ページアイテムは 1 つ以上のパスで構成され、パスは 2 つ以上のパスポイントで構成されます。パスは、
開いた状態または閉じた状態の場合があります。

パスポイントには、1 つのアンカーポイント(ポイント自体の位置)と、2 つのコントロールハンドル
(パスポイントの前にある線区分のカーブを制御する左方向線と、ポイントの後にある線区分のカーブを
制御する右方向線)があります。これらの各プロパティには、(x, y)形式の配列があります(x はポイン
トの水平方向の位置、y は垂直方向の位置)。この配列には、ポイントまたはコントロールハンドルの位
置が、現在の定規の座標で格納されます。
前述の内容は、スクリプトでページアイテムを形成する必要がある場合は、原点の位置も制御する必要があ
り、場合によっては使用時の測定単位を設定する必要があることを意味します。
パスとパスポイントの操作
簡単なページアイテムでは、ほとんどの場合、オブジェクトのシェイプを定義するパスとパスポイントにつ
いて考慮する必要はありません。長方形、楕円形、テキストフレームは、この章で前述した例が示すように、
それぞれの境界線を指定することで作成できます。
ただし、パスポイントの位置を指定してパスのシェイプを形成または変更することが必要になる場合があり
ます。この場合は、パスの各パスポイントのアンカーポイント、左方向線および右方向線を個別に設定する
か(DrawRegularPolygon_Slow スクリプトを参照してください)、パスの EntirePath プロパティを使用してパ
スポイントのすべての位置を一度に設定できます(DrawRegularPolygon_Fast スクリプトを参照してくださ
い)
。後者のアプローチのほうが高速です。
EntirePath プロパティに使用する配列のアイテムには、アンカーポイントのみを指定するか、アンカーポイン
トとコントロールハンドルを指定できます。次に、アンカーポイントの位置のみが指定されている配列の例
を示します。
Array(Array(x1, y1), Array(x2, y2), ...)
x と y には、アンカーの位置を指定します。
次に、パスポイントがすべて指定されている配列(つまり、左方向線、アンカー、右方向線が、順に指定さ
れている配列)の例を示します。
Array(Array(Array(xL1, YL1), Array(x1, y1), Array(xR1, yR1)), Array(Array(xL2, YL2), Array(x2,
y2), Array(xR2, yR2)), ...)
xL と yL には左方向線を、x と y にはアンカーポイントを、xR と yR には右方向線を指定します。
次の例のように、2 つのアプローチを組み合わせることもできます。
Array(Array(Array(xL1, YL1), Array(x1, y1), Array(xR1, yR1)), Array(x2, y2), ...)
対象となるパスのポイントの数と、配列に指定するポイントの数は、同じである必要はありません。
EntirePath プロパティに配列が適用される際は、パスに対してポイントが自動的に追加または削除されます。
第 5 章 ページアイテムの操作
ページアイテムのグループ化
70
次の AddPathPoint スクリプトは、EntirePath プロパティを使用せずにパスポイントをパスに追加する方法を
示しています。
Rem Given a graphic line "myGraphicLine"...
Set myPathPoint = myGraphicLine.Paths.Item(1).PathPoints.Add
Rem Move the path point to a specific location.
myPathPoint.Anchor = Array(144, 144)
次の DeletePathPoint スクリプトは、パスからパスポイントを削除する方法を示しています。
Rem Given a polygon "myPolygon", remove the
Rem last path point in the first path.
myPolygon.Paths.Item(1).PathPoints.Item(-1).Delete
ページアイテムのグループ化
InDesign のユーザーインターフェイスでページアイテムのグループを作成するには、ページアイテムを選択
し、次に、オブジェクトメニューから「グループ」を選択します(または、対応するキーボードショート
カットを押します)。InDesign スクリプティングでは、次の Group スクリプトのように、グループ化するペー
ジアイテムを格納しているオブジェクト(通常はページやスプレッド)に指示をして、ページアイテムをグ
ループ化します。
Rem Given a page "myPage" containing at least two ovals and two rectangles...
ReDim myArray(0)
Rem Add the items to the array.
myPush myArray, myPage.Rectangles.Item(1), True
myPush myArray, myPage.Rectangles.Item(2), True
myPush myArray, myPage.Ovals.Item(1), True
myPush myArray, myPage.Ovals.Item(1), True
Rem Group the items.
myPage.Groups.Add myArray
グループを解除するには、次の Ungroup スクリプトのように、グループ解除するグループ自体に指示をしま
す。
Rem Given a group "myGroup"...
Set myPageItems = myGroup.Ungroup
グループ内のページアイテムのシェイプやフォーマット、コンテンツを変更する際、グループの解除は不要
です。代わりに、他のページアイテムの場合と同様に、変更するページアイテムへの参照を取得するだけで
す。
ページアイテムの複製と移動
InDesign のユーザーインターフェイスでは、ページアイテムを選択して新しい位置にドラッグすることで、
ページアイテムを移動できます。ページアイテムのコピーは、コピーして貼り付ける方法や、Option または
Alt キーを押しながらオブジェクトをドラッグする方法、編集メニューから「複製」、「元の位置にペースト」
または「繰り返し複製」を選択する方法で作成することもできます。InDesign スクリプティングでは、ペー
ジアイテムの位置を変更する場合は move メソッドを使用し、ページアイテムのコピーを作成する(必要な
場合はそのコピーを別の位置に移動する)場合は duplicate メソッドを使用できます。
この move メソッドには、オプションの 2 つのパラメーター MoveTo と MoveBy のいずれかを指定できます。
この 2 つのパラメーターは、水平値と垂直値の 2 つの測定単位の配列で構成されています。MoveTo には、原
点の現在の位置と相対的で、配列に指定されている位置への絶対的な移動を指定します。MoveBy には、現
在のページアイテム自体の位置から相対的に、ページアイテムをどの程度移動するか(距離)を指定します。
次の Move スクリプトに、これらの 2 つのアプローチの相違を示します。
第 5 章 ページアイテムの操作
ページアイテムの複製と移動
71
Rem Given a reference to a rectangle "myRectangle"...
Rem Move the rectangle to the location (12, 12).
Rem Absolute move:
myRectangle.Move Array(12, 12)
Rem Move the rectangle *by* 12 points horizontally, 12 points vertically.
Rem Relative move (note empty first parameter):
myRectangle.Move , Array(12, 12)
Rem Move the rectangle to another page (rectangle appears at (0,0).
Set myPage = myInDesign.Documents.Item(1).Pages.Add
myRectangle.Move myPage
Rem To move a page item to another document, use the Duplicate method.
move メソッドによってオブジェクトが実際に移動することに注意してください。別のドキュメントに移動
したページアイテムは、元のドキュメントから削除されます。元のオブジェクトを残したままオブジェクト
を別の位置に動かすには、duplicate メソッドを使用します(次の例を参照してください)。
ページアイテムのコピーを作成するには、duplicate メソッドを使用します。デフォルトでは、duplicate メ
ソッドによって、元のオブジェクトと同じ位置にオブジェクトの「クローン」が作成されます。複製したオ
ブジェクトを新しい位置に移動(同じドキュメント内の他のページへの移動や完全に別のドキュメントへの
移動など)するには、duplicate メソッドでオプションのパラメーターを使用します。
Rem
Rem
Rem
Rem
Set
Rem
Rem
Rem
Set
Rem
Set
Set
Rem
Set
Set
Given a reference to a rectangle "myRectangle"...
Duplicate the rectangle and move the
duplicate to the location (12, 12).
Absolute move:
myDuplicate = myRectangle.Duplicate(Array(12, 12))
Duplicate the rectangle and move the duplicate *by* 12
points horizontally, 12 points vertically.
Relative move (note empty first parameter):
myDuplicate = myRectangle.Duplicate (, Array(12, 12))
Duplicate the rectangle to another page (rectangle appears at (0,0).
myPage = myInDesign.Documents.Item(1).Pages.Add
myDuplicate = myRectangle.Duplicate(myPage)
Duplicate the rectangle to another document.
myDocument = myInDesign.Documents.Add
myDuplicate = myRectangle.Duplicate(myDocument.Pages.Item(1))
InDesign スクリプティングではコピーして貼り付ける方法も使用できますが、この方法を使用するスクリプ
トの場合、
(コピーする)オブジェクトを選択し、(貼り付ける際は)現在の表示状態に影響される状態で、
貼り付け対象要素の位置を設定する必要があります。これは、コピーして貼り付ける方法を使用するスクリ
プトは、複製して移動する方法を使用するスクリプトよりも確実性が低い(失敗する可能性が高い)ことを
意味します。可能な限り、現在の表示や選択状態に依存しないスクリプトを記述してください。
複合パスの作成
InDesign では、オブジェクト/パス/複合パスを作成メニューオプションを使用して、2 つ以上のページア
イテムのパスを、複数のパスが含まれる単一のページアイテムに結合することができます。InDesign スクリ
プティングでこの処理を行うには、ページアイテムの MakeCompoundPath メソッドを使用します。次のスク
リプトにその例を示します(完全なスクリプトについては、MakeCompoundPath スクリプトを参照してくだ
さい)。
Rem Given a rectangle "myRectangle" and an Oval "myOval"...
myRectangle.MakeCompoundPath myOval
複合パスを作成すると、複合パスの作成に使用したオブジェクトの種類に関係なく、結果として形成される
オブジェクトの種類は多角形になります。
複合パスを解除して、複合パスの各パスを個別のページアイテムに変換するには、ページアイテムの
ReleaseCompoundPath メソッドを使用します。次のスクリプトにその例を示します(完全なスクリプトにつ
いては、ReleaseCompoundPath スクリプトを参照してください)。
第 5 章 ページアイテムの操作
ページアイテムの複製と移動
72
Rem Given a polygon "myPolygon" (all compound paths are type Polygon)...
Set mPageItems = myPolygon.ReleaseCompoundPath
パスファインダー機能の使用
InDesign のパスファインダー機能には、InDesign ページの複数ページアイテム間の関係を操作する方法が用
意されています。ページアイテムのパスを結合したり、あるページアイテムの領域を別のページアイテムか
ら取り除いたり、2 つ以上のページアイテムが交差している領域から新しいページアイテムを作成したりす
ることができます。すべてのページアイテムでは、パスファインダー機能に関連する AddPath、
ExcludeOverlapPath、IntersectPath、MinusBack および SubtractPath の各メソッドがサポートされています。
パスファインダーのすべてのメソッドは同じように機能します。ユーザーは、操作の基本として使用する
ページアイテムの配列を用意します(ユーザーインターフェイスでパスファインダー操作を選択する前に、
一連のページアイテムを選択する場合と同様です)。
いずれかのパスファインダー操作を適用すると、オブジェクトの種類が変更される可能性が非常に高いこと
に注意してください。操作の結果、1 つまたは複数のパスに存在するポイントの数が幾つになるか、そしてど
の位置に来るかによって、オブジェクトの種類が決まります。
2 つのページアイテムを 1 つのページアイテムに結合するには、例えば、次のスクリプトに示すようなアプ
ローチを使用します(完全なスクリプトについては、AddPath を参照してください)。
Rem Given a rectangle "myRectangle" and an Oval "myOval"...
myRectangle.AddPath myOval
ExcludeOverlapPath メソッドは、重なり合った 2 つ以上のページアイテムの交差していない領域に基づいて新
しいパスを作成します。次のスクリプトにその例を示します(完全なスクリプトについては、
ExcludeOverlapPath スクリプトを参照してください)。
Rem Given a rectangle "myRectangle" and an Oval "myOval"...
myRectangle.ExcludeOverlapPath myOval
IntersectPath メソッドは、2 つ以上のページアイテムの交差している領域から新しいページアイテムを作成し
ます。次のスクリプトにその例を示します(完全なスクリプトについては、IntersectPath を参照してくださ
い)
。
Rem Given a rectangle "myRectangle" and an Oval "myOval"...
myRectangle.IntersectPath myOval
MinusBack メソッドは、最背面のオブジェクトの前面にある 1 つまたは複数のページアイテムから、最背面
のオブジェクトと交差している領域を取り除きます。次のスクリプトにその例を示します(完全なスクリプ
トについては、MinusBack を参照してください)。
Rem Given a rectangle "myRectangle" and an Oval "myOval"...
myRectangle.MinusBack myOval
SubtractPath メソッドは、最前面のオブジェクトの背面にある 1 つまたは複数のページアイテムから、最前面
のオブジェクトと交差している領域を取り除きます。次のスクリプトにその例を示します(完全なスクリプ
トについては、SubtractPath を参照してください)。
Rem Given a rectangle "myRectangle" and an Oval "myOval"...
myOval.SubtractPath myRectangle
第 5 章 ページアイテムの操作
ページアイテムの複製と移動
73
ページアイテムのシェイプの変換
InDesign のページアイテムは、オブジェクト/シェイプを変換メニューで表示されるオプションを使用する
か、パスファインダーパネル(ウィンドウ/オブジェクトとレイアウト/パスファインダー)を使用して、
他のシェイプに変換できます。InDesign スクリプティングのページアイテムでは、ConvertShape メソッドが
サポートされています。次のスクリプトにその例を示します(完全なスクリプトについては、ConvertShape
を参照してください)。
Rem Given a rectangle "myRectangle"...
myRectangle.ConvertShape idConvertShapeOptions.idConvertToRoundedRectangle
ConvertShape メソッドには、反転パスの開閉方法も用意されています。次のスクリプトにその例を示します
(完全なスクリプトについては、OpenPath を参照してください)。
Rem Given a rectangle "myRectangle"...
myRectangle.ConvertShape idConvertShapeOptions.idConvertToOpenPath
ページアイテムの配置
InDesign レイアウトのページアイテムは、レイヤー内での重なり順を調整することによって、前面または背
面に相互に配置したり、別のレイヤーに配置したりできます。次のスクリプトに、レイヤー内でオブジェク
トを前面または背面に移動する方法と、オブジェクトの相対的な重なり順を制御する方法を示します(完全
なスクリプトについては、StackingOrder を参照してください)。
Rem Given a rectangle "myRectangle" and an oval "myOval",
Rem where "myOval" is in front of "myRectangle", bring
Rem the rectangle to the front...
myRectangle.BringToFront
ページアイテムを作成する場合は、そのページアイテムのレイヤーを指定できますが、レイヤー間でページ
アイテムを移動することもできます。これを実行する場合は、ページアイテムの ItemLayer プロパティが重要
な役割を果たします。次のスクリプトにその例を示します(完全なスクリプトについては、ItemLayer を参照
してください)。
Rem Given a rectangle "myRectangle" and a layer "myLayer",
Rem send the rectangle to the layer...
myRectangle.ItemLayer = myInDesign.Documents.Item(1).Layers.Item("myLayer")
ドキュメント内でのレイヤーの重なり順は、レイヤー自体の Move メソッドを使用して変更することもでき
ます。次のスクリプトにその例を示します(完全なスクリプトについては、MoveLayer を参照してくださ
い)
。
Rem Given a layer "myLayer", move the layer behind
Rem the default layer (the lowest layer in the document
Rem is Layers.Item(-1).
myLayer.Move idLocationOptions.idAfter, myInDesign.Documents.Item(1).Layers.Item(-1)
第 5 章 ページアイテムの操作
ページアイテムの変形
74
ページアイテムの変形
変形には、拡大・縮小、回転、シアー(歪み)、移動(または変換)があります。スクリプティングでは、
transform メソッドを使用して変形を適用します。InDesign CS3(5.0)より前の InDesign バージョンで使用さ
れていた resize、rotate、shear の各メソッドは、この 1 つのメソッドに置き換えられました。
transform メソッドの使用
transform メソッドには、オブジェクトに適用する変形または一連の変形を定義する変形マトリックス
(TransformationMatrix)オブジェクトが必要です。変形マトリックスには、定規、回転、シアー、変換など
の操作の組み合わせを指定できます。
オブジェクトに変形を適用する順序は重要です。異なる順序で変形を適用すると、まったく異なる結果とな
る可能性があります。
オブジェクトを変形するには、次の 2 つの手順に従います。
1.
変形マトリックスを作成します。
2.
この変形マトリックスを transform メソッドを使用してオブジェクトに適用します。適用する際は、変
形が行われる座標系も指定します。座標系について詳しくは、77 ページの「座標スペース」を参照して
ください。さらに、変形の中心、つまり変形の基点を指定します。変形の基点について詳しくは、
78 ページの「変形の基点」を参照してください。
次のスクリプトに、ページアイテムを変形する基本的なプロセスの例を示します (完全なスクリプトについ
ては、TransformExamples を参照してください)。
Rem Rotate a rectangle "myRectangle" around its center point.
set myRotateMatrix = myInDesign.transformationMatrices.add(, , , 27)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myRotateMatrix
Rem Scale a rectangle "myRectangle" around its center point.
set myScaleMatrix = myInDesign.TransformationMatrices.Add(.5, .5)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myScaleMatrix
Rem Shear a rectangle "myRectangle" around its center point.
set myShearMatrix = myInDesign.TransformationMatrices.Add(, , 30)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myShearMatrix
Rem Rotate a rectangle "myRectangle" around a specified ruler point ([72, 72]).
Set myRotateMatrix = myInDesign.transformationMatrices.add(, , , 27)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, Array(Array(72, 72),
idAnchorPoint.idCenterAnchor), myRotateMatrix, , True
Rem Scale a rectangle "myRectangle" around a specified ruler point ([72, 72]).
Set myScaleMatrix = myInDesign.transformationMatrices.add(.5, .5)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, Array(Array(72, 72),
idAnchorPoint.idCenterAnchor), myScaleMatrix, , True
変形関数を、簡単に使用できる一連の関数に「ラップ」するスクリプトについては、Transform スクリプトを
参照してください。
第 5 章 ページアイテムの操作
ページアイテムの変形
75
変形マトリックスの操作
一度作成した変形マトリックスは変更できませんが、様々な方法で変形マトリックスを操作して、既存の変
形マトリックスに基づいて新規の変換マトリックスを作成できます。次のスクリプトに、変形マトリックス
に複数の変形を適用し、元のマトリックスを置き換える方法の例を示します (完全なスクリプトについて
は、TransformMatrix を参照してください)。
Rem Scale a transformation matrix by 50% in
Rem both horizontal and vertical dimensions.
var myTransformationMatrix = myTransformationMatrix.scaleMatrix(.5, .5);
var myTransformationMatrix = myTransformationMatrix.scaleMatrix(.5, .5);
//Rotate a transformation matrix by 45 degrees.
myTransformationMatrix = myTransformationMatrix.rotateMatrix(45);
//Shear a transformation matrix by 15 degrees.
myTransformationMatrix = myTransformationMatrix.shearMatrix(15);
RotateMatrix メソッドを使用する場合は、次の RotateMatrix スクリプトのように、角度ではなくサイン値ま
たはコサイン値を使用してマトリックスを変形できます。
Rem
Rem
Set
Set
Set
The following statements
(0.25881904510252 is the
myTransformationMatrix =
myTransformationMatrix =
myTransformationMatrix =
are equivalent
sine of 15 degrees; 0.96592582628907, the cosine).
myTransformationMatrix.RotateMatrix(15)
myTransformationMatrix.RotateMatrix(, 0.96592582628907);
myTransformationMatrix.RotateMatrix(, , 0.25881904510252);
shearMatrix メソッドを使用する場合は、次の ShearMatrix スクリプトのように、角度ではなく傾斜を使用で
きます。
Set myRectangle = myInDesign.Documents.Item(1).Pages.Item(1).Rectangles.Item(1)
Set myTransformationMatrix = myInDesign.TransformationMatrices.Add(, , 0)
Rem ShearMatrix can take the following parameters: byAngle, bySlope
Rem Replace the current matrix with the sheared matrix.
Set myTransformationMatrix = myTransformationMatrix.ShearMatrix(45)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
Rem The following statements are equivalent.
Rem slope = rise/run--so a 45 degree slope is 1.
Set myTransformationMatrix = myTransformationMatrix.shearMatrix(45)
Set myTransformationMatrix = myTransformationMatrix.shearMatrix(, 1)
InvertMatrix メソッドを使用すると、変形マトリックスの逆マトリックスを取得できます。次のスクリプト
にその例を示します (完全なスクリプトについては、InvertMatrix を参照してください)。マトリックスの効
果は、反転させた変形マトリックスを使用して元に戻すことができます。
Set myRectangle = myInDesign.Documents.Item(1).Pages.Item(1).Rectangles.Item(1)
Set myTransformationMatrix = myInDesign.TransformationMatrices.Add(, , , 30, 12, 12)
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
Set myNewRectangle = myRectangle.Duplicate
Rem Move the duplicated rectangle to the location of the original
Rem rectangle by inverting, then applying the transformation matrix.
Set myTransformationMatrix = myTransformationMatrix.InvertMatrix
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
CatenateMatrix メソッドを使用すると、変形マトリックスを追加できます。次のスクリプトにその例を示し
ます (完全なスクリプトについては、CatenateMatrix を参照してください)。
第 5 章 ページアイテムの操作
ページアイテムの変形
76
Rem Transformation matrix with counterclockwise rotation angle = 30.
Set myTransformationMatrixA = myInDesign.TransformationMatrices.Add(, , , 30)
Rem Transformation matrix with horizontal translation = 12,
Rem vertical translation = 12.
Set myTransformationMatrixB = myInDesign.TransformationMatrices.Add(, , , , 12, 12)
Set myRectangle = myInDesign.Documents.Item(1).Pages.Item(1).Rectangles.Item(1)
Set myNewRectangle = myRectangle.Duplicate
Rem Rotate the duplicated rectangle.
myNewRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates,
idAnchorPoint.idCenterAnchor, myTransformationMatrixA
Set myNewRectangle = myRectangle.Duplicate
Rem Move the duplicate (unrotated) rectangle.
myNewRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates,
idAnchorPoint.idCenterAnchor, myTransformationMatrixB)
Rem Merge the two transformation matrices.
Set myTransformationMatrix = myTransformationMatrixA.CatenateMatrix(myTransformationMatrixB)
Set myNewRectangle = myRectangle.Duplicate
Rem The duplicated rectangle will be both moved and rotated.
myNewRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates,
idAnchorPoint.idCenterAnchor, myTransformationMatrix
オブジェクトが変形されている場合は、TransformValuesOf メソッドを使用して、そのオブジェクトに適用
された変形マトリックスを取得できます。次のスクリプトにその例を示します (完全なスクリプトについて
は、TransformValuesOf を参照してください)。
Set myRectangle = myInDesign.Documents.Item(1).Pages.Item(1).Rectangles.Item(1)
Rem Note that transformValuesOf() always returns an array containing a single
transformationMatrix.
Set myTransformArray = myRectangle.TransformValuesOf(idCoordinateSpaces.idPasteboardCoordinates)
Set myTransformationMatrix = myTransformArray.Item(1)
myRotationAngle = myTransformationMatrix.CounterclockwiseRotationAngle
myShearAngle = myTransformationMatrix.ClockwiseShearAngle
myXScale = myTransformationMatrix.HorizontalScaleFactor
myYScale = myTransformationMatrix.VerticalScaleFactor
myXTranslate = myTransformationMatrix.HorizontalTranslation
myYTranslate = myTransformationMatrix.VerticalTranslation
myString = "Rotation Angle: " & myRotationAngle & vbCr
myString = myString & "Shear Angle: " & myShearAngle & vbCr
myString = myString & "Horizontal Scale Factor: " & myXScale & vbCr
myString = myString & "Vertical Scale Factor: " & myYScale & vbCr
myString = myString & "Horizontal Translation: " & myXTranslate & vbCr
myString = myString & "Vertical Translation: " & myYTranslate & vbCr & vbCr
myString = myString & "Note that the Horizontal Translation and" & vbCr
myString = myString & "Vertical Translation values are the location" & vbCr
myString = myString & "of the center anchor in pasteboard coordinates."
MsgBox myString
注意 : このメソッドで返された変形マトリックスの水平変形フィールド値と垂直変形フィールド値は、ペー
ストボードの座標におけるオブジェクトの左上アンカーの位置です。
第 5 章 ページアイテムの操作
ページアイテムの変形
77
座標スペース
前述の変形スクリプトでは、transform メソッドのパラメーターに
CoordinateSpaces.pasteboardCoordinates 列挙法が指定されています。このパラメーターによって、変形操
作が発生する座標系、つまり座標スペースが決まります。座標スペースの値は、次のいずれかです。

idCoordinateSpaces.idPasteboardCoordinates は、InDesign ドキュメント全体の座標スペースです。こ
の座標スペースは、ドキュメント内のすべてのスプレッドにわたって適用されます。InDesign の定規また
は原点には対応しておらず、InDesign のユーザーインターフェイスでページの周囲に表示されるペース
トボードの領域とも関係ありません。オブジェクトに適用した変形による、この座標スペースへの影響
はありません(例えば、水平軸と垂直軸の角度は変化しません)。

idCoordinateSpaces.idParentCoordinates は、オブジェクトの親の座標スペースです。親に適用した変
形は、親座標に影響を与えます。例えば、親オブジェクトを回転させると、この座標スペースの水平軸
と垂直軸の角度が変化します。この場合、親オブジェクトとはオブジェクトを格納しているグループま
たはページアイテムを指します。オブジェクトの親がページまたはスプレッドの場合、親座標はスプ
レッドの座標と同じです。

idCoordinateSpaces.idInnerCoordinates は、オブジェクト自体が作成された座標スペースです。

idCoordinateSpaces.idSpreadCoordinates は、スプレッドの座標スペースです。この座標スペースの基
点は、スプレッドの中心にあり、ユーザーインターフェイスに表示される定規には対応していません。
次のスクリプトは、座標スペース間の相違を示します (完全なスクリプトについては、CoordinateSpaces を
参照してください)。
Set myRectangle = myInDesign.Documents.Item(1).Pages.Item(1).Groups.Item(1).Rectangles.Item(1)'
myString = "The page contains a group which has been" & vbCr
myString = myString & "rotated 45 degrees (counterclockwise)." & vbCr
myString = myString & "The rectangle inside the group was" & vbCr
myString = myString & "rotated 45 degrees counterclockwise" & vbCr
myString = myString & "before it was added to the group." & vbCr & vbcr
myString = myString & "Watch as we apply a series of scaling" & vbCr
myString = myString & "operations in different coordinate spaces." & vbCr & vbCr
myString = myString & "(You might need to move the alert aside" & vbCr
myString = myString & "to see the effect of the transformations.)" & vbCr
MsgBox myString
Rem Create a transformation matrix with horizontal scale factor = 2.
Set myTransformationMatrix = myInDesign.TransformationMatrices.Add(2)
Rem Transform the rectangle using inner coordinates.
myRectangle.Transform idCoordinateSpaces.idInnerCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
Rem Select the rectangle and display an alert.
myInDesign.Select myRectangle
MsgBox "Transformed by inner coordinates."
Rem Undo the transformation.
myInDesign.Documents.Item(1).Undo
Rem Transform using parent coordinates.
myRectangle.Transform idCoordinateSpaces.idParentCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
myInDesign.Select myRectangle
MsgBox "Transformed by parent coordinates."
myInDesign.Documents.Item(1).Undo
Rem Transform using pasteboard coordinates.
myRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
myInDesign.Select myRectangle
MsgBox "Transformed by pasteboard coordinates."
myInDesign.Documents.Item(1).Undo
第 5 章 ページアイテムの操作
ページアイテムの変形
78
変形の基点
変形の基点は、変形の中心点です。変形の基点は様々な方法で指定できます。

境界線スペース:

アンカー - オブジェクト自体のアンカーポイント。
AnchorPoint.CenterAnchor

アンカー、境界線の種類 - オブジェクトの境界線(BoundingBoxLimits.GeometricPathBounds)また
はオブジェクトの表示可能な境界線(BoundingBoxLimits.OuterStrokeBounds)との相対位置で指定
されたアンカーポイント。
Array(idAnchorPoint.idBottomLeftAnchor,
idBoundingBoxLimits.idOuterStrokeBounds)

アンカー、境界線の種類、座標系 - 特定の座標スペースにおいて、オブジェクトの境界線
(BoundingBoxLimits.GeometricPathBounds)またはオブジェクトの表示可能な境界線
(BoundingBoxLimits.OuterStrokeBounds)として指定されたアンカーポイント。
Array(idAnchorPoint.idBottomLeftAnchor,
idBoundingBoxLimits.idOuterStrokeBounds,
idCoordinateSpaces.idPasteboardCoordinates)
 (x,y)
、境界線の種類 - オブジェクトの境界線(BoundingBoxLimits.GeometricPathBounds)またはオ
ブジェクトの表示可能な境界線(BoundingBoxLimits.OuterStrokeBounds)との相対位置で指定され
たポイント。この場合、バウンディングボックスの左上角は(0, 0)
、右下角は(1, 1)です。中心の
アンカーは(.5, .5)に配置されます。
Array(Array(.5, .5), idBoundingBoxLimits.idOuterStrokeBounds)
、境界線の種類、座標スペース - 特定の座標スペースにおける、オブジェクトの境界線
 (x, y)
(BoundingBoxLimits.GeometricPathBounds)またはオブジェクトの表示可能な境界線
(BoundingBoxLimits.OuterStrokeBounds)との相対位置で指定されたポイント。この場合、バウン
ディングボックスの左上角は(0, 0)
、右下角は(1, 1)です。中心のアンカーは(.5, .5)に配置され
ます。
Array(Array(.5, .5), idBoundingBoxLimits.idOuterStrokeBounds,
idCoordinateSpaces.idPasteboardCoordinates)

定規スペース:
 (x, y)
、ページインデックス - スプレッドの指定ページ上にある定規基点との相対位置で指定された
ポイント。
Array(Array(72, 144), 1)
、位置 - オブジェクトの指定された位置の親ページとの相対位置で指定されたポイント。位置
 (x, y)
は、アンカーポイントまたは 1 組の座標として指定できます。位置は、オブジェクトの境界線または
表示可能な境界線との相対位置で指定でき、特定の座標スペースに指定できます。
Array(Array(72, 144), idAnchorPoint.idCenterAnchor)

変形スペース:
 (x, y)- ペーストボードの座標スペース内のポイント。
Array(72, 72)
、座標系 - 指定した座標スペース内のポイント。
 (x, y)
Array(Array(72, 72), idCoordinateSpaces.idParentCoordinates
第 5 章 ページアイテムの操作
ページアイテムの変形
79
(x, y))- transform メソッドの in パラメーターとして指定された座標スペース内のポイント。
 (
Array(Array(72, 72))
変形の基点オプションを使用する方法について、次のスクリプトにいくつかの例を示します (完全なスクリ
プトについては、TransformationOrigin を参照してください)。
Set myPage = myInDesign.Documents.Item(1).Pages.Item(1)
Set myRectangle = myPage.Rectangles.Item(1)
myString = "Watch as we rotate the rectangle using different anchor points," & vbCr
myString = myString & "bounds types, and coordinate spaces." & vbCr & vbCr
myString = myString & "(You might need to move the alert aside" & vbCr
myString = myString & "to see the effect of the transformations.)"
MsgBox myString
Set myNewRectangle = myRectangle.Duplicate
Rem Create a transformation matrix with counterclockwise rotation angle = 30.
Set myTransformationMatrix = myInDesign.TransformationMatrices.Add(, , , 30)
Rem Rotate around the duplicated rectangle's center point.
myNewRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates,
idAnchorPoint.idCenterAnchor, myTransformationMatrix
Rem Select the rectangle and display an alert.
myInDesign.Select myNewRectangle
MsgBox "Transformed around center anchor."
Rem Undo the transformation.
myInDesign.Documents.Item(1).Undo
Rem Rotate the rectangle around the ruler location [-100, -100].
Rem Note that the anchor point specified here specifes the page
Rem containing the point--*not* that transformation point itself.
Rem The transformation gets the ruler coordinate [-100, -100] based
Rem on that page. Setting the considerRulerUnits parameter to true
Rem makes certain that the transformation uses the current
Rem ruler units.
myNewRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates, Array(Array(-100, -100),
idAnchorPoint.idTopLeftAnchor), myTransformationMatrix, , True
Rem Move the page guides to reflect the transformation point.
myPage.Guides.Item(1).Location = -100
myPage.Guides.Item(2).Location = -100
Rem Select the rectangle and display an alert.
myInDesign.Select myNewRectangle
MsgBox "Rotated around -100x, -100y."
Rem Undo the transformation and the guide moves.
myInDesign. Documents.Item(1).Undo
myInDesign. Documents.Item(1).Undo
myInDesign. Documents.Item(1).Undo
myNewRectangle.StrokeWeight = 12
myBounds = myNewRectangle.visibleBounds
Rem Move the page guides to reflect the transformation point.
myPage.Guides.Item(1).Location = myBounds(1)
myPage.Guides.Item(2).Location = myBounds(2)
Rem Rotate the rectangle around the outer edge of the lower left corner.
myNewRectangle.Transform idCoordinateSpaces.idPasteboardCoordinates,
Array(idAnchorPoint.idBottomLeftAnchor, idBoundingBoxLimits.idOuterStrokeBounds),
myTransformationMatrix, idMatrixContent.idRotationValue, True
Rem Select the rectangle and display an alert.
myInDesign.Select myNewRectangle
MsgBox "Rotated around the outside edge of the bottom left corner."
Rem Undo the transformation and the guide moves.
myInDesign. Documents.Item(1).Undo
myInDesign. Documents.Item(1).Undo
myInDesign. Documents.Item(1).Undo
myInDesign. Documents.Item(1).Undo
第 5 章 ページアイテムの操作
ページアイテムの変形
80
位置の解決
ある座標スペースに指定したポイントの位置を、別の座標スペースのコンテキストで取得することが必要に
なる場合があります。取得するには、resolve メソッドを使用します。次のスクリプトにその例を示します
(完全なスクリプトについては、ResolveLocation を参照してください)。
Set myPage = myInDesign.Documents.Item(1).Pages.Item(1)
Set myRectangle = myPage.Groups.Item(1).Rectangles.Item(1)
Rem Template for resolve():
Rem PageItem.resolve (Location:any, in: CoordinateSpaces,
Rem ConsideringRulerUnits:boolean)
Rem Get a ruler coordinate in pasteboard coordinates.
Rem The following should work, but, due to a bug in InDesign CS6,
Rem it does not work in VBScript. It does work in VB6.
'myPageLocation = myRectangle.Resolve(Array(Array(72, 72),
idAnchorPoint.idTopRightAnchor),idCoordinateSpaces.idPasteboardCoordinates, True)
Rem resolve() returns an array (in this case, the array containins a single item).
'myPageLocation = myPageLocation(0)
'myPageLocationX = myPageLocation(0)
'myPageLocationY = myPageLocation(1)
'MsgBox "X: " & CStr(myPageLocation(0)) & vbCr & "Y: " & CStr(myPageLocation(1))
Rem Because of the above bug, here's a workaround using JavaScript.
myString = "var myRectangle =
app.documents.item(0).pages.item(0).groups.item(0).rectangles.item(0);" & vbCr
myString = myString & "var myPageLocation = myRectangle.resolve([[72, 72],
AnchorPoint.topRightAnchor], CoordinateSpaces.pasteboardCoordinates, true);" & vbCr
myString = myString & "alert(""X: "" + myPageLocation[0][0] + ""¥rY: "" + myPageLocation[0][1])"
myInDesign.DoScript myString, idScriptLanguage.idJavaScript
ポイントの変形
ポイントもオブジェクトと同様に変形することができます。つまり、スクリプト自体に計算を組み込まなく
てもスクリプトで様々な算術演算を処理できます。次の ChangeCoordinates サンプルスクリプトは、このアプ
ローチを使用して一連の正多角形を描画する方法を示しています。
Rem General purpose routine for drawing regular polygons from their center point.
Function myDrawPolygon(myInDesign, myParent, myCenterPoint, myNumberOfPoints, myRadius,
myStarPolygon, myStarInset)
ReDim myPathPoints(0)
myPoint = Array(0, 0)
If myStarPolygon = True Then
myNumberOfPoints = myNumberOfPoints * 2
End If
myInnerRadius = myRadius * myStarInset
myAngle = 360 / myNumberOfPoints
Set myRotateMatrix = myInDesign.TransformationMatrices.Add(, , , myAngle)
Set myOuterTranslateMatrix = myInDesign.TransformationMatrices.Add
(, , , , myRadius)
Set myInnerTranslateMatrix = myInDesign.TransformationMatrices.Add
(, , , , myInnerRadius)
For myPointCounter = 0 To myNumberOfPoints
Rem Translate the point to the inner/outer radius.
If ((myStarInset = 1) Or (myIsEven(myPointCounter) = True)) Then
myTransformedPoint = myOuterTranslateMatrix.ChangeCoordinates(myPoint)
Else
myTransformedPoint = myInnerTranslateMatrix.ChangeCoordinates(myPoint)
End If
myTransformedPoint = myRotateMatrix.ChangeCoordinates(myTransformedPoint)
myPathPoints = myPush(myPathPoints, myTransformedPoint)
Set myRotateMatrix = myRotateMatrix.RotateMatrix(myAngle)
Next
Rem Create a new polygon.
Set myPolygon = myParent.Polygons.Add
第 5 章 ページアイテムの操作
ページアイテムの変形
81
Rem Set the entire path of the polygon to the array we've created.
myPolygon.Paths.Item(1).EntirePath = myPathPoints
Rem If the center point is somewhere other than [0,0],
Rem translate the polygon to the center point.
If (myCenterPoint(0) <> 0) Or (myCenterPoint(1) <> 0) Then
Set myTranslateMatrix = myInDesign.TransformationMatrices.Add
(, , , , myCenterPoint(0), myCenterPoint(1))
myPolygon.Transform idCoordinateSpaces.idPasteboardCoordinates,
idAnchorPoint.idCenterAnchor, myTranslateMatrix
End If
Set myDrawPolygon = myPolygon
End Function
Rem Generic function for adding a value to an array.
Function myPush(myArray, myValue)
If Not (IsEmpty(myArray(0))) Then
ReDim Preserve myArray(UBound(myArray) + 1)
End If
Set myArray(UBound(myArray)) = myValue
myPush = myArray
End Function
Rem This function returns true if myNumber is even, false if it is not.
Function myIsEven(myNumber)
myResult = myNumber Mod 2
If myResult = 0 Then
myResult = True
Else
myResult = False
End If
myIsEven = myResult
End Function
FunWithTransformations サンプルスクリプトに示すように、ChangeCoordinate メソッドを使用して、カーブ
を制御するポイントの位置を変更することもできます。
変形の繰り返し
ユーザーインターフェイスでは変形または一連の変形を繰り返し適用できますが、同じことがスクリプティ
ングでも可能です。変形を繰り返し適用するメソッドは、4 種類あります。

TransformAgain

TransformAgainIndividually

TransformSequenceAgain

TransformSequenceAgainIndividually
TransformAgain の使用方法を、次のスクリプトに示します (完全なスクリプトについては、TransformAgain
を参照してください)。
第 5 章 ページアイテムの操作
サイズ変更とフレーム調整
82
set myRectangle = myPage.Rectangles.Item(1)
myBounds = myRectangle.GeometricBounds
myX1 = myBounds(1)
myY1 = myBounds(0)
Set myRectangleA = myPage.Rectangles.Add
myRectangleA.GeometricBounds = Array(myY1-12, myX1-12, myY1+12, myX1+12)
Set myTransformationMatrix = myInDesign.TransformationMatrices.add(, , , 45)
myRectangleA.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
Set myRectangleB = myRectangleA.Duplicate
myRectangleB.Transform idCoordinateSpaces.idPasteboardCoordinates, Array(Array(0,0),
idAnchorPoint.idTopLeftAnchor), myTransformationMatrix, , True
Set myRectangleC = myRectangleB.Duplicate
myRectangleC.TransformAgain
Set myRectangleD = myRectangleC.Duplicate
myRectangleD.transformAgain
Set myRectangleE = myRectangleD.Duplicate
myRectangleE.TransformAgain
set myRectangleF = myRectangleE.Duplicate
myRectangleF.TransformAgain
set myRectangleG = myRectangleF.Duplicate
myRectangleG.TransformAgain
set myRectangleH = myRectangleG.Duplicate
myRectangleH.TransformAgain
myRectangleA.Transform idCoordinateSpaces.idPasteboardCoordinates, idAnchorPoint.idCenterAnchor,
myTransformationMatrix
myRectangleD.TransformAgain
myRectangleF.TransformAgain
myRectangleH.TransformAgain
サイズ変更とフレーム調整
Transform メソッドを使用したページアイテムの拡大・縮小に加え、他の 2 つのメソッド Resize と Reframe を
使用してシェイプのサイズを変更することもできます。これらのメソッドでは、ページアイテムのコンテン
ツや線幅を拡大・縮小せずに、ページアイテムのパスポイントの位置が変更されます。Resize メソッドの使用
方法を、次のスクリプトに示します。完全なスクリプトについては、Resize を参照してください。
Rem Given a reference to a rectangle "myRectangle"...
Set myDuplicate = myRectangle.Duplicate
myDuplicate.Resize idCoordinateSpaces.idInnerCoordinates, idAnchorPoint.idCenterAnchor,
idResizeMethods.idMultiplyingCurrentDimensionsBy, Array(2, 2)
Reframe メソッドの使用方法を、次のスクリプトに示します。完全なスクリプトについては、Reframe を参照
してください。
Rem Given a reference to a rectangle "myRectangle"...
myBounds = myRectangle.GeometricBounds
myX1 = myBounds(1)-72
myY1 = myBounds(0)-72
myX2 = myBounds(3)+72
myY2 = myBounds(2)+72
Set myDuplicate = myRectangle.Duplicate
myDuplicate.Reframe idCoordinateSpaces.idInnerCoordinates, Array(Array(myY1, myX1), Array(myY2,
myX2))
第 5 章 ページアイテムの操作
アーティクルの使用
83
アーティクルの使用
アーティクルを使用することで、デザイナーや制作アーティストはページアイテム間の関係を簡単に作成す
ることができます。関係を使用することで、ePub、HTML またはアクセシブル PDF への書き出しに使用するコ
ンテンツや、コンテンツの順序を定義できます。画像、グラフィック、テキストなど、レイアウトに含まれ
ている既存のページアイテムを組み合わせてアーティクルを作成することができます。アーティクルを作成
した後は、ページアイテムを追加または削除したり、ページアイテムの順序を変更したりできます。
アーティクルリストの取得
ドキュメント内のアーティクルを取得するには、次のスクリプトを使用します(完全なスクリプトについて
は、CreateArticle を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set articles = myDocument.Articles
新しいアーティクルの追加
ドキュメントに新しいアーティクルを追加するには、次のスクリプトを使用します(完全なスクリプトにつ
いては、CreateArticle を参照してください)。
Set article1 = myDocument.Articles.Add("Article1", True)
アーティクルの削除
アーティクルを削除するには、次のスクリプトに示すように、削除対象のアーティクル自体に対して削除を
指示します(完全なスクリプトについては、RemoveArticle を参照してください)。
article.Delete
アーティクルの順序変更
アーティクルの順序を変更するには、次のスクリプトに示すように、移動対象のアーティクルに対して参照
アーティクルと参照アーティクルを基準にした相対位置を指示します(完全なスクリプトについては、
ReorderArticles を参照してください)。
Set
Set
Set
Set
article1
article2
article3
article4
=
=
=
=
myDocument.Articles.Add("Article1",
myDocument.Articles.Add("Article2",
myDocument.Articles.Add("Article3",
myDocument.Articles.Add("Article4",
Rem Reverse the order of articles.
Rem Move article4 to the first.
article4.Move idLocationOptions.idAtBeginning
Rem Move article1 to the end.
article1.Move idLocationOptions.idAtEnd
Rem Move article3 to the second place.
article3.Move idLocationOptions.idAfter, article4
Rem Move article2 to the third place.
article2.Move idLocationOptions.idBefore, article1
True)
True)
True)
True)
第 5 章 ページアイテムの操作
アーティクルの使用
84
アーティクルへの新規メンバーの追加
アーティクルに新規メンバーを追加するには、次のスクリプトを使用します(完全なスクリプトについては、
AddRemoveArticleMember を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set articles = myDocument.Articles
Rem
Set
Set
Set
Create new
article1 =
article2 =
article3 =
articles.
articles.Add("Article1", True)
articles.Add("Article2", True)
articles.Add("Article3", True)
Set myPage = myDocument.pages.item(1)
Set article1Members = article1.ArticleMembers
article1Members.Add myPage.Rectangles.item(1)
article1Members.Add myPage.Ovals.item(1)
Set article2Members = article2.ArticleMembers
article2Members.Add myPage.Rectangles.item(2)
article2Members.Add myPage.Ovals.item(2)
Set article3Members = article3.ArticleMembers
Rem Add group as article member.
article3Members.Add myPage.Groups.item(1)
アーティクルのメンバーの順序変更
アーティクルのメンバーの順序を変更するには、次のスクリプトに示すように、移動対象のメンバーに対し
て参照オブジェクトと参照オブジェクトを基準にした相対位置を指示します(完全なスクリプトについては、
ReorderArticleMembers を参照してください)。
Rem Assume there are four members in the article in the following order:
Rem rectangle, oval, text frame, group
Set articleMembers = article.ArticleMembers
articleMembers.Add myPage.Rectangles.item(1)
articleMembers.Add myPage.Ovals.item(1)
articleMembers.Add myPage.TextFrames.item(1)
articleMembers.Add myPage.Groups.item(1)
articleMembers.item(1).Move idLocationOptions.idAtEnd
articleMembers.item(3).Move idLocationOptions.idAtBeginning
articleMembers.item(2).Move idLocationOptions.idAfter, articleMembers.item(3)
アーティクルからのメンバーの削除
アーティクルからメンバーを削除するには、次のスクリプトに示すように、削除対象のアーティクルメン
バー自体に対して削除を指示します(完全なスクリプトについては、AddRemoveArticleMember を参照して
ください)。
Set articleMember = article1Members.item(1)
articleMember.Delete
テキストと組版
6
章の更新ステータス
CS6
更新
103 ページの「テキストフレームをコンテンツに合わせる」という節の追加。
テキストの入力、編集、フォーマットといった作業は、InDesign ドキュメントの製作工程の中でも、最も時
間のかかる作業の 1 つです。したがって、テキストや書式に関する作業を自動化できれば、生産性の大幅な
向上が期待できます。
この章では、テキストや書式に関する一般的な操作をスクリプトで実行する方法について説明します。最初
は簡単なサンプルスクリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。また、InDesign でテキストを
操作する方法や、組版に関する基本的な用語を理解しているものとしています。
テキストの入力と読み込み
ここでは、InDesign ドキュメントにテキストを配置する方法について説明します。InDesign のユーザーイン
ターフェイスを使用してテキストフレームにテキストを入力したり、テキストファイルを配置したりするの
と同じように、スクリプトを使用してテキストフレームを作成し、ストーリーにテキストを挿入し、ページ
上にテキストファイルを配置することができます。
テキストフレームの作成
次のスクリプトでは、テキストフレームを作成し、フレームの境界(サイズ)を設定し、フレームにテキス
トを入力しています(完全なスクリプトについては、MakeTextFrame というチュートリアルスクリプトを参
照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Add
Rem Set the bounds of the text frame.
myTextFrame.GeometricBounds = Array(72, 72, 288, 288)
Rem Enter text in the text frame.
myTextFrame.Contents = "This is some example text."
次のスクリプトでは、ページマージンによって定義される領域と同じサイズのテキストフレームを作成して
います。ここで使用している myGetBounds は、様々なスクリプトで活用できる便利な関数であり、この章の
多くの例でも使用されています (完全なスクリプトについては、MakeTextFrameWithinMargins を参照してく
ださい)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Rem Create a text frame on the current page.
Set myTextFrame = myPage.TextFrames.Add
Rem Set the bounds of the text frame.
myTextFrame.GeometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
Rem Enter text in the text frame.
myTextFrame.Contents = "This is some example text."
次のスクリプトに myGetBounds 関数を示します。
85
第 6 章 テキストと組版
テキストの入力と読み込み
86
Function myGetBounds(myDocument, myPage)
myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
If myPage.Side = idPageSideOptions.idLeftHand Then
myX2 = myPage.MarginPreferences.Left
myX1 = myPage.MarginPreferences.Right
Else
myX1 = myPage.MarginPreferences.Left
myX2 = myPage.MarginPreferences.Right
End If
myY1 = myPage.marginPreferences.Top
myX2 = myPageWidth - myX2
myY2 = myPageHeight - myPage.MarginPreferences.Bottom
myGetBounds = Array(myY1, myX1, myY2, myX2)
End Function
テキストの追加
ストーリーにテキストを追加するには、テキストを挿入する箇所で挿入点の contents プロパティを使用しま
す。次のサンプルスクリプトでは、この方法を使用して、ストーリーの末尾にテキストを追加しています
(完全なスクリプトについては、AddText を参照してください)。
set myDocument = myInDesign.Documents.Item(1)
Set myTextFrame = myDocument.TextFrames.Item(1)
Rem Add text at the end of the text in the text frame.
Rem To do this, we'll use the last insertion point in the story.
Rem (vbCr is a return character, "&" concatenates two strings.)
myNewText = "This is a new paragraph of example text."
myTextFrame.ParentStory.InsertionPoints.Item(-1).Contents = vbCr & myNewText
ストーリーとテキストフレーム
InDesign レイアウトの中にあるテキストは、すべてストーリーの中に含まれています。どのストーリーにも
1 つ以上のテキストフレームを含めることができます。テキストフレームを 1 つ作成するとストーリーが 1 つ
作成されます。ストーリーには複数のテキストフレームを含めることができます。
前述のスクリプトでは、テキストフレームの末尾ではなく、親ストーリーの末尾にテキストを追加しました。
これは、テキストの長さやフォーマットによっては、テキストフレームの末尾がストーリーの末尾ではない
ことがあるからです。親ストーリーの末尾にテキストを追加することによって、テキストフレームの状態に
関係なく、確実にテキストが追加されるようにしています。
テキストフレームの親ストーリーを取得するには、テキストフレームの ParentTextFrame プロパティを使用
します。多くの場合、テキストフレームのテキストを操作するよりも、ストーリーのテキストを操作するほ
うが便利です。この違いを次のスクリプトに示します。表示される警告を見ると、テキストフレームには
オーバーセットテキストが含まれておらず、ストーリーには含まれていることがわかります(完全なスクリ
プトについては、StoryAndTextFrame を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Now add text beyond the end of the text frame.
myTextFrame.InsertionPoints.Item(-1).Contents = vbCr & "This is some overset text"
myString = myTextFrame.Contents
MsgBox ("The last paragraph in this alert should be ""This is some overset text"". Is it?" & vbCr &
myString)
myString = myTextFrame.ParentStory.Contents
MsgBox ("The last paragraph in this alert should be ""This is some overset text"". Is it?" & vbCr &
myString)
InDesign ドキュメントの中にあるテキストオブジェクトの関係について詳しくは、95 ページの「テキストオ
ブジェクト」を参照してください。
第 6 章 テキストと組版
テキストの入力と読み込み
87
テキストの置換
次のスクリプトでは、適当なオブジェクトの内容を変更することで、1 つの単語をある語句に置換していま
す(完全なスクリプトについては、ReplaceWord を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Replace the third word with the phrase
Rem "a little bit of".
myTextFrame.ParentStory.Words.Item(3).contents = "a little bit of"
次のスクリプトでは、段落内のテキストを置換しています(完全なスクリプトについては、ReplaceText を参
照してください)。
Rem Replace the text in the second paragraph without replacing
Rem the return character at the end of the paragraph. To do this,
Rem we'll use the ItemByRange method.
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Set myStartCharacter = myTextFrame.ParentStory.Paragraphs.Item(2).Characters.Item(1)
Set myEndCharacter = myTextFrame.ParentStory.Paragraphs.Item(2).Characters.Item(-2)
myTextFrame.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1).Contents = "This text
replaces the text in paragraph 2."
このスクリプトでは、ItemByRange メソッドを使用して、段落内のテキストへの参照(単一のテキストオブ
ジェクト)を取得しています(段落末尾の改行文字は除外しています)。改行文字を除外しているのは、改行
を削除してしまうと、段落に適用されている段落スタイルが変更される可能性があるからです。ここでは、
ストーリーのテキストコレクションの ItemByRange メソッドを使用しています。パラメーターには 2 つの文
字(段落の先頭の文字と、末尾の文字(改行文字)の直前にある文字)を指定しています。
myTextFrame.ParentStory.Characters.ItemByRange を使用する方法も考えられますが、その場合は
Character オブジェクトのコレクションが返されます。ここでは、単一の Text オブジェクトを使用すること
で、1 つのアクションで置換を行っています。
特殊文字の挿入
多くの VBScript エディターでは Unicode がサポートされているので、InDesign に渡すテキスト文字列に
Unicode 文字を簡単に入力できます。また、Unicode 文字の字形の識別番号を指定する <nnnn> という
InDesign ショートカット(nnnn は、目的の文字の Unicode コード)を使用することもできます。次のスクリ
プトでは、特殊文字をいくつかの方法で入力しています (ここでは、myGetBounds 関数は省略しています。
この関数については、85 ページの「テキストフレームの作成」または SpecialCharacters というチュートリア
ルスクリプトを参照してください)。
第 6 章 テキストと組版
テキストの配置とテキスト読み込み環境設定の指定
88
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Entering special characters directly.
myTextFrame.contents = "Registered trademark: ®" & vbCr & "Copyright: ©" & vbCr & "Trademark: ™" &
vbCr & ""
Rem Entering special characters by their Unicode glyph ID
Rem value ("&H" indicates a hexadecimal number):
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = "Not equal to: " & ChrW(&H2260) &
vbCr & "Square root: " & ChrW(&H221A) & vbCr & "Paragraph: " & ChrW(&HB6) & vbCr
Rem Entering InDesign special characters by their enumerations:
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = "Page number marker:"
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = idSpecialCharacters.idAutoPageNumber
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = vbCr
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = "Section symbol:"
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = idSpecialCharacters.idSectionSymbol
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = vbCr
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = "En dash:"
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = idSpecialCharacters.idEnDash
myTextFrame.ParentStory.InsertionPoints.Item(-1).contents = vbCr
特定の文字の Unicode ID を調べたい場合は、InDesign の字形パレットを使用するのが最も簡単です。パレッ
ト内で文字の上にカーソルを移動すると、その文字の Unicode 値が表示されます。Unicode について詳しく
は、http://www.unicode.org を参照してください。
テキストの配置とテキスト読み込み環境設定の指定
テキスト文字列の入力だけでなく、ワードプロセッサーやテキストエディターで作成したテキストファイル
を配置することもできます。ドキュメントページにテキストファイルを配置する方法を、次のスクリプトに
示します(完全なスクリプトについては、PlaceTextFile を参照してください)。
Set
Set
myX
myY
Rem
Rem
Rem
Rem
Rem
Rem
Rem
Rem
Set
Rem
Rem
Rem
myDocument = myInDesign.Documents.Item(1)
myPage = myDocument.Pages.Item(1)
= myPage.MarginPreferences.Left
= myPage.MarginPreferences.Top
Autoflow a text file on the current page.
Parameters for Page.place():
File as File object,
[PlacePoint as Array [x, y]]
[DestinationLayer as Layer object]
[ShowingOptions as Boolean = False]
[Autoflowing as Boolean = False]
You'll have to fill in your own file path.
myTextFrame = myPage.Place("c:¥test.txt", Array(myX, myY), , False, True)
Note that if the PlacePoint parameter is inside a file, only the vertical (y)
coordinate will be honored--the text frame will expand horizontally
to fit the column.
既存のテキストフレームにテキストファイルを配置する方法を、次のスクリプトに示します (ここでは、
myGetBounds 関数は省略しています。この関数については、85 ページの「テキストフレームの作成」または
PlaceTextFileInFrame というチュートリアルスクリプトを参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Place a text file in the text frame.
Rem Parameters for TextFrame.place():
Rem File as string,
Rem [ShowingOptions as Boolean = False]
Rem You'll have to fill in your own file path.
myTextFrame.Place "c:¥test.txt"
第 6 章 テキストと組版
テキストの配置とテキスト読み込み環境設定の指定
89
テキスト内の特定の場所にテキストファイルを挿入する方法を、次のスクリプトに示します (ここでは、
myGetBounds 関数は省略しています。この関数については、85 ページの「テキストフレームの作成」または
InsertTextFile というチュートリアルスクリプトを参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Rem Create a text frame.
Set myTextFrame = myPage.TextFrames.Add
myTextFrame.geometricBounds = myGetBounds(myDocument, myPage)
myTextFrame.Contents = "Inserted text file follows:" & vbCr
Rem Place a text file at the end of the text.
Rem Parameters for InsertionPoint.place():
Rem File as string (file path),
Rem [ShowingOptions as Boolean = False]
Rem You'll have to fill in your own file path.
myTextFrame.ParentStory.InsertionPoints.Item(-1).Place "c:¥test.txt"
配置するテキストファイルの種類に応じた読み込みオプションを指定するには、対応する読み込み環境設定
オブジェクトを使用します。テキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全な
スクリプトについては、TextImportPreferences を参照してください)。スクリプトのコメントに、各プロパ
ティに指定可能な値を示します。
With myInDesign.TextImportPreferences
Rem Options for characterSet: idTextImportCharacterSet
.CharacterSet = idTextImportCharacterSet.idUTF8
.ConvertSpacesIntoTabs = True
.SpacesIntoTabsCount = 3
Rem Dictionary can take many values, such as French, Italian.
.Dictionary = "English: USA"
Rem platform options: idImportPlatform
.Platform = idImportPlatform.idPC
.StripReturnsBetweenLines = True
.StripReturnsBetweenParagraphs = True
.UseTypographersQuotes = True
End With
タグ付きテキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、TaggedTextImportPreferences を参照してください)。
With myInDesign.TaggedTextImportPreferences
.RemoveTextFormatting = False
Rem .styleConflict property can be:
Rem idStyleConflict.idPublicationDefinition
Rem idStyleConflict.idTagFileDefinition
.StyleConflict = idStyleConflict.idPublicationDefinition
.UseTypographersQuotes = True
End With
Word および RTF 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、WordRTFImportPreferences を参照してください)。
第 6 章 テキストと組版
テキストの配置とテキスト読み込み環境設定の指定
With myInDesign.WordRTFImportPreferences
Rem convertPageBreaks property can be:
Rem idConvertPageBreaks.idColumnBreak
Rem idConvertPageBreaks.idNone
Rem idConvertPageBreaks.idPageBreak
.ConvertPageBreaks = idConvertPageBreaks.idNone
Rem convertTablesTo property can be:
Rem idConvertTablesOptions.idUnformattedTabbedText
Rem idConvertTablesOptions.idUnformattedTable
.ConvertTablesTo = idConvertTablesOptions.idUnformattedTable
.ImportEndnotes = True
.ImportFootnotes = True
.ImportIndex = True
.ImportTOC = True
.ImportUnusedStyles = False
.PreserveGraphics = False
.PreserveLocalOverrides = False
.PreserveTrackChanges = False
.RemoveFormatting = False
Rem resolveCharacterStyleClash and resolveParagraphStyleClash properties can be:
Rem idResolveStyleClash.idResolveClashAutoRename
Rem idResolveStyleClash.iduseExisting
Rem idResolveStyleClash.iduseNew
.ResolveCharacterStyleClash = idResolveStyleClash.idResolveClashUseExisting
.ResolveParagraphStyleClash = idResolveStyleClash.idResolveClashUseExisting
.UseTypographersQuotes = True
End With
Excel 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについては、
ExcelImportPreferences を参照してください)。
With myInDesign.ExcelImportPreferences
Rem alignmentStyle property can be:
Rem AlignmentStyleOptions.centerAlign
Rem AlignmentStyleOptions.leftAlign
Rem AlignmentStyleOptions.rightAlign
Rem AlignmentStyleOptions.spreadsheet
.AlignmentStyle = idAlignmentStyleOptions.idSpreadsheet
.DecimalPlaces = 4
.PreserveGraphics = False
Rem Enter the range you want to import as "start cell:end cell".
.RangeName = "A1:B16"
.SheetIndex = 1
.SheetName = "pathpoints"
.ShowHiddenCells = False
Rem tableFormatting property can be:
Rem idTableFormattingOptions.idExcelFormattedTable
Rem idTableFormattingOptions.idExcelUnformattedTabbedText
Rem idTableFormattingOptions.idExcelUnformattedTable
.TableFormatting = idTableFormattingOptions.idExcelFormattedTable
.UseTypographersQuotes = True
.ViewName = ""
End With
90
第 6 章 テキストと組版
テキストの書き出しとテキスト書き出し環境設定の指定
91
テキストの書き出しとテキスト書き出し環境設定の指定
InDesign ドキュメントからテキストを書き出す方法を、次のスクリプトに示します。テキストファイル形式
で書き出すには、テキストオブジェクトやストーリーオブジェクトを使用する必要があることに注意してく
ださい。1 つの操作でドキュメント内のすべてのテキストを書き出すことはできません (ここでは、
myGetBounds 関数は省略しています。この関数については、85 ページの「テキストフレームの作成」または
ExportTextFile というチュートリアルスクリプトを参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Text export method parameters:
Rem Format as idExportFormat
Rem To As File
Rem [ShowingOptions As Boolean = False]
Rem
Rem Format parameter can be:
Rem idExportFormat.idInCopy
Rem idExportFormat.idInCopyCS2Story
Rem idExportFormat.idRTF
Rem idExportFormat.idTaggedText
Rem idExportFormat.idTextType
Rem
Rem Export the story as text. You'll have to fill in a valid file path on your system.
myTextFrame.ParentStory.Export idExportFormat.idTextType, "C:¥test.txt"
指定したテキスト範囲を書き出す方法を、次の例に示します (ここでは、myGetBounds 関数は省略していま
す。この関数については、85 ページの「テキストフレームの作成」または ExportTextRange というチュート
リアルスクリプトを参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Set myStory = myTextFrame.ParentStory
Set myStartCharacter = myStory.Paragraphs.Item(1).Characters.Item(1)
Set myEndCharacter = myStory.Paragraphs.Item(1).Characters.Item(-1)
Set myText = myTextFrame.ParentStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
Rem Text export method parameters:
Rem Format as idExportFormat
Rem To As File
Rem [ShowingOptions As Boolean = False]
Rem
Rem Format parameter can be:
Rem idExportFormat.idInCopy
Rem idExportFormat.idInCopyCS2Story
Rem idExportFormat.idRTF
Rem idExportFormat.idTaggedText
Rem idExportFormat.idTextType
Rem
Rem Export the text range. You'll have to fill in a valid file path on your system.
myText.Export idExportFormat.idTextType, "C:¥test.txt"
書き出すテキストファイルの種類に応じた書き出しオプションを指定するには、対応する書き出し環境設定
オブジェクトを使用します。テキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完
全なスクリプトについては、TextExportPreferences を参照してください)。
With myInDesign.TextExportPreferences
Rem Options for characterSet: idTextExportCharacterSet
.CharacterSet = idTextExportCharacterSet.idUTF8
Rem platform options: idImportPlatform
.Platform = idImportPlatform.idPC
End With
第 6 章 テキストと組版
テキストの書き出しとテキスト書き出し環境設定の指定
92
タグ付きテキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完全なスクリプトにつ
いては、TaggedTextExportPreferences を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
With myInDesign.TaggedTextExportPreferences
Rem Options for characterSet:
Rem idTagTextExportCharacterSet.idAnsi
Rem idTagTextExportCharacterSet.idASCII
Rem idTagTextExportCharacterSet.idGB18030
Rem idTagTextExportCharacterSet.idKSC5601
Rem idTagTextExportCharacterSet.idShiftJIS
Rem idTagTextExportCharacterSet.idUnicode
.CharacterSet = idTagTextExportCharacterSet.idUnicode
Rem tagForm options:
Rem idTagTextForm.idAbbreviated
Rem idTagTextForm.idVerbose
.TagForm = idTagTextForm.idVerbose
End With
ドキュメント内のすべてのテキストを 1 ステップの操作で書き出すことはできません。すべてのテキストを
まとめたい場合は、ドキュメント内のテキストを 1 つのストーリーに結合してからそのストーリーを書き出
すか、または、生成された複数のファイルをスクリプトで読み込んで 1 つのファイルに書き出す必要があり
ます。次のスクリプトでは、前者の方法を使用しています (ここでは、myGetBounds 関数は省略しています。
この関数については、85 ページの「テキストフレームの作成」または ExportAllText というチュートリアルス
クリプトを参照してください)。書き出す形式が単純なテキスト形式でない場合、後者の方法はかなり複雑に
なることがあります。
If myInDesign.Documents.Count <> 0 Then
If myInDesign.Documents.Item(1).Stories.Count <> 0 Then
myExportAllText myInDesign, myInDesign.Documents.Item(1).Name
End If
End If
このスクリプトで参照されている ExportAllText 関数を次に示します。
Function myExportAllText(myInDesign, myDocumentName)
mySeparatorString = "----------------------------------------" & vbCr
Rem If you want to add a separator line between stories,
Rem set myAddSeparator to true.
myAddSeparator = True
Set myNewDocument = myInDesign.Documents.Add
Set myDocument = myInDesign.Documents.Item(myDocumentName)
Set myTextFrame = myNewDocument.Pages.Item(1).TextFrames.Add
myTextFrame.geometricBounds = myGetBounds(myNewDocument,
myNewDocument.Pages.Item(1))
Set myNewStory = myTextFrame.ParentStory
For myCounter = 1 To myDocument.Stories.Count
Set myStory = myDocument.Stories.Item(myCounter)
myStory.texts.item(1).duplicate idLocationOptions.idAfter,
myNewStory.InsertionPoints.Item(1)
Rem If the text did not end with a return, enter a return
Rem to keep the stories from running together.
If myCounter <> myDocument.Stories.Count Then
If myNewStory.Characters.Item(-1).Contents <> vbCr Then
myNewStory.InsertionPoints.Item(-1).Contents = vbCr
End If
If myAddSeparator = True Then
myNewStory.InsertionPoints.Item(-1).Contents = mySeparatorString
End If
End If
Next
myNewStory.Export idExportFormat.idTaggedText, "c:¥test.txt"
myNewDocument.Close idSaveOptions.idNo
End Function
第 6 章 テキストと組版
テキストの書き出しとテキスト書き出し環境設定の指定
93
既存の書き出しフィルターを使用しないでテキストを書き出すこともできます。VBScript には、テキストファ
イルをディスクに書き出す機能が用意されています。この機能を利用すれば、スクリプトでドキュメント内
のテキストをスキャンして、任意のテキストマークアップスキームを使用して任意の順序でテキストを書き
出すことができます。HTML 形式で InDesign テキストを書き出す簡単な例を次に示します (ここでは、
myGetBounds 関数は省略しています。この関数については、85 ページの「テキストフレームの作成」または
ExportHTML というチュートリアルスクリプトを参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Rem Use the myStyleToTagMapping dictionary to set
Rem up your paragraph style to tag mapping.
Set myStyleToTagMapping = CreateObject("Scripting.Dictionary")
Rem For each style to tag mapping, add a new item to the dictionary.
myStyleToTagMapping.Add "body_text", "p"
myStyleToTagMapping.Add "heading1", "h1"
myStyleToTagMapping.Add "heading2", "h2"
myStyleToTagMapping.Add "heading3", "h3"
Rem End of style to tag mapping.
If myDocument.Stories.Count <> 0 Then
Rem Open a new text file.
Set myDialog = CreateObject("UserAccounts.CommonDialog")
myDialog.Filter = "HTML Files|*.html|All Files|*.*"
myDialog.FilterIndex = 1
myDialog.InitialDir = "C:¥"
myResult = myDialog.ShowOpen
Rem If the user clicked the Cancel button, the result is null.
If myResult = True Then
myTextFileName = myDialog.FileName
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myTextFile = myFileSystemObject.CreateTextFile(myTextFileName)
For myCounter = 1 To myInDesign.Documents.Item(1).Stories.Count
Set myStory = myDocument.Stories.Item(myCounter)
For myParagraphCounter = 1 To myStory.Paragraphs.Count
Set myParagraph = myStory.Paragraphs.Item(myParagraphCounter)
If myParagraph.Tables.Count = 0 Then
If myParagraph.TextStyleRanges.Count = 1 Then
Rem If the paragraph is a simple paragraph--no tables,
Rem no local formatting--then simply export the text
Rem of the pararaph with the appropriate tag.
myTag = myStyleToTagMapping.Item(myParagraph.
AppliedParagraphStyle.Name)
Rem If the tag comes back empty, map it to the basic paragraph tag.
If myTag = "" Then
myTag = "p"
End If
myStartTag = "<" & myTag & ">"
myEndTag = "</" & myTag & ">"
Rem If the paragraph is not the last paragraph in the story,
Rem omit the return character.
If myParagraph.Characters.Item(-1).Contents = vbCr Then
myString = myParagraph.Texts.ItemByRange(myParagraph.
Characters.Item(1), myParagraph.Characters.Item(-2)).
Item(1).Contents
Else
myString = myParagraph.Contents
End If
Rem Write the paragraphs' text to the text file.
myTextFile.WriteLine myStartTag & myString & myEndTag
Else
Rem Handle text style range export by iterating
Rem through the text style ranges in the paragraph..
For myRangeCounter = 1 To myParagraph.TextStyleRanges.Length
myTextStyleRange = myParagraph.TextStyleRanges.Item
(myRangeCounter)
If myTextStyleRange.Characters.Item(-1) = vbCr Then
myString = myTextStyleRange.Texts.ItemByRange
第 6 章 テキストと組版
テキストの書き出しとテキスト書き出し環境設定の指定
(myTextStyleRange.Characters.Item(1),
myTextStyleRange.Characters.Item(-2)).Item(1).Contents
Else
myString = myTextStyleRange.Contents
End If
Select Case myTextStyleRange.FontStyle
Case "Bold":
myString = "<b>" & myString & "</b>"
Case "Italic":
myString = "<i>" & myString & "</i>"
End Select
myTextFile.write myString
Next
myTextFile.write vbCr
End If
Else
Rem Handle table export (assumes that there is
Rem only one table per paragraph,
Rem and that the table is in the paragraph by itself).
Set myTable = myParagraph.Tables.Item(1)
myTextFile.write "<table border = 1>"
For myRowCounter = 1 To myTable.Rows.Count
myTextFile.write "<tr>"
For myColumnCounter = 1 To myTable.Columns.Count
If myRowCounter = 1 Then
myString = "<th>" & myTable.Rows.Item(myRowCounter).
Cells.Item(myColumnCounter).Texts.Item(1).Contents &
"</th>"
Else
myString = "<td>" & myTable.Rows.Item(myRowCounter).
Cells.Item(myColumnCounter).Texts.Item(1).Contents &
"</td>"
End If
myTextFile.write myString
Next
myTextFile.WriteLine "</tr>"
Next
myTextFile.WriteLine "</table>"
End If
Next
Rem Close the text file.
myTextFile.Close
Next
End If
End If
このスクリプトで参照されている myFindTag 関数を次に示します。
function myFindTag (myStyleName, myStyleToTagMapping){
var myTag = "";
var myDone = false;
var myCounter = 0;
do{
if(myStyleToTagMapping[myCounter][0] == myStyleName){
myTag = myStyleToTagMapping[myCounter][1];
break;
}
myCounter ++;
} while((myDone == false)||(myCounter < myStyleToTagMapping.length))
return myTag;
}
94
第 6 章 テキストと組版
テキストオブジェクト
95
テキストオブジェクト
次の図は、InDesign のテキストオブジェクトモデルを図式化したものです。この図にもあるように、テキス
トオブジェクトには レイアウトオブジェクト(テキストフレーム)とテキストストリームオブジェクト(ス
トーリー、挿入点、文字、単語など)の 2 つの種類があります。
document
story
spread, page, layer
insertion points
characters
text containers
text frame
words
insertion points
lines
characters
paragraphs
words
text columns
lines
text style ranges
paragraphs
texts
text columns
notes
text style ranges
texts
notes
特定のテキストオブジェクトへの参照を取得するには、様々な方法があります。次の図に、新規ドキュメン
トの最初のページの最初のテキストフレームにある最初の文字を参照する方法をいくつか示します。
第 6 章 テキストと組版
テキストオブジェクト
96
document
pages.item(0)
textFrames.item(0)
characters.item(0)
textFrames.item(0)
paragraphs.item(0)
characters.item(0)
stories.item(0)
characters.item(0)
stories.item(0)
paragraphs.item(0)
characters.item(0)
テキストストリームオブジェクトの parent は、そのオブジェクトが含まれているストーリーです。テキスト
オブジェクトが含まれているテキストフレーム(またはテキストフレームのコレクション)への参照を取得
するには、ParentTextFrames プロパティを使用します。
テキストフレームの parent は、通常、そのテキストフレームが含まれているページまたはスプレッドです。
グループ内にあるテキストフレームや、別のページアイテム内にペーストされたテキストフレームの parent
は、そのテキストフレームが含まれているページアイテムです。アンカー付きフレームに変換されたテキス
トフレームの parent は、そのアンカー付きフレームが含まれている文字です。
テキスト選択の操作
テキスト関連のスクリプトでよく行われる操作の 1 つが、テキスト選択に対する操作です。現在の選択がテ
キスト選択かどうかを調べる方法を、次のスクリプトに示します。他の多くのサンプルスクリプトと異なり、
このスクリプトは実際には何も行いません。このスクリプトでは、選択をフィルタリングする方法のみが示
されています(完全なスクリプトについては、TextSelection を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count <> 0 Then
Rem If the selection contains more than one item, the selection
Rem is not text selected with the Type tool.
If myInDesign.Selection.Count = 1 Then
Select Case TypeName(myInDesign.Selection.Item(1))
Case "InsertionPoint", "Character", "Word", "TextStyleRange",
"Line", "Paragraph", "TextColumn", "Text"
MsgBox "The selection is a text object."
Rem A real script would now act on the text object
Rem or pass it on to a function.
Case "TextFrame"
Rem In addition to checking for the above text objects, we can
Rem also continue if the selection is a text frame selected with
Rem the Selection tool or the Direct Selection tool.
第 6 章 テキストと組版
テキストオブジェクト
97
Rem If the selection is a text frame, you get a reference to the
Rem text in the text frame and then pass it along to a function.
Rem Set myText = myInDesign.Selection.Item(1).Texts.Item(1)
MsgBox "The selected object is a text frame."
Case Else
MsgBox "The selected object is not a text object.
Select some text and try again."
End Select
Else
MsgBox "Please select some text and try again."
End If
Else
MsgBox "No documents are open. Please open a document,
select some text, and try again."
End If
テキストの移動とコピー
move メソッドを使用して、テキスト内の別の場所にテキストオブジェクトを移動することができます。テキ
ストをコピーするには、duplicate メソッドを使用します(パラメーターは move メソッドと同じです)。次の
スクリプトにその例を示します(完全なスクリプトについては、MoveText を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Rem Set the bounds live area of the page.
myBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
myX1 = myBounds(1)
myY1 = myBounds(0)
myX2 = myBounds(3)
myY2 = myBounds(2)
myWidth = myX2 - myX1
myHeight = myY2 - myY1
Rem Create a series of text frames.
Set myTextFrameA = myPage.TextFrames.Add
myTextFrameA.geometricBounds = Array(myY1, myX1, myY1 + (myHeight / 2), myX1 + (myWidth / 2))
myTextFrameA.Contents = "Before." & vbCr
Set myTextFrameB = myPage.TextFrames.Add
myTextFrameB.geometricBounds = Array(myY1, myX1 + (myWidth / 2), myY1 + (myHeight / 2), myX2)
myTextFrameB.Contents = "After." & vbCr
Set myTextFrameC = myPage.TextFrames.Add
myTextFrameC.geometricBounds = Array(myY1 + (myHeight / 2), myX1, myY2, myX1 + (myWidth / 2))
myTextFrameC.Contents = "Between words." & vbCr
Set myTextFrameD = myPage.TextFrames.Add
myTextFrameD.geometricBounds = Array(myY1 + (myHeight / 2), myX1 + (myWidth / 2), myY2, myX2)
myTextFrameD.Contents = "Text to move:" & vbCr & "WordA" & vbCr & "WordB" & vbCr & "WordC" & vbCr
Rem Move WordC between the words in TextFrameC.
myTextFrameD.ParentStory.Paragraphs.Item(-1).Words.Item(1).Move idLocationOptions.idBefore,
myTextFrameC.ParentStory.Paragraphs.Item(1).Words.Item(2)
Rem Move WordB after the word in TextFrameB.
myTextFrameD.ParentStory.Paragraphs.Item(-2).Words.Item(1).Move idLocationOptions.idAfter,
myTextFrameB.ParentStory.Paragraphs.Item(1).Words.Item(1)
Rem Move WordA to before the word in TextFrameA.
myTextFrameD.ParentStory.Paragraphs.Item(-3).Words.Item(1).Move idLocationOptions.idBefore,
myTextFrameA.ParentStory.Paragraphs.Item(1).Words.Item(1)
Rem Note that moving text removes it from its original location.
フォーマットされたテキストをドキュメント間で転送する場合にも、move メソッドが使用できます。コピー
して貼り付けるよりも、move メソッドや duplicate メソッドを使用するほうが優れています。コピーして貼
り付けるためには、ドキュメントを表示して、コピーするテキストを選択しなければなりません。move や
duplicate を使用するほうが速くて確実です。move や duplicate を使用して、ドキュメント間でテキストを
移動する方法を、次のスクリプトに示します (ここでは、myGetBounds 関数は省略しています。この関数に
ついては、85 ページの「テキストフレームの作成」または MoveTextBetweenDocuments というチュートリア
ルスクリプトを参照してください)。
第 6 章 テキストと組版
テキストオブジェクト
98
Rem Create the source document
Set mySourceDocument = myInDesign.Documents.Add
Set mySourcePage = mySourceDocument.Pages.Item(1)
Set mySourceTextFrame = mySourcePage.TextFrames.Add
mySourceTextFrame.geometricBounds = myGetBounds(mySourceDocument, mySourcePage)
mySourceTextFrame.Contents = "This is the source text." & vbCr & "This text is not the source
text."
Set mySourceParagraph = mySourceTextFrame.ParentStory.Paragraphs.Item(1)
mySourceParagraph.PointSize = 24
Rem Create the target document.
Set myTargetDocument = myInDesign.Documents.Add
Set myTargetPage = myTargetDocument.Pages.Item(1)
Set myTargetTextFrame = myTargetPage.TextFrames.Add
myTargetTextFrame.GeometricBounds = myGetBounds(myTargetDocument, myTargetPage)
myTargetTextFrame.Contents = "This is the target text. Insert the source text before this
paragraph." & vbCr
Rem Move the text from the source document to the target document.
Rem This deletes the text from the source document.
mySourceParagraph.Move idLocationOptions.idBefore, myTargetTextFrame.InsertionPoints.Item(1)
Rem To duplicate (rather than move) the text, use the following:
Rem mySourceParagraph.Duplicate idLocationOptions.idBefore,
myTargetTextFrame.InsertionPoints.Item(1)
テキストをコピーして貼り付ける必要がある場合は、アプリケーションの copy メソッドを使用できます。こ
の場合は、コピーする前にテキストを選択しておく必要があります。繰り返しになりますが、コピーして貼
り付ける方法は最後の手段だと考えてください。他の方法を使用するほうが速くて確実であり、ドキュメン
トを表示する必要がありません (ここでは、myGetBounds 関数は省略しています。この関数については、
85 ページの「テキストフレームの作成」または CopyPasteText というチュートリアルスクリプトを参照して
ください)
。
Set myDocumentA = myInDesign.Documents.Add
Set myPageA = myDocumentA.Pages.Item(1)
Set myTextFrameA = myPageA.TextFrames.Add
myTextFrameA.GeometricBounds = myGetBounds(myDocumentA, myPageA)
myTextFrameA.Contents = "Example text." & vbCr
Set myDocumentB = myInDesign.Documents.Add
Set myPageB = myDocumentB.Pages.Item(1)
Set myTextFrameB = myPageB.TextFrames.Add
myTextFrameB.GeometricBounds = myGetBounds(myDocumentB, myPageB)
Rem Make document A the active document.
myInDesign.ActiveDocument = myDocumentA
Rem Select the text.
myInDesign.Select myTextFrameA.ParentStory.Texts.Item(1)
myInDesign.Copy
Rem Make document B the active document.
myInDesign.ActiveDocument = myDocumentB
Rem Select the insertion point at which you want to paste the text.
myInDesign.Select myTextFrameB.ParentStory.InsertionPoints.Item(1)
myInDesign.Paste
フォーマットされていないテキストをテキストオブジェクト間でコピーする方法としては、コピーするテキ
ストオブジェクトの contents プロパティを取得して、その文字列を別のテキストオブジェクトの contents
プロパティに設定する方法があります。次のスクリプトにその例を示します(完全なスクリプトについては、
CopyUnformattedText を参照してください)。
第 6 章 テキストと組版
テキストオブジェクト
99
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrameA = myPage.TextFrames.Add
myTextFrameA.geometricBounds = Array(72, 72, 144, 288)
myTextFrameA.Contents = "This is a formatted string."
myTextFrameA.ParentStory.Texts.Item(1).FontStyle = "Bold"
Set myTextFrameB = myPage.TextFrames.Add
myTextFrameB.geometricBounds = Array(228, 72, 300, 288)
myTextFrameB.Contents = "This is the destination text frame. Text pasted here will retain its
formatting."
myTextFrameB.ParentStory.Texts.Item(1).FontStyle = "Italic"
Rem Copy from one frame to another using a simple copy.
myInDesign.Select myTextFrameA.Texts.Item(1)
myInDesign.Copy
myInDesign.Select myTextFrameB.ParentStory.InsertionPoints.Item(-1)
myInDesign.Paste
Rem Create another text frame on the active page.
Set myTextFrameC = myPage.TextFrames.Add
myTextFrameC.geometricBounds = Array(312, 72, 444, 288)
myTextFrameC.Contents = "Text copied here will take on the formatting of the existing text."
myTextFrameC.ParentStory.Texts.Item(1).FontStyle = "Italic"
Rem Copy the unformatted string from text frame A to the end of text frame C (note
Rem that this doesn't really copy the text it replicates the text string from one
Rem text frame in another text frame):
myTextFrameC.ParentStory.InsertionPoints.Item(-1).Contents =
myTextFrameA.ParentStory.Texts.Item(1).Contents
テキストオブジェクトと反復処理
一連のテキストオブジェクトに対して繰り返して処理を行っている間に、テキストの移動、削除、追加を行
うと、テキスト参照に問題が発生することがあります。このような問題が発生する例を、次のスクリプトに
示します (ここでは、myGetBounds 関数は省略しています。この関数については、85 ページの「テキストフ
レームの作成」または TextIterationWrong というチュートリアルスクリプトを参照してください)。
Set
Set
Rem
For
myDocument = myInDesign.Documents.Item(1)
myStory = myDocument.Stories.Item(1)
The following for loop cause an error.
myParagraphCounter = 1 to myStory.Paragraphs.Count
If myStory.Paragraphs.Item(myParagraphCounter).Words.Item(1).contents = "Delete" Then
myStory.Paragraphs.Item(myParagraphCounter).Delete
Else
myStory.Paragraphs.Item(myParagraphCounter).PointSize = 24
End If
Next
この例では、フォーマットされない段落がいくつか発生することになります。その理由は次のとおりです。こ
のスクリプトのループは、ストーリー内の最初の段落から最後の段落まで、段落に対して繰り返し処理を行
います。そうすると、「Delete」という単語で始まる段落があれば削除されます。このスクリプトで第 2 段落
が削除されると、第 3 段落がその場所に移動します。次にループカウンターが 3 になると、先ほどまで第 4 段
落であった段落が処理されます。第 3 段落であった段落はこの時点で第 2 段落になっているので、処理は行
われません。
この問題を回避するには、次のスクリプトのように、テキストオブジェクトを逆順で処理します (ここで
は、myGetBounds 関数は省略しています。この関数については、85 ページの「テキストフレームの作成」ま
たは TextIterationRight というチュートリアルスクリプトを参照してください)。
第 6 章 テキストと組版
テキストフレームの操作
100
Set
Set
Rem
Rem
For
myDocument = myInDesign.Documents.Item(1)
myStory = myDocument.Stories.Item(1)
The following for loop will format all of the paragraphs by iterating
backwards through the paragraphs in the story.
myCounter = myStory.Paragraphs.Count To 1 Step -1
If myStory.Paragraphs.Item(myCounter).Words.Item(1).contents = "Delete" Then
myStory.Paragraphs.Item(myCounter).Delete
Else
myStory.Paragraphs.Item(myCounter).PointSize = 24
End If
Next
テキストフレームの操作
前の節ではテキストストリームオブジェクトの操作について説明しましたが、この節ではテキストフレーム
(InDesign ドキュメント内のテキストを格納するページレイアウトアイテム)について説明します。
テキストフレームのリンク
InDesign スクリプティングで、テキストフレームのリンクをたどっていく際に重要になるのが、テキストフ
レームの nextTextFrame プロパティと previousTextFrame プロパティです。これらのプロパティは、InDesign
テキストフレームの入力ポートと出力ポートに相当します。次のスクリプトにその例を示します(完全なス
クリプトについては、LinkTextFrames を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrameA = myPage.TextFrames.Add
myTextFrameA.geometricBounds = Array(72, 72, 144, 144)
Set myTextFrameB = myPage.TextFrames.Add
myTextFrameB.geometricBounds = Array(228, 72, 300, 144)
Rem Add a page.
Set myNewPage = myDocument.Pages.Add
Rem Create another text frame on the new page.
Set myTextFrameC = myNewPage.TextFrames.Add
myTextFrameC.geometricBounds = Array(72, 72, 144, 144)
Rem Link TextFrameA to TextFrameB using the nextTextFrame property.
myTextFrameA.NextTextFrame = myTextFrameB
Rem Link TextFrameC to TextFrameB using the previousTextFrame property.
myTextFrameC.PreviousTextFrame = myTextFrameB
Rem Fill the text frames with placeholder text.
myTextFrameA.Contents = idTextFrameContents.idPlaceholderText
テキストフレームのリンク解除
テキストフレームのリンクを解除する方法を、次のスクリプト例に示します(完全なスクリプトについては、
UnlinkTextFrames を参照してください)。
Rem Given two linked text frames on page 1...
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrameA = myPage.TextFrames.Item(-1)
Rem Unlink text frame A.
myTextFrameA.NextTextFrame = Nothing
第 6 章 テキストと組版
テキストフレームの操作
101
ストーリーからのフレームの削除
InDesign では、ストーリーからフレームを削除しても、フレーム内のテキストは削除されません(そのフ
レームがストーリー内の唯一のフレームである場合を除く)。ストーリー内の他のフレームを維持したまま、
特定のフレームとそこに含まれているテキストをストーリーから削除する方法を、次のスクリプトに示しま
す(完全なスクリプトについては、BreakFrame を参照してください)。
ReDim myObjectList(0)
Rem Script does nothing if no documents are open or if no objects are selected.
If myInDesign.Documents.Count <> 0 Then
If myInDesign.Selection.Count <> 0 Then
Rem Process the objects in the selection to create a list of
Rem qualifying objects (text frames).
For myCounter = 1 To myInDesign.Selection.Count
Select Case TypeName(myInDesign.Selection.Item(myCounter))
Case "TextFrame":
If Not (IsEmpty(myObjectList(0))) Then
ReDim Preserve myObjectList(UBound(myObjectList) + 1)
End If
Set myObjectList(UBound(myObjectList)) =
myInDesign.Selection.Item(myCounter)
Case "InsertionPoint", "Character", "Word", "TextStyleRange", "Line",
"Paragraph", "TextColumn", "Text":
If Not (IsEmpty(myObjectList(0))) Then
ReDim Preserve myObjectList(UBound(myObjectList) + 1)
End If
Set myObjectList(UBound(myObjectList)) =
myInDesign.Selection.Item(myCounter).ParentTextFrames.Item(1)
End Select
Next
Rem If the object list is not empty, pass it on to the function
Rem that does the real work.
If Not (IsEmpty(myObjectList(0))) Then
myBreakFrames myObjectList
End If
End If
End If
このスクリプトで参照されている myBreakFrames 関数を次に示します。
Function myBreakFrames(myObjectList)
For myCounter = UBound(myObjectList) To 0 Step -1
myBreakOutFrame myObjectList(myCounter)
Next
End Function
Function myBreakFrame(myTextFrame)
myProcessFrame = vbYes
If (TypeName(myTextFrame.NextTextFrame) <> "Nothing") Or
(TypeName(myTextFrame.PreviousTextFrame) <> "Nothing") Then
If myTextFrame.ParentStory.Tables.Count <> 0 Then
myProcessFrame = MsgBox("This story contains tables. If the text frame you
are trying to remove from the story contains a table, the results might not be
what you expect. Do you want to continue?", vbYesNo)
End If
If myProcessFrame = vbYes Then
Set myNewFrame = myTextFrame.Duplicate
If myTextFrame.Contents <> "" Then
myTextFrame.Texts.Item(1).Delete
End If
myTextFrame.Delete
End If
End If
End Function
第 6 章 テキストと組版
テキストフレームの操作
102
ストーリー内のすべてのフレームの分割
ストーリー内のすべてのフレームを独立した別個のストーリーに分割して、リンクされていないテキストフ
レームが各ストーリーに 1 つだけ含まれるようにする方法を、次のスクリプトに示します(完全なスクリプ
トについては、SplitStory を参照してください)。
Rem Get the first item in the selection.
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Set myStory = myTextFrame.ParentStory
Rem If the text frame is the only text frame in the story, do nothing.
If myStory.TextContainers.Count > 1 Then
Rem Splitting the story is a two-step process: first, duplicate
Rem the text frames, second, delete the original text frames.
mySplitStory myStory
myRemoveFrames myStory
End If
このスクリプトで参照されている mySplitStory 関数を次に示します。
Function mySplitStory(myStory)
Rem Duplicate each text frame in the story.
For myCounter = myStory.TextContainers.Count To 1 Step -1
Set myTextFrame = myStory.TextContainers.Item(myCounter)
myTextFrame.Duplicate
Next
End Function
Function myRemoveFrames(myStory)
Rem Remove each text frame in the story.
RemIterate backwards to avoid invalid references.
For myCounter = myStory.TextContainers.Count To 1 Step -1
myStory.TextContainers.Item(myCounter).Delete
Next
End Function
アンカー付きフレームの作成
アンカー付きフレーム(インラインフレームとも呼ばれます)を作成するには、テキストの特定の位置(通
常は挿入点)にテキストフレーム(または長方形、楕円形、多角形、グラフィックの線)を作成します。次
のスクリプトにその例を示します(完全なスクリプトについては、AnchoredFrame を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
set myTextFrame = myPage.TextFrames.Item(1)
Set myInsertionPoint = myTextFrame.Paragraphs.Item(1).InsertionPoints.Item(1)
Set myInlineFrame = myInsertionPoint.TextFrames.Add
Rem Recompose the text to make sure that getting the
Rem geometric bounds of the inline graphic will work.
myTextFrame.Texts.Item(1).Recompose
Rem Get the geometric bounds of the inline frame.
myBounds = myInlineFrame.GeometricBounds
Rem Set the width and height of the inline frame. In this example, we'll
Rem make the frame 24 points tall by 72 points wide.
myArray = Array(myBounds(0), myBounds(1), myBounds(0) + 24, myBounds(1) + 72)
myInlineFrame.GeometricBounds = myArray
myInlineFrame.Contents = "This is an inline frame."
Set myInsertionPoint = myTextFrame.Paragraphs.Item(2).InsertionPoints.Item(1)
Set myAnchoredFrame = myInsertionPoint.TextFrames.Add
Rem Recompose the text to make sure that getting the
Rem geometric bounds of the inline graphic will work.
myTextFrame.Texts.Item(1).Recompose
Rem Get the geometric bounds of the inline frame.
第 6 章 テキストと組版
テキストフレームの操作
103
myBounds = myAnchoredFrame.GeometricBounds
Rem Set the width and height of the inline frame. In this example, we'll
Rem make the frame 24 points tall by 72 points wide.
myArray = Array(myBounds(0), myBounds(1), myBounds(0) + 24, myBounds(1) + 72)
myAnchoredFrame.GeometricBounds = myArray
myAnchoredFrame.Contents = "This is an anchored frame."
With myAnchoredFrame.AnchoredObjectSettings
.AnchoredPosition = idAnchorPosition.idAnchored
.AnchorPoint = idAnchorPoint.idTopLeftAnchor
.HorizontalReferencePoint = idAnchoredRelativeTo.idAnchorLocation
.HorizontalAlignment = idHorizontalAlignment.idLeftAlign
.AnchorXoffset = 72
.VerticalReferencePoint = idVerticallyRelativeTo.idLineBaseline
.AnchorYoffset = 24
.AnchorSpaceAbove = 24
End With
テキストフレームをコンテンツに合わせる
テキストフレームにルールを設定し、ユーザーのテキスト入力に応じてテキストフレームを伸縮させる方法
を、次のスクリプトに示します(完全なスクリプトについては、PersistedTextFrameFill を参照してください)。
Set myDocument = myInDesign.Documents.item(1)
Set myTextFrame = myDocument.Pages.item(1).TextFrames.item(4)
REM Now add text at the end of the text frame.
myTextFrame.InsertionPoints.item(-1).Contents = vbCr&"This is some overset text"
MsgBox("The last paragraph in this alert should be ""This is some overset text"". Is it?" & _
vbCr&myTextFrame.Contents)
MsgBox("The last paragraph in this alert should be ""This is some overset text"". Is it?" & _
vbCr&myTextFrame.ParentStory.Contents)
Set myTextFrame2 = myDocument.Pages.item(1).TextFrames.item(3)
REM Set auto size dimension of the text frame
with myTextFrame2.TextFramePreferences
.AutoSizingDimension=idAutoSizingDimension.idHEIGHTANDWIDTHPROPORTIONALLY
End With
REM Now add text at the end of the text frame.
myTextFrame2.InsertionPoints.item(-1).Contents = vbCr&"This is some overset text"
Set myTextFrame3 = myDocument.Pages.item(1).TextFrames.item(2)
REM Set auto size dimension of the text frame
REM useMinimumHeightForAutoSizing and useNoLineBreaksForAutoSizing
with myTextFrame3.TextFramePreferences
.AutoSizingDimension=idAutoSizingDimension.idHEIGHTONLY
.UseMinimumHeightForAutoSizing=true
.UseNoLineBreaksForAutoSizing=true
End With
REM Now add text at the end of the text frame.
myTextFrame3.InsertionPoints.item(-1).Contents = vbCr&"This is some overset text"
Set myTextFrame4 = myDocument.Pages.item(1).TextFrames.item(1)
REM Set auto size dimension of the text frame and autoSizingReferencePoint
with myTextFrame4.TextFramePreferences
.AutoSizingDimension=idAutoSizingDimension.idWIDTHONLY
.AutoSizingReferencePoint=idAutoSizingReferencePoint.idTOPLEFTPOSITION
End With
REM Now add text at the end of the text frame.
myTextFrame4.InsertionPoints.item(-1).Contents = vbCr&"This is some overset text"
第 6 章 テキストと組版
テキストのフォーマット
104
テキストのフォーマット
この章の前の節では、ドキュメントにテキストを追加し、テキストフレームをリンクし、ストーリーやテキ
ストオブジェクトを操作しました。この節では、テキストにフォーマットを適用します。InDesign のすべての
フォーマット機能は、スクリプティングで操作することができます。
テキストデフォルトの設定
テキストデフォルトは、アプリケーションとドキュメントの両方で設定できます。アプリケーションのテキ
ストデフォルトは、新しく作成されるすべてのドキュメントのテキストデフォルトとして使用されます。ド
キュメントのテキストデフォルトは、そのドキュメントで新しく作成されるすべてのテキストオブジェクト
のフォーマットとして使用されます (完全なスクリプトについては、TextDefaults を参照してください)。
With myInDesign.TextDefaults
.AlignToBaseline = True
Rem Because the font might not be available, it's usually best
Rem to trap errors using "On Error Resume Next" error handling.
Rem Fill in the name of a font on your system.
Err.Clear
On Error Resume Next
.AppliedFont = myInDesign.Fonts.Item("Minion Pro")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
Rem Because the font style might not be available, it's usually best
Rem to trap errors using "On Error Resume Next" error handling.
Err.Clear
On Error Resume Next
.FontStyle = "Regular"
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
Rem Because the language might not be available, it's usually best
Rem to trap errors using "On Error Resume Next" error handling.
Err.Clear
On Error Resume Next
.AppliedLanguage = "English: USA"
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.AutoLeading = 100
.BalanceRaggedLines = False
.BaselineShift = 0
.Capitalization = idCapitalization.idNormal
.Composer = "Adobe Paragraph Composer"
.DesiredGlyphScaling = 100
.DesiredLetterSpacing = 0
.DesiredWordSpacing = 100
.DropCapCharacters = 0
If .DropCapCharacters <> 0 Then
.DropCapLines = 3
On Error Resume Next
.DropCapStyle = myInDesign.CharacterStyles.Item("myDropCap")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
End If
On Error Resume Next
.FillColor = myInDesign.Colors.Item("Black")
第 6 章 テキストと組版
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.FillTint = 100
.FirstLineIndent = 14
.GridAlignFirstLineOnly = False
.HorizontalScale = 100
.HyphenateAfterFirst = 3
.HyphenateBeforeLast = 4
.HyphenateCapitalizedWords = False
.HyphenateLadderLimit = 1
.HyphenateWordsLongerThan = 5
.Hyphenation = True
.HyphenationZone = 36
.HyphenWeight = 9
.Justification = idJustification.idLeftAlign
.KeepAllLinesTogether = False
.KeepLinesTogether = True
.KeepFirstLines = 2
.KeepLastLines = 2
.KeepWithNext = 0
.KerningMethod = "Optical"
.Leading = 14
.LeftIndent = 0
.Ligatures = True
.MaximumGlyphScaling = 100
.MaximumLetterSpacing = 0
.MaximumWordSpacing = 160
.MinimumGlyphScaling = 100
.MinimumLetterSpacing = 0
.MinimumWordSpacing = 80
.NoBreak = False
.OTFContextualAlternate = True
.OTFDiscretionaryLigature = True
.OTFFigureStyle = idOTFFigureStyle.idProportionalOldstyle
.OTFFraction = True
.OTFHistorical = True
.OTFOrdinal = False
.OTFSlashedZero = True
.OTFSwash = False
.OTFTitling = False
.OverprintFill = False
.OverprintStroke = False
.PointSize = 11
.Position = idPosition.idNormal
.RightIndent = 0
.RuleAbove = False
If .RuleAbove = True Then
On Error Resume Next
.RuleAboveColor = myInDesign.Colors.Item("Black")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
On Error Resume Next
.RuleAboveGapColor = myInDesign.Swatches.Item("None")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.RuleAboveGapOverprint = False
.RuleAboveGapTint = 100
.RuleAboveLeftIndent = 0
.RuleAboveLineWeight = 0.25
.RuleAboveOffset = 14
テキストのフォーマット
105
第 6 章 テキストと組版
.RuleAboveOverprint = False
.RuleAboveRightIndent = 0
.RuleAboveTint = 100
On Error Resume Next
.RuleAboveType = myInDesign.StrokeStyles.Item("Solid")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.RuleAboveWidth = idRuleWidth.idColumnWidth
End If
.RuleBelow = False
If .RuleBelow = True Then
On Error Resume Next
.RuleBelowColor = myInDesign.Colors.Item("Black")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
On Error Resume Next
.RuleBelowGapColor = myInDesign.Swatches.Item("None")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.RuleBelowGapOverPrint = False
.RuleBelowGapTint = 100
.RuleBelowLeftIndent = 0
.RuleBelowLineWeight = 0.25
.RuleBelowOffset = 0
.RuleBelowOverPrint = False
.RuleBelowRightIndent = 0
.RuleBelowTint = 100
On Error Resume Next
.RuleBelowType = myInDesign.StrokeStyles.Item("Solid")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.RuleBelowWidth = idRuleWidth.idColumnWidth
End If
.SingleWordJustification = idSingleWordJustification.idLeftAlign
.Skew = 0
.SpaceAfter = 0
.SpaceBefore = 0
.StartParagraph = idStartParagraph.idAnywhere
.StrikeThru = False
If .StrikeThru = True Then
On Error Resume Next
.StrikeThroughColor = myInDesign.Colors.Item("Black")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
On Error Resume Next
.StrikeThroughGapColor = myInDesign.Swatches.Item("None")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.StrikeThroughGapOverprint = False
.StrikeThroughGapTint = 100
.StrikeThroughOffset = 3
.StrikeThroughOverprint = False
テキストのフォーマット
106
第 6 章 テキストと組版
.StrikeThroughTint = 100
On Error Resume Next
.StrikeThroughType = myInDesign.StrokeStyles.Item("Solid")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.StrikeThroughWeight = 0.25
End If
On Error Resume Next
.StrokeColor = myInDesign.Swatches.Item("None")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.StrokeTint = 100
.StrokeWeight = 0
.Tracking = 0
.Underline = False
If .Underline = True Then
On Error Resume Next
.UnderlineColor = myInDesign.Colors.Item("Black")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
On Error Resume Next
.UnderlineGapColor = myInDesign.Swatches.Item("None")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.UnderlineGapOverprint = False
.UnderlineGapTint = 100
.UnderlineOffset = 3
.UnderlineOverprint = False
.UnderlineTint = 100
On Error Resume Next
.UnderlineType = myInDesign.StrokeStyles.Item("Solid")
If Err.Number <> 0 Then
Err.Clear
End If
On Error GoTo 0
.UnderlineWeight = 0.25
End If
.VerticalScale = 100
End With
テキストのフォーマット
107
第 6 章 テキストと組版
テキストのフォーマット
108
フォントの操作
InDesign アプリケーションオブジェクトのフォントコレクションには、InDesign で利用できるすべてのフォ
ントが含まれています。これとは対照的に、ドキュメントのフォントコレクションには、そのドキュメント
で使用されているフォントのみが含まれています。ドキュメントのフォントコレクションには、環境に無い
フォント(ドキュメントで使用されているが InDesign では利用できないフォント)も含まれます。アプリ
ケーションフォントとドキュメントフォントの違いを調べる方法を、次のスクリプトに示します (ここで
は、myGetBounds 関数は省略しています。完全なスクリプトについては、FontCollections を参照してくださ
い)
。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myApplicationFonts = myInDesign.Fonts
myString = "Document Fonts:" & vbCr
For myCounter = 1 To myDocument.Fonts.Count
myString = myString & myDocument.Fonts.Item(myCounter).Name & vbCr
Next
myString = myString & vbCr & "Application Fonts:" & vbCr
For myCounter = 1 To myInDesign.Fonts.Count
myString = myString & myInDesign.Fonts.Item(myCounter) & vbCr
Next
Set myTextFrame = myPage.TextFrames.Item(1)
Set myStory = myTextFrame.ParentStory
myStory.Contents = myString
注意 : フォント名は通常、familyName<tab>fontStyle という形式で示されます。familyName はフォントファ
ミリー名、<tab> はタブ文字、fontStyle はフォントスタイル名です。例えば、次のようになります。
"Adobe Caslon Pro<tab>Semibold Italic"
フォントの適用
テキストのある範囲にローカルフォントを適用するには、appliedFont プロパティを使用します。次のスク
リプトにその例を示します(チュートリアルスクリプトの ApplyFont より)。
Rem Given a font name "myFontName" and a text object "myText"...
myText.AppliedFont = myInDesign.Fonts.Item(myFontName)
また、次のスクリプトのように、フォントファミリー名とフォントスタイルを指定してフォントを適用する
こともできます。
myText.AppliedFont = myInDesign.Fonts.Item("Adobe Caslon Pro")
myText.FontStyle = "Semibold Italic"
第 6 章 テキストと組版
テキストのフォーマット
109
テキストプロパティの変更
InDesign のテキストオブジェクトには、そのフォーマット属性に対応する多数のプロパティが用意されてい
ます。単なる挿入点にも、テキストのフォーマットに影響を与える多数のプロパティ(その挿入点が含まれ
ている段落とほぼ同じプロパティ)が用意されています。SetTextProperties というチュートリアルスクリプト
には、テキストオブジェクトのすべてのプロパティを設定する方法が示されています。次のスクリプトにそ
の例を示します。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myTextObject = myStory.Characters.Item(1)
myFontName = "Minion Pro" & vbTab & "Regular"
With myTextObject
.AlignToBaseline = False
.AppliedCharacterStyle = myDocument.CharacterStyles.Item("[None]")
On Error Resume Next
.AppliedFont = myInDesign.Fonts.Item(myFontName)
.FontStyle = "Regular"
If Err.Number <> 0 Then
Err.Clear
End If
On Error Goto 0
.AppliedLanguage = myInDesign.LanguagesWithVendors.Item("English: USA")
.AppliedNumberingList = myDocument.NumberingLists.Item("[Default]")
.AppliedParagraphStyle = myDocument.ParagraphStyles.Item("[No Paragraph Style]")
.AutoLeading = 120
.BalanceRaggedLines = idBalanceLinesStyle.idNoBalancing
.BaselineShift = 0
.BulletsAlignment = idListAlignment.idLeftAlign
.BulletsAndNumberingListType = idListType.idNoList
.BulletsCharacterStyle = myDocument.CharacterStyles.Item("[None]")
.BulletsTextAfter = "^t"
.Capitalization = idCapitalization.idNormal
.Composer = "Adobe Paragraph Composer"
.DesiredGlyphScaling = 100
.DesiredLetterSpacing = 0
.DesiredWordSpacing = 100
.DropCapCharacters = 0
.DropCapLines = 0
.DropCapStyle = myDocument.CharacterStyles.Item("[None]")
.DropcapDetail = 0
.FillColor = myDocument.Colors.Item("Black")
.FillTint = -1
.FirstLineIndent = 0
.GradientFillAngle = 0
.GradientFillLength = -1
.GradientFillStart = Array(0, 0)
.GradientStrokeAngle = 0
.GradientStrokeLength = -1
.GradientStrokeStart = Array(0, 0)
.GridAlignFirstLineOnly = False
.HorizontalScale = 100
.HyphenWeight = 5
.HyphenateAcrossColumns = True
.HyphenateAfterFirst = 2
.HyphenateBeforeLast = 2
.HyphenateCapitalizedWords = True
.HyphenateLadderLimit = 3
.HyphenateLastWord = True
.HyphenateWordsLongerThan = 5
.Hyphenation = True
.HyphenationZone = 3
.IgnoreEdgeAlignment = False
第 6 章 テキストと組版
.Justification = idJustification.idLeftAlign
.KeepAllLinesTogether = False
.KeepFirstLines = 2
.KeepLastLines = 2
.KeepLinesTogether = False
.KeepRuleAboveInFrame = False
.KeepWithNext = 0
.KerningMethod = "Optical"
.LastLineIndent = 0
.Leading = 12
.LeftIndent = 0
.Ligatures = True
.MaximumGlyphScaling = 100
.MaximumLetterSpacing = 0
.MaximumWordSpacing = 133
.MinimumGlyphScaling = 100
.MinimumLetterSpacing = 0
.MinimumWordSpacing = 80
.NoBreak = False
.NumberingAlignment = idListAlignment.idLeftAlign
.NumberingApplyRestartPolicy = True
.NumberingCharacterStyle = myDocument.CharacterStyles.Item("[None]")
.NumberingContinue = True
.NumberingExpression = "^#.^t"
.NumberingFormat = "1, 2, 3, 4..."
.NumberingLevel = 1
.NumberingStartAt = 1
.OTFContextualAlternate = True
.OTFDiscretionaryLigature = False
.OTFFigureStyle = idOTFFigureStyle.idProportionalLining
.OTFFraction = False
.OTFHistorical = False
.OTFLocale = True
.OTFMark = True
.OTFOrdinal = False
.OTFSlashedZero = False
.OTFStylisticSets = 0
.OTFSwash = False
.OTFTitling = False
.OverprintFill = False
.OverprintStroke = False
.PointSize = 12
.Position = idPosition.idNormal
.PositionalForm = idPositionalForms.idNone
.RightIndent = 0
.RuleAbove = False
.RuleAboveColor = "Text Color"
.RuleAboveGapColor = myDocument.Swatches.Item("None")
.RuleAboveGapOverprint = False
.RuleAboveGapTint = -1
.RuleAboveLeftIndent = 0
.RuleAboveLineWeight = 1
.RuleAboveOffset = 0
.RuleAboveOverprint = False
.RuleAboveRightIndent = 0
.RuleAboveTint = -1
.RuleAboveType = myDocument.StrokeStyles.Item("Solid")
.RuleAboveWidth = idRuleWidth.idColumnWidth
.RuleBelow = False
.RuleBelowColor = "Text Color"
.RuleBelowGapColor = myDocument.Swatches.Item("None")
.RuleBelowGapOverprint = False
.RuleBelowGapTint = -1
.RuleBelowLeftIndent = 0
テキストのフォーマット
110
第 6 章 テキストと組版
テキストのフォーマット
111
.RuleBelowLineWeight = 1
.RuleBelowOffset = 0
.RuleBelowOverprint = False
.RuleBelowRightIndent = 0
.RuleBelowTint = -1
.RuleBelowType = myDocument.StrokeStyles.Item("Solid")
.RuleBelowWidth = idRuleWidth.idColumnWidth
.SingleWordJustification = idSingleWordJustification.idLeftAlign
.Skew = 0
.SpaceAfter = 0
.SpaceBefore = 0
.StartParagraph = idStartParagraph.idAnywhere
.StrikeThroughColor = "Text Color"
.StrikeThroughGapColor = myDocument.Swatches.Item("None")
.StrikeThroughGapOverprint = False
.StrikeThroughGapTint = -1
.StrikeThroughOffset = -9999
.StrikeThroughOverprint = False
.StrikeThroughTint = -1
.StrikeThroughType = myDocument.StrokeStyles.Item("Solid")
.StrikeThroughWeight = -9999
.StrikeThru = False
.StrokeColor = myDocument.Swatches.Item("None")
.StrokeTint = -1
.StrokeWeight = 1
.Tracking = 0
.Underline = False
.UnderlineColor = "Text Color"
.UnderlineGapColor = myDocument.Swatches.Item("None")
.UnderlineGapOverprint = False
.UnderlineGapTint = -1
.UnderlineOffset = -9999
.UnderlineOverprint = False
.UnderlineTint = -1
.UnderlineType = myDocument.StrokeStyles.Item("Solid")
.UnderlineWeight = -9999
.VerticalScale = 100
End With
テキストカラーの変更
テキスト文字の塗りと線にカラーを適用できます。次のスクリプトにその例を示します(チュートリアルス
クリプトの TextColors より)。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Rem Apply a color to the fill of the text.
Set myText = myStory.Paragraphs.Item(1)
myText.FillColor = myDocument.Colors.Item("DGC1_446a")
Rem Use the itemByRange method to apply the color to the stroke of the text.
myText.StrokeColor = myDocument.Swatches.Item("DGC1_446b")
Set myText = myStory.Paragraphs.Item(2)
myText.FillColor = myDocument.Swatches.Item("DGC1_446b")
myText.StrokeColor = myDocument.Swatches.Item("DGC1_446a")
myText.StrokeWeight = 3
第 6 章 テキストと組版
テキストのフォーマット
112
スタイルの作成と適用
前述のいくつかの例でローカルフォーマットを適用する方法を示しましたが、ここでは、文字スタイルや段
落スタイルを使用してテキストをフォーマットする方法について説明します。スタイルを使用すると、
フォーマットされたテキストとスタイルの間にリンクが作成されます。そのため、スタイルの再定義、特定
のスタイルでフォーマットされたテキストの収集、テキストの検索や変更などが簡単に行えます。段落スタ
イルや文字スタイルは、テキストのフォーマット作業を効率化する上で重要な役割を果たします。段落と文
字スタイルはテキストにフォーマットを設定する場合に生産性の鍵となるものであり、テキストにフォー
マットを適用するどんなスクリプトにとっても中心的な存在になるはずです。
段落スタイルや文字スタイルを作成して適用する方法を、次のスクリプトに示します(完全なスクリプトに
ついては、CreateStyles を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Create a color for use by one of the paragraph styles we'll create.
Set myColor = myAddColor(myDocument, "Red", idColorModel.idProcess,
Array(0, 100, 100, 0))
Rem Create a character style named "myCharacterStyle" if
Rem no style by that name already exists.
Set myCharacterStyle = myAddStyle(myDocument, "myCharacterStyle", 1)
Rem At this point, the variable myCharacterStyle contains a reference to a character
Rem style object, which you can now use to specify formatting.
myCharacterStyle.FillColor = myColor
Rem Create a paragraph style named "myParagraphStyle" if
Rem no style by that name already exists.
Set myParagraphStyle = myAddStyle(myDocument, "myParagraphStyle", 2)
Rem At this point, the variable myParagraphStyle contains a reference to a paragraph
Rem style object, which you can now use to specify formatting.
myTextFrame.ParentStory.Texts.Item(1).ApplyParagraphStyle myParagraphStyle, True
Set myStartCharacter = myTextFrame.ParentStory.Characters.Item(14)
Set myEndCharacter = myTextFrame.ParentStory.Characters.Item(55)
Set myText = myTextFrame.ParentStory.Texts.ItemByRange(myStartCharacter, myEndCharacter)
myText.Item(1).ApplyCharacterStyle myCharacterStyle, True
テキストオブジェクトの appliedParagraphStyle プロパティを使用せずに applyParagraphStyle メソッドを
使用する利点は、既存のフォーマットをオーバーライドできる点にあります。スタイルにプロパティを設定
しても、ローカルフォーマットは変更されずに保持されます。
新規ドキュメントの作成時に、スタイルが存在するかどうかを確認しているのは、アプリケーションのデ
フォルトスタイルとして同じ名前のスタイルが存在している可能性があるからです。その場合、同じ名前で
新しいスタイルを作成しようとするとエラーが発生します。
先頭文字スタイル(Nested Style)を使用すると、文字スタイルのフォーマットを特定のパターンに従って段
落に適用することができます。先頭文字スタイルを含む段落スタイルの作成方法を、次のスクリプトに示し
ます(完全なスクリプトについては、NestedStyles を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myParagraphStyle = myDocument.ParagraphStyles.Item("myParagraphStyle")
Rem At this point, the variable myParagraphStyle contains a reference to a paragraph
Rem style object, which you can now use to specify formatting.
Set myNestedStyle = myParagraphStyle.NestedStyles.Add
myNestedStyle.AppliedCharacterStyle = myDocument.CharacterStyles.Item("myCharacterStyle")
myNestedStyle.Delimiter = "."
myNestedStyle.Inclusive = True
myNestedStyle.Repetition = 1
Rem Note that the story object does not have the ApplyParagraphStyle method.)
Set myText = myPage.TextFrames.Item(1).ParentStory.Texts.Item(1)
myText.ApplyParagraphStyle myParagraphStyle, True
第 6 章 テキストと組版
テキストの検索と変更
113
スタイルの削除
ユーザーインターフェイスでスタイルを削除する際には、タグ付けされたスタイルでテキストのフォーマッ
ト方法を選択することができますが、InDesign スクリプティングでもこれと同じことが行えます。次のスク
リプトにその例を示します(チュートリアルスクリプトの RemoveStyle より)
。
Set myDocument = myInDesign.Documents.Item(1)
Set myParagraphStyleA = myDocument.ParagraphStyles.Item("myParagraphStyleA")
Rem Delete the paragraph style myParagraphStyleA and replace with myParagraphStyleB.
myParagraphStyleA.Delete myDocument.ParagraphStyles.Item("myParagraphStyleB")
段落スタイルや文字スタイルの読み込み
他の InDesign ドキュメントから文字スタイルや段落スタイルを読み込むことができます。次のスクリプトに
その例を示します(チュートリアルスクリプトの ImportTextStyles より)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myNewDocument = myInDesign.Documents.Add
Rem Import the styles from the saved document.
Rem ImportStyles parameters:
Rem Format as idImportFormat enumeration. Options for text styles are:
Rem idImportFormat.idParagraphStylesFormat
Rem idImportFormat.idCharacterStylesFormat
Rem idImportFormat.idTextStylesFormat
Rem From as string (file path)
Rem GlobalStrategy as idGlobalClashResolutionStrategy enumeration. Options are:
Rem idGlobalClashResolutionStrategy.idDoNotLoadTheStyle
Rem idGlobalClashResolutionStrategy.idLoadAllWithOverwrite
Rem idGlobalClashResolutionStrategy.idLoadAllWithRename
myNewDocument.ImportStyles idImportFormat.idTextStylesFormat, "c:¥styles.indd",
idGlobalClashResolutionStrategy.idLoadAllWithOverwrite
テキストの検索と変更
検索/変更機能は、テキストを操作するための最も強力なツールの 1 つであり、スクリプティングに完全に
対応しています。スクリプトを使用すれば、ユーザーインターフェイスではできないことも可能になります。
InDesign では、次の 3 つの方法でテキストを検索できます。

テキストやテキストフォーマットを検索して、別のテキストやテキストフォーマットに変更できます。
この場合は、findTextPreferences オブジェクトや changeTextPreferences オブジェクトを使用して、
findText メソッドや changeText メソッドのパラメーターを指定します。

正規表現を使用したテキスト検索(grep)を実行できます。この場合は、findGrepPreferences オブジェ
クトや changeGrepPreferences オブジェクトを使用して、findGrep メソッドや changeGrep メソッドのパ
ラメーターを指定します。

特定の字形(とそのフォーマット)を検索して、別の字形やフォーマットに置換できます。この場合は、
findGlyphPreferences オブジェクトや changeGlyphPreferences オブジェクトを使用して、findGlyph メ
ソッドや changeGlyph メソッドのパラメーターを指定します。
どの検索/変更メソッドにも、ReverseOrder という 1 つのオプションパラメーターがあります。このパラ
メーターで、検索結果を返す順序を指定できます。検索/変更操作の結果に基づいて、ストーリーのテキス
トを追加したり削除したりする場合は、この章の以前の節で説明したテキスト参照の問題に注意する必要が
あります。この問題が発生する場合は、返されたテキストオブジェクトのコレクションを逆順で処理するよ
うにループを設定するか、または、検索結果を逆順で返すように設定して、そのコレクションを通常の順序
で処理します。
第 6 章 テキストと組版
テキストの検索と変更
114
検索/変更の環境設定
テキストを検索する前に、検索/変更の環境設定を消去することで、前回の設定を引き継がないようにする
ことができます。また、必要に応じていくつかの検索/変更環境設定を指定して、対象となるテキスト、
フォーマット、正規表現、字形などを指定することができます。検索/変更操作を行う一般的な手順を次に
示します。
1.
検索/変更の環境設定を消去します。検索/変更操作の種類に応じて、次の 3 つのいずれかを行います。

Rem Find/Change text preferences
Set myInDesign = CreateObject("InDesign.Application")
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing

Rem Find/Change grep preferences
Set myInDesign = CreateObject("InDesign.Application")
myInDesign.FindGrepPreferences = idNothingEnum.idNothing
myInDesign.ChangeGrepPreferences = idNothingEnum.idNothing

Rem Find/Change glyph preferences
Set myInDesign = CreateObject("InDesign.Application")
myInDesign.FindGlyphPreferences = idNothingEnum.idNothing
myInDesign.ChangeGlyphPreferences = idNothingEnum.idNothing
2.
検索パラメーターを設定します。
3.
検索/変更操作を実行します。
4.
検索/変更の環境設定を再び消去します。
テキストの検索と変更
指定したテキスト文字列を検索する方法を、次のスクリプトに示します。このスクリプトではドキュメント
全体を検索していますが、ストーリー、テキストフレーム、段落、テキスト列などのテキストオブジェクト
を検索することもできます。findText メソッドとそのパラメーターは、すべてのテキストオブジェクトで共
通しています (完全なスクリプトについては、FindText を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Rem Clear the find/change text preferences.
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
Rem Search the document for the string "text".
myInDesign.FindTextPreferences.FindWhat = "text"
Rem Set the find options.
myInDesign.FindChangeTextOptions.CaseSensitive = False
myInDesign.FindChangeTextOptions.IncludeFootnotes = False
myInDesign.FindChangeTextOptions.IncludeHiddenLayers = False
myInDesign.FindChangeTextOptions.IncludeLockedLayersForFind = False
myInDesign.FindChangeTextOptions.IncludeLockedStoriesForFind = False
myInDesign.FindChangeTextOptions.IncludeMasterPages = False
myInDesign.FindChangeTextOptions.WholeWord = False
Set myFoundItems = myInDesign.Documents.Item(1).FindText
MsgBox ("Found " & CStr(myFoundItems.Count) & " instances of the search string.")
Rem Clear the find/change text preferences after the search.
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
指定したテキスト文字列を検索して別の文字列に置換する方法を、次のスクリプトに示します(完全なスク
リプトについては、ChangeText を参照してください)。
第 6 章 テキストと組版
テキストの検索と変更
115
Set myDocument = myInDesign.Documents.Item(1)
Rem Clear the find/change text preferences.
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
Rem Search the document for the string "copy" and replace with "text".
myInDesign.FindTextPreferences.FindWhat = "copy"
myInDesign.ChangeTextPreferences.ChangeTo = "text"
Rem Set the find options.
myInDesign.FindChangeTextOptions.CaseSensitive = False
myInDesign.FindChangeTextOptions.IncludeFootnotes = False
myInDesign.FindChangeTextOptions.IncludeHiddenLayers = False
myInDesign.FindChangeTextOptions.IncludeLockedLayersForFind = False
myInDesign.FindChangeTextOptions.IncludeLockedStoriesForFind = False
myInDesign.FindChangeTextOptions.IncludeMasterPages = False
myInDesign.FindChangeTextOptions.WholeWord = False
Set myFoundItems = myInDesign.Documents.Item(1).ChangeText
MsgBox ("Changed " & CStr(myFoundItems.Count) & " instances of the search string.")
Rem Clear the find/change text preferences.
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
テキストフォーマットの検索と変更
テキストフォーマットの検索や変更を行うには、findTextPreferences オブジェクトや
changeTextPreferences オブジェクトのその他のプロパティを設定します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの FindChangeFormatting より)。
Rem Clear the find/change preferences.
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
Rem Set the find options.
myInDesign.FindChangeTextOptions.CaseSensitive = false
myInDesign.FindChangeTextOptions.IncludeFootnotes = false
myInDesign.FindChangeTextOptions.IncludeHiddenLayers = false
myInDesign.FindChangeTextOptions.IncludeLockedLayersForFind = false
myInDesign.FindChangeTextOptions.IncludeLockedStoriesForFind = false
myInDesign.FindChangeTextOptions.IncludeMasterPages = false
myInDesign.FindChangeTextOptions.WholeWord = false
Rem Search the document for the 24 point text and change it to 10 point text.
myInDesign.findTextPreferences.pointSize = 24
myInDesign.changeTextPreferences.pointSize = 10
myInDesign.documents.item(1).changeText
Rem Clear the find/change preferences after the search.
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
grep の使用
InDesign の findGrep メソッドや changeGrep メソッドを使用すれば、正規表現を利用した検索/変更操作が
行えます。正規表現を利用した検索/変更操作では、指定したフォーマットのテキストを検索したり、テキ
ストのフォーマットを changeGrepPreferences オブジェクトのプロパティで指定したフォーマットに置換す
ることができます。これらのメソッドや関係する環境設定オブジェクトの使用方法を、次のスクリプトに示
します(完全なスクリプトについては、FindGrep を参照してください)。
第 6 章 テキストと組版
テキストの検索と変更
116
Set myDocument = myInDesign.Documents.Item(1)
Rem Clear the find/change grep preferences.
myInDesign.FindGrepPreferences = idNothingEnum.idNothing
myInDesign.ChangeGrepPreferences = idNothingEnum.idNothing
Rem Set the find options.
myInDesign.FindChangeGrepOptions.IncludeFootnotes = False
myInDesign.FindChangeGrepOptions.IncludeHiddenLayers = False
myInDesign.FindChangeGrepOptions.IncludeLockedLayersForFind = False
myInDesign.FindChangeGrepOptions.IncludeLockedStoriesForFind = False
myInDesign.FindChangeGrepOptions.IncludeMasterPages = False
Rem Regular expression for finding an email address.
myInDesign.FindGrepPreferences.FindWhat = "(?i)[A-Z]*?@[A-Z]*?[.]..."
Rem Apply the change to 24-point text only.
myInDesign.FindGrepPreferences.PointSize = 24
myInDesign.ChangeGrepPreferences.Underline = True
myDocument.ChangeGrep
Rem Clear the find/change grep preferences after the search.
myInDesign.FindGrepPreferences = idNothingEnum.idNothing
myInDesign.ChangeGrepPreferences = idNothingEnum.idNothing
注意 : findChangeTextOptions オブジェクトで使用できる wholeWord と caseSensitive の 2 つのプロパティ
は、findChangeGrepOptions オブジェクトでは使用できません。これは、正規表現の文字列で同等のオプショ
ンを表現できるからです。大文字と小文字を区別しない場合は (?i) を使用し、区別する場合は (?-i) を使用
します。単語の先頭に一致するには ¥> を使用し、単語の末尾に一致するには ¥< を使用し、単語の境界に一致
するには ¥b を使用します。
grep 検索/変更の利用例として、マークアップテキスト(タグでフォーマットが指定されているプレーンテ
キスト)を InDesign 形式のテキストに変換する処理があります。簡単なテキストマークアップスキームとし
ては、PageMaker の段落タグがあります(これは、PageMaker のタグ付きテキスト形式のファイルとは異な
ります)
。このスキームでマークアップされたテキストファイルでは、次のように、段落スタイルの名前が段
落の先頭に示されます。
<heading1>This is a heading.
<body_text>This is body text.
grep 検索とテキスト検索/変更を組み合わせれば、テキストにフォーマットを適用して、マークアップタグ
を削除することができます。次のスクリプトにその例を示します(チュートリアルスクリプトの ReadPMTags
より)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Access the active document.
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
myReadPMTags myInDesign, myStory
このスクリプトで参照されている myReadPMTags 関数を次に示します。
Function myReadPMTags(myInDesign, myStory)
Set myDocument = myStory.Parent
Rem Reset the findGrepPreferences to ensure that previous settings
Rem do not affect the search.
myInDesign.FindGrepPreferences = idNothingEnum.idNothing
myInDesign.ChangeGrepPreferences = idNothingEnum.idNothing
Rem Find the tags.
myInDesign.FindGrepPreferences.findWhat = "(?i)^<¥s*¥w+¥s*>"
Set myFoundItems = myStory.findGrep
If myFoundItems.Count <> 0 Then
Set myFoundTags = CreateObject("Scripting.Dictionary")
For myCounter = 1 To myFoundItems.Count
If Not (myFoundTags.Exists(myFoundItems.Item(myCounter).Contents)) Then
myFoundTags.Add myFoundItems.Item(myCounter).Contents,
myFoundItems.Item(myCounter).Contents
End If
Next
Rem At this point, we have a list of tags to search for.
第 6 章 テキストと組版
テキストの検索と変更
117
For Each myFoundTag In myFoundTags
myString = myFoundTag
Rem Find the tag using findWhat.
myInDesign.FindTextPreferences.findWhat = myString
Rem Extract the style name from the tag.
myStyleName = Mid(myString, 2, Len(myString) - 2)
Rem Create the style if it does not already exist.
Set myStyle = myAddStyle(myDocument, myStyleName)
Rem Apply the style to each instance of the tag.
myInDesign.ChangeTextPreferences.AppliedParagraphStyle = myStyle
myStory.ChangeText
Rem Reset the changeTextPreferences.
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
Rem Set the changeTo to an empty string.
myInDesign.ChangeTextPreferences.ChangeTo = ""
Rem Search to remove the tags.
myStory.ChangeText
Rem Reset the find/change preferences again.
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
Next
End If
myInDesign.FindGrepPreferences = idNothingEnum.idNothing
myInDesign.ChangeGrepPreferences = idNothingEnum.idNothing
End Function
字形検索の使用
特定のフォントに含まれている個々の文字を検索/変更するには、findGlyph メソッドや changeGlyph メ
ソッドを使用します。パラメーターは findGlyphPreferences オブジェクトや changeGlyphPreferences オブ
ジェクトで設定します。次のスクリプトでは、サンプルドキュメントの中で字形を検索し、変更しています
(完全なスクリプトについては、FindChangeGlyph を参照してください)。
Rem Clear the find/change glyph preferences.
myInDesign.FindGlyphPreferences = idNothingEnum.idNothing
myInDesign.ChangeGlyphPreferences = idNothingEnum.idNothing
Rem Set the find options.
myInDesign.FindChangeGrepOptions.IncludeFootnotes = False
myInDesign.FindChangeGrepOptions.IncludeHiddenLayers = False
myInDesign.FindChangeGrepOptions.IncludeLockedLayersForFind = False
myInDesign.FindChangeGrepOptions.IncludeLockedStoriesForFind = False
myInDesign.FindChangeGrepOptions.IncludeMasterPages = False
Rem You must provide a font that is used in the document for the
Rem AppliedFont property of the FindGlyphPreferences object.
myInDesign.FindGlyphPreferences.AppliedFont = myInDesign.Fonts.Item("Minion Pro" & vbTab &
"Regular")
Rem Provide the glyph ID, not the glyph Unicode value.
myInDesign.FindGlyphPreferences.GlyphID = 374
Rem The appliedFont of the changeGlyphPreferences object can be
Rem any font available to the application.
myInDesign.changeGlyphPreferences.AppliedFont = myInDesign.Fonts.Item("Times New Roman" & vbTab &
"Bold")
myInDesign.changeGlyphPreferences.GlyphID = 85
myInDesign.Documents.Item(1).ChangeGlyph
Rem Clear the find/change glyph preferences after the search.
myInDesign.FindGlyphPreferences = idNothingEnum.idNothing
myInDesign.ChangeGlyphPreferences = idNothingEnum.idNothing
第 6 章 テキストと組版
表の操作
118
表の操作
convertTextToTable メソッドを使用して、既存のテキストから表を作成したり、ストーリー内の任意の挿入
点に空の表を作成することができます。次のスクリプトでは、3 つの異なる方法で表を作成しています(完全
なスクリプトについては、MakeTable を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Add
Rem Set the bounds of the text frame.
myTextFrame.GeometricBounds = myGetBounds(myDocument, myPage)
Rem Fill the text frame with placeholder text.
myString = "Table 1" & vbCr
myString = myString & "Column 1" & vbTab & "Column 2" & vbTab & "Column 3" & vbCr & "1a" & vbTab &
"1b" & vbTab & "1c" & vbCr & "2a" & vbTab & "2b" & vbTab & "2c" & vbCr & "3a" & vbTab & "3b" & vbTab
& "3c" & vbCr
myString = myString & "Table 2" & vbCr
myString = myString & "Column 1,Column 2,Column 3;1a,1b,1c;2a,2b,2c;3a,3b,3c" & vbCr
myString = myString & "Table 3" & vbCr
myTextFrame.Contents = myString
Set myStory = myTextFrame.ParentStory
Set myStartCharacter = myStory.Paragraphs.Item(7).Characters.Item(1)
Set myEndCharacter = myStory.Paragraphs.Item(7).Characters.Item(-2)
Set myText = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
Rem The convertToTable method takes three parameters:
Rem [ColumnSeparator as string]
Rem [RowSeparator as string]
Rem [NumberOfColumns as integer] (only used if the ColumnSeparator
Rem and RowSeparator values are the same)
Rem In the last paragraph in the story, columns are separated by commas
Rem and rows are separated by semicolons, so we provide those characters
Rem to the method as parameters.
Set myTable = myText.ConvertToTable(",", ";")
Set myStartCharacter = myStory.Paragraphs.Item(2).Characters.Item(1)
Set myEndCharacter = myStory.Paragraphs.Item(5).Characters.Item(-2)
Set myText = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
Rem In the second through the fifth paragraphs, colums are separated by
Rem tabs and rows are separated by returns. These are the default delimiter
Rem parameters, so we don't need to provide them to the method.
Set myTable = myText.ConvertToTable
Rem You can also explicitly add a table--you don't have to convert text to a table.
Set myTable = myStory.InsertionPoints.Item(-1).Tables.Add
myTable.ColumnCount = 3
myTable.BodyRowCount = 3
表セルの結合方法を、次のスクリプトに示します (完全なスクリプトについては、MergeTableCells を参照し
てください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myTable = myStory.Tables.Item(1)
Rem Merge all of the cells in the first column.
myTable.Cells.Item(1).Merge myTable.Columns.Item(1).Cells.Item(-1)
Rem Convert column 2 into 2 cells (rather than 4).
myTable.Columns.Item(2).Cells.Item(-1).Merge myTable.Columns.Item(2).Cells.Item(-2)
myTable.Columns.Item(2).Cells.Item(1).Merge myTable.Columns.Item(2).Cells.Item(2)
Rem Merge the last two cells in row 1.
myTable.Rows.Item(1).Cells.Item(-1).Merge myTable.Rows.Item(1).Cells.Item(-1)
Rem Merge the last two cells in row 3.
myTable.Rows.Item(3).Cells.Item(-2).Merge myTable.Rows.Item(3).Cells.Item(-1)
表セルの分割方法を、次のスクリプトに示します (完全なスクリプトについては、SplitTableCells を参照して
ください)
。
第 6 章 テキストと組版
表の操作
119
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myTable = myStory.InsertionPoints.Item(-1).Tables.Add
myTable.ColumnCount = 1
myTable.BodyRowCount = 1
myArray = myGetBounds(myDocument, myDocument.Pages.Item(1))
myWidth = myArray(3) - myArray(1)
myTable.Columns.Item(1).Width = myWidth
myTable.Cells.Item(1).Split idHorizontalOrVertical.idHorizontal
myTable.Columns.Item(1).Split idHorizontalOrVertical.idVertical
myTable.Cells.Item(1).Split idHorizontalOrVertical.idVertical
myTable.Rows.Item(-1).Split idHorizontalOrVertical.idHorizontal
myTable.Cells.Item(-1).Split idHorizontalOrVertical.idVertical
For myRowCounter = 1 To myTable.Rows.Count
Set myRow = myTable.Rows.Item(myRowCounter)
For myCellCounter = 1 To myRow.Cells.Count
myString = "Row: " & myRowCounter & " Cell: " & myCellCounter
myRow.Cells.Item(myCellCounter).contents = myString
Next
Next
表にヘッダー行とフッター行を作成する方法を、次のスクリプトに示します(完全なスクリプトについては、
HeaderAndFooterRows を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Rem Create a text frame on page 1.
Set myTable = myDocument.Stories.Item(1).Tables.Item(1)
Rem Convert the first row to a header row.
myTable.Rows.Item(1).RowType = idRowTypes.idHeaderRow
Rem Convert the last row to a footer row.
myTable.Rows.Item(-1).RowType = idRowTypes.idFooterRow
表にフォーマットを適用する方法を、次のスクリプトに示します(完全なスクリプトについては、
TableFormatting を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myTable = myStory.Tables.Item(1)
Rem Convert the first row to a header row.
myTable.Rows.Item(1).RowType = idRowTypes.idHeaderRow
Rem Use a reference to a swatch, rather than to a color.
myTable.Rows.Item(1).FillColor = myDocument.Swatches.Item("DGC1_446b")
myTable.Rows.Item(1).FillTint = 40
myTable.Rows.Item(2).FillColor = myDocument.Swatches.Item("DGC1_446a")
myTable.Rows.Item(2).FillTint = 40
myTable.Rows.Item(3).FillColor = myDocument.Swatches.Item("DGC1_446a")
myTable.Rows.Item(3).FillTint = 20
myTable.Rows.Item(4).FillColor = myDocument.Swatches.Item("DGC1_446a")
myTable.Rows.Item(4).FillTint = 40
Rem Iterate through the cells to apply the cell stroke formatting.
For myCounter = 1 To myTable.Cells.Count
第 6 章 テキストと組版
表の操作
120
myTable.Cells.Item(myCounter).TopEdgeStrokeColor =
myDocument.Swatches.Item("DGC1_446b")
myTable.Cells.Item(myCounter).TopEdgeStrokeWeight = 1
myTable.Cells.Item(myCounter).BottomEdgeStrokeColor =
myDocument.Swatches.Item("DGC1_446b")
myTable.Cells.Item(myCounter).BottomEdgeStrokeWeight = 1
Rem When you set a cell stroke to a swatch, make certain that
Remyou also set the stroke weight.
myTable.Cells.Item(myCounter).LeftEdgeStrokeColor =
myDocument.Swatches.Item("None")
myTable.Cells.Item(myCounter).LeftEdgeStrokeWeight = 0
myTable.Cells.Item(myCounter).RightEdgeStrokeColor =
myDocument.Swatches.Item("None")
myTable.Cells.Item(myCounter).RightEdgeStrokeWeight = 0
Next
表に反復行フォーマットを追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
AlternatingRows を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myTable = myDocument.stories.Item(1).tables.Item(1)
Rem Apply alternating fills to the table.
myTable.alternatingFills = idAlternatingFillsTypes.idAlternatingRows
myTable.startRowFillColor = myDocument.swatches.Item("DGC1_446a")
myTable.startRowFillTint = 60
myTable.endRowFillColor = myDocument.swatches.Item("DGC1_446b")
myTable.endRowFillTint = 50
テキストや表セルが選択されている場合の選択の処理方法を、次のスクリプトに示します。このスクリプト
では、選択状況に応じて警告を表示していますが、実際のスクリプトでは選択されているアイテムに応じて
何らかの操作を行うことになります (完全なスクリプトについては、TableSelection を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count <> 0 Then
If myInDesign.Selection.Count <> 0 Then
Select Case TypeName(myInDesign.Selection.Item(1))
Rem When a row, a column, or a range of cells is selected,
Rem the type returned is "Cell"
Case "Cell"
MsgBox ("A cell is selected.")
Case "Table"
MsgBox ("A table is selected.")
Case "InsertionPoint", "Character", "Word", "TextStyleRange",
"Line", "Paragraph", "TextColumn", "Text"
If TypeName(myInDesign.Selection.Item(1).Parent) = "Cell" Then
MsgBox ("The selection is inside a table cell.")
End If
Case "Rectangle", "Oval", "Polygon", "GraphicLine"
If TypeName(myInDesign.Selection.Item(1).Parent.Parent) = "Cell" Then
MsgBox ("The selection is inside a table cell.")
End If
Case "Image", "PDF", "EPS"
If TypeName(myInDesign.Selection.Item(1).Parent.Parent.Parent) =
"Cell" Then
MsgBox ("The selection is inside a table cell.")
End If
Case Else
MsgBox ("The selection is not inside a table.")
End Select
End If
End If
第 6 章 テキストと組版
パステキストの追加
121
パステキストの追加
パステキストは、長方形、楕円形、多角形、グラフィックの線、テキストフレームに追加できます。ページ
アイテムにパステキストを追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
PathText を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Rem Create a rectangle on the first page.
Set myTextFrame = myPage.TextFrames.Add
myTextFrame.geometricBounds = Array(72, 72, 288, 288)
Set myTextPath = myTextFrame.TextPaths.Add
myTextPath.Contents = "This is path text."
テキストパスを別のテキストパスやテキストフレームにリンクするには、nextTextFrame プロパティや
previousTextFrame プロパティを使用します。これは、テキストフレームのリンクの場合と同じです
。
(100 ページの「テキストフレームの操作」を参照)
自動修正の使用
自動修正機能を使用すると、テキストが入力されたときにテキストを自動的に修正することができます。次
のスクリプトにその例を示します(完全なスクリプトについては、Autocorrect を参照してください)。
ReDim myNewWordPairList(0)
Rem Add a word pair to the autocorrect list. Each
Rem AutoCorrectTable is linked to a specific language.
Set myAutoCorrectTable = myInDesign.AutoCorrectTables.Item("English: USA")
Rem To safely add a word pair to the auto correct table, get the current
Rem word pair list, then add the new word pair to that array, and then
Rem set the autocorrect word pair list to the array.
myWordPairList = myAutoCorrectTable.AutoCorrectWordPairList
ReDim myNewWordPairList(UBound(myWordPairList)+1)
For myCounter = 0 To UBound(myWordPairList)
myNewWordPairList(myCounter) = myWordPairList(myCounter)
Next
Rem Add a new word pair to the array.
myNewWordPairList(UBound(myNewWordPairList)) = (Array("paragarph", "paragraph"))
Rem Update the word pair list.
myAutoCorrectTable.AutoCorrectWordPairList = myNewWordPairList
Rem To clear all autocorrect word pairs in the current dictionary:
Rem myAutoCorrectTable.autoCorrectWordPairList = array(())
Rem Turn autocorrect on if it's not on already.
If myInDesign.AutoCorrectPreferences.AutoCorrect = False Then
myInDesign.AutoCorrectPreferences.AutoCorrect = True
End If
myInDesign.AutoCorrectPreferences.AutoCorrectCapitalizationErrors = True
第 6 章 テキストと組版
脚注の追加
122
脚注の追加
ストーリーに脚注を追加する方法を、次のスクリプトに示します(myGetRandom 関数を含む完全なスクリプ
トについては、Footnotes を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
With myDocument.FootnoteOptions
.SeparatorText = vbTab
.MarkerPositioning = idFootnoteMarkerPositioning.idSuperscriptMarker
End With
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Item(1)
Rem Add four footnotes at random locations in the story.
For myCounter = 1 To 4
myRandomNumber = CLng(myGetRandom(1, myTextFrame.ParentStory.Words.Count))
Set myWord = myTextFrame.ParentStory.Words.Item(myRandomNumber)
Set myFootnote = myWord.InsertionPoints.Item(-1).Footnotes.Add
Rem Note: when you create a footnote, it contains text--the footnote marker
Rem and the separator text (if any). If you try to set the text of the footnote
Rem by setting the footnote contents, you will delete the marker. Instead, append
Rem the footnote text, as shown below.
myFootnote.InsertionPoints.Item(-1).Contents = "This is a footnote."
Next
段抜きと段分割
段抜きや段分割の属性を適用して、段落のレイアウトを複数の段にまたがるようにしたり、段を分割したり
することができます。段落の段抜きおよび段分割のスタイルを設定する方法を、次のスクリプトに示します
(完全なスクリプトについては、SpanColumns を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.ActiveDocument
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
myTextFrame.TextFramePreferences.TextColumnCount = 3
Set myStory = myTextFrame.ParentStory
Rem Split Column
With myStory.Paragraphs.Item(1)
.SpanColumnType = idSpanColumnTypeOptions.idSplitColumns
.SpanSplitColumnCount = 2
.SplitColumnOutsideGutter = 0
.SplitColumnInsideGutter = 1
End With
Rem Span Columns
mySpanIndex = myStory.Paragraphs.Count ¥ 2 + 1
With myStory.Paragraphs.Item(mySpanIndex)
.SpanColumnType = idSpanColumnTypeOptions.idSpanColumns
.SpanSplitColumnCount = idSpanColumnCountOptions.idAll
End With
第 6 章 テキストと組版
テキスト環境設定の指定
テキスト環境設定の指定
一般的なテキスト環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについては、
TextPreferences を参照してください)。
With myInDesign.TextPreferences
.AbutTextToTextWrap = True
.AddPages = idAddPageOptions.idEndOfDocument
Rem baseline shift key increment can range from .001 to 200 points.
.BaselineShiftKeyIncrement = 1
.DeleteEmptyPages = False
.EnableStylePreviewMode = False
.HighlightCustomSpacing = False
.HighlightHjViolations = True
.HighlightKeeps = True
.HighlightSubstitutedFonts = True
.HighlightSubstitutedGlyphs = True
.JustifyTextWraps = True
Rem kerning key increment value is 1/1000 of an em.
.KerningKeyIncrement = 10
Rem leading key increment value can range from .001 to 200 points.
.LeadingKeyIncrement = 1
.LimitToMasterTextFrames = False
.LinkTextFilesWhenImporting = False
.PreserveFacingPageSpreads = False
.ShowInvisibles = True
.SmallCap = 60
.SmartTextReflow = False
.SubscriptPosition = 30
.SubscriptSize = 60
.SuperscriptPosition = 30
.SuperscriptSize = 60
.TypographersQuotes = False
.UseOpticalSize = False
.UseParagraphLeading = False
.ZOrderTextWrap = False
End With
Rem Text editing preferences are application-wide.
With myInDesign.TextEditingPreferences
.AllowDragAndDropTextInStory = True
.DragAndDropTextInLayout = True
.SingleClickConvertsFramesToTextFrames = True
.SmartCutAndPaste = True
.TripleClickSelectsLine = False
End With
123
第 6 章 テキストと組版
リンクストーリーの操作
124
リンクストーリーの操作
リンクストーリーを使用すると、1 つのドキュメントに含まれる同一のストーリーまたはテキストコンテン
ツの複数のバージョンを簡単に管理することができます。これにより、例えば縦組みと横組みの両方のレイ
アウト用のデザインが必要になるといった、新たなデジタルパブリッシングワークフローへの対応が容易に
なります。リンクストーリーは、一般的なリンクと同じように動作します。ストーリーを親として指定し、同
じストーリーをドキュメント内の別の場所に子ストーリーとして配置できます。親ストーリーを更新すると
リンクパネル内で子ストーリーにフラグが付くので、子ストーリーを更新して親ストーリーに同期させるこ
とができます。
リンクストーリーの作成
リンクストーリーは複数の方法で作成できます。既存のテキストフレームを親ストーリーにリンクする方法
と、指定した場所にテキストフレームを作成して親ストーリーにリンクするよう Page オブジェクト、Spread
オブジェクト、Master オブジェクトまたは Document オブジェクトに対して指示する方法があります。
既存のテキストフレームを親ストーリーにリンクするには、次のスクリプトを使用します(完全なスクリプ
トについては、CreateLinkedStories を参照してください)。
childTextFrame1.PlaceAndLink myTextFrame.ParentStory, False
2 つ目のパラメーターに true を指定すると(オプション)、リンクストーリーのオプションダイアログボック
スが表示されます。指定しなかった場合は、デフォルトのオプションが使用されます。
親ストーリーのリンクストーリーの作成を Page オブジェクトに対して指示するために、PlaceAndLink メソッ
ドには 2 つのパラメーターが用意されており、これらのパラメーターでリンクストーリーを配置するレイ
ヤーと位置を指定できます。次のスクリプトにその例を示します(完全なスクリプトについては、
CreateLinkedStories を参照してください)。
Set newPage = myDocument.Pages.Add
newPage.PlaceAndLink myTextFrame.ParentStory, Array(originY, originX), myDocument.ActiveLayer,
False
親ストーリーのリンクストーリーの作成を Spread オブジェクトに対して指示する場合、PlaceAndLink メソッ
ドでは Page オブジェクトの PlaceAndLink メソッドと同じパラメーターを取ります。次のスクリプトにその例
を示します(完全なスクリプトについては、CreateLinkedStories を参照してください)。
Set newSpread = myDocument.Spreads.Add
newSpread.PlaceAndLink myTextFrame.ParentStory, Array(originY, originX), myDocument.ActiveLayer,
False
また、PlaceAndLink メソッドを Document オブジェクトで呼び出すことも可能です。このメソッドは親ストー
リーを唯一のパラメーターとして取ります。このメソッドではリンクストーリーは作成されませんが、プ
レースガンが読み込まれるので、ユーザーがリンクストーリーの場所を自分で決めることができます。
リンクストーリーのオプションの変更
リンクストーリーのオプションを変更するには、次のスクリプトを使用します(完全なスクリプトについて
は、CreateLinkedStories を参照してください)。
With myDocument.LinkedStoryOptions
.RemoveForcedLineBreaks = True
.UpdateWhileSaving = True
.WarnOnUpdateOfEditedStory = True
End With
第 6 章 テキストと組版
リンクストーリーの操作
125
よくある質問
特定のリンクがリンクストーリーのリンクであるかどうかは、どのように判断す
ることができますか?
Link.FilePath を使用します。これが空の場合、そのリンクはリンクストーリーのリンクです。
リンクストーリーのリンクでは、リンクソースをどのような方法で取得できます
か?
次のスクリプトを使用して、リンクソースを選択します。
Link.EditOriginal
次に、次のスクリプトでアクティブな選択を検出します。これがリンクソースです。
Application.Selection
7
ユーザーインターフェイス
章の更新ステータス
CS6
変更なし
VBScript で作成できるダイアログボックスは、「はい」か「いいえ」で答えられる単純な質問をするためのダ
イアログボックスか、テキストを入力するためのダイアログボックスに限られていますが、より複雑なダイ
アログボックスを使用したいこともあります。InDesign スクリプティングを使用すれば、ポップアップリス
ト、テキスト入力フィールド、数値入力フィールドなどの一般的なユーザーインターフェイスコントロール
を備えたダイアログボックスを作成できます。ユーザー(または自分)から情報を受け取って、それに基づ
いて処理を実行したい場合は、dialog オブジェクトが役に立ちます。
この章では、InDesign のダイアログボックスを使用したスクリプトについて説明します。最初は簡単なサン
プルスクリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
注意 : JavaScript で InDesign スクリプトを作成する場合は、Adobe ScriptUI コンポーネントを使用してユー
ザーインターフェイスを作成することもできます。この章には、ScriptUI スクリプティングのチュートリアル
も含まれています。詳しくは、『Adobe JavaScript Tools Guide』を参照してください。
注意 : Visual Basic アプリケーションでは非常に複雑なユーザーインターフェイスが作成できますが、このイ
ンターフェイスは独立した Visual Basic 実行可能ファイルとして実行しなければなりません。InDesign スクリ
プティングには、InDesign の標準ユーザーインターフェイスによく似た外観を持つ複雑なダイアログボック
スを作成して、InDesign の中に表示する機能が用意されています。VBScript は、外部アプリケーションから実
行するよりも、スクリプトパレットから実行するほうが実行速度が速くなります。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成して実行する方法を理解しているものとして説明を行います。
ダイアログボックスの概要
InDesign のダイアログボックスは、InDesign の他のスクリプティングオブジェクトと同じく、1 つのオブジェ
クトです。次の図に示すように、ダイアログボックスには様々な要素(「ウィジェット」と呼ばれます)を含
めることができます。この図に示されている各要素について、この図の次の表で説明します。
126
第 7 章 ユーザーインターフェイス
ダイアログボックスの概要
dialog
127
dialog column
static text
border panel
checkbox control
radiobutton group
radiobutton control
measurement editbox
dropdown
ダイアログボックスの要素
InDesign での名前
テキスト編集フィールド
Text editbox control
数値入力フィールド
Real editbox, integer editbox, measurement editbox,
percent editbox, angle editbox
ポップアップメニュー
Drop-down control
テキスト編集フィールドとポップアップメニューを
組み合わせたコントロール
Combo-box control
チェックボックス
Check-box control
ラジオボタン
Radio-button control
これらのコントロールは、dialog オブジェクトに直接格納されるのではなく、DialogColumn というオブジェ
クトに格納されます。DialogColumn を使用することで、ダイアログボックス内のコントロールの位置を制御
することができます。DialogColumn の中に、別の DialogColumn や BorderPanel を含めて、ダイアログボック
スをさらに細かく分割することができます(必要に応じて、DialogColumn や BorderPanel の中に別の
DialogColumn や BorderPanel を順次含めていくことができます)
。
InDesign の他のスクリプティングオブジェクトと同じように、ダイアログボックスの各パーツにも固有のプ
ロパティがあります。例えば、CheckboxControl には、表示されるテキストを表すプロパティ(StaticLabel)
や、コントロールの状態を表すプロパティ(CheckedState)があります。また、Dropdown コントロールには、
メニューに表示されるオプションのリストを表すプロパティ(StringList)があります。
スクリプトの中でダイアログボックスを使用するには、まず dialog オブジェクトを作成し、そこに様々なコ
ントロールを配置して、ダイアログボックスを表示します。そして、スクリプトの処理に必要な値をそれら
のコントロールから収集します。ダイアログボックスは、破棄されるまで InDesign のメモリ内に維持されま
す。したがって、ダイアログボックスをメモリ内に保持しておき、そのプロパティに保存されているデータ
を複数のスクリプトで使用することが可能です。ただし、ダイアログボックスを保持するためにメモリが消
費されるので、必要がなくなったら破棄するようにしてください。一般的には、スクリプトが処理を終了す
る前にダイアログボックスオブジェクトを破棄します。
第 7 章 ユーザーインターフェイス
最初の InDesign ダイアログボックスの作成
128
最初の InDesign ダイアログボックスの作成
InDesign ダイアログボックスは、簡単な手順で作成できます。ダイアログボックスを追加し、ダイアログ
ボックスにダイアログコラムを追加し、ダイアログコラムにコントロールを追加します。次のスクリプトに
その例を示します(完全なスクリプトについては、SimpleDialog を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDialog = myInDesign.Dialogs.Add
Rem Add a dialog column.
With myDialog.DialogColumns.Add
With .StaticTexts.Add
.StaticLabel = "This is a very simple dialog box."
End With
End With
Rem Show the dialog box.
myResult = myDialog.Show
Rem If the user clicked OK, display one message;
Rem if they clicked Cancel, display a different message.
If myResult = True Then
MsgBox("You clicked the OK button!")
Else
MsgBox("You clicked the Cancel button!")
End If
Rem Remove the dialog from memory.
myDialog.Destroy
「Hello World」へのユーザーインターフェイスの追加
次の例は、
『Adobe InDesign スクリプティングチュートリアル』で作成した Hello World チュートリアルスク
リプトに、簡単なユーザーインターフェイスを追加したものです。ダイアログボックスに表示されるオプ
ションを使用して、表示するテキストを指定したり、テキストのポイントサイズを変更したりすることがで
きます。
Function myDisplayDialog(myInDesign)
Set myDialog = myInDesign.Dialogs.Add
myDialog.CanCancel = True
myDialog.Name = "Simple User Interface Example Script"
Set myDialogColumn = myDialog.DialogColumns.Add
Set myTextEditField = myDialogColumn.TextEditboxes.Add
myTextEditField.EditContents = "Hello World!"
myTextEditField.MinWidth = 180
Rem Create a number (real) entry field.
Set myPointSizeField = myDialogColumn.measurementEditboxes.Add
myPointSizeField.EditValue = 72
myResult = myDialog.Show
If myResult = True Then
Rem Get the values from the dialog box controls.
myString = myTextEditField.EditContents
myPointSize = myPointSizeField.EditValue
Rem Remove the dialog box from memory.
myDialog.Destroy
myMakeDocument(myInDesign, myString, myPointSize)
Else
myDialog.Destroy
End If
End Function
このスクリプトで参照されている myMakeDocument 関数を次に示します。
第 7 章 ユーザーインターフェイス
さらに複雑なユーザーインターフェイスの作成
129
Function myMakeDocument(myInDesign, myString, myPointSize)
Set myDocument = myInDesign.Documents.Add
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
Rem Resize the text frame to the "live" area of the page
Rem (using the function "myGetBounds").
myBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
myTextFrame.GeometricBounds = myBounds
Rem Enter the text from the dialog box in the text frame.
myTextFrame.Contents = myString
Rem Set the size of the text to the size you entered in the dialog box.
myTextFrame.Texts.Item(1).PointSize = myPointSize
End Function
さらに複雑なユーザーインターフェイスの作成
次の例では、様々なコントロールをサンプルダイアログボックスに追加します。この例では、次のようなダ
イアログボックスが作成されます。
完全なスクリプトについては、ComplexUI を参照してください。
Set myDialog = myInDesign.Dialogs.Add
myDialog.CanCancel = True
myDialog.Name = "User Interface Example Script"
Rem Create a dialog column.
Set myDialogColumn = myDialog.DialogColumns.Add
Rem Create a border panel.
Set myBorderPanel = myDialogColumn.BorderPanels.Add
Rem Create a dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myStaticText = myTempDialogColumn.StaticTexts.Add
myStaticText.StaticLabel = "Message:"
Rem Create another dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myTextEditField = myTempDialogColumn.TextEditboxes.Add
myTextEditField.EditContents = "Hello World!"
myTextEditField.MinWidth = 180
Rem Create another border panel.
Set myBorderPanel = myDialogColumn.BorderPanels.Add
Rem Create a dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myStaticText = myTempDialogColumn.StaticTexts.Add
myStaticText.StaticLabel = "Point Size:"
Rem Create another dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myPointSizeField = myTempDialogColumn.RealEditboxes.Add
myPointSizeField.EditValue = 72
Rem Create another border panel.
Set myBorderPanel = myDialogColumn.BorderPanels.Add
Rem Create a dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myStaticText = myTempDialogColumn.StaticTexts.Add
第 7 章 ユーザーインターフェイス
さらに複雑なユーザーインターフェイスの作成
myStaticText.StaticLabel = "Vertical Justification:"
Rem Create another dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myVerticalJustificationMenu = myTempDialogColumn.Dropdowns.Add
myVerticalJustificationMenu.StringList = Array("Top", "Center", "Bottom")
myVerticalJustificationMenu.SelectedIndex = 0
Rem Create another border panel.
Set myBorderPanel = myDialogColumn.BorderPanels.Add
Rem Create a dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myStaticText = myTempDialogColumn.StaticTexts.Add
myStaticText.StaticLabel = "Paragraph Alignment:"
Rem Create another dialog column inside the border panel.
Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
Set myRadioButtonGroup = myTempDialogColumn.RadiobuttonGroups.Add
Set myLeftRadioButton = myRadioButtonGroup.RadiobuttonControls.Add
myLeftRadioButton.StaticLabel = "Left"
myLeftRadioButton.CheckedState = True
Set myCenterRadioButton = myRadioButtonGroup.RadiobuttonControls.Add
myCenterRadioButton.StaticLabel = "Center"
Set myRightRadioButton = myRadioButtonGroup.RadiobuttonControls.Add
myRightRadioButton.StaticLabel = "Right"
Rem If the user clicked OK, then create the example document.
If myDialog.Show = True Then
Rem Get the values from the dialog box controls.
myString = myTextEditField.EditContents
myPointSize = myPointSizeField.EditValue
Select Case myVerticalJustificationMenu.SelectedIndex
Case 0
myVerticalJustification = idVerticalJustification.idTopAlign
Case 1
myVerticalJustification = idVerticalJustification.idCenterAlign
Case Else
myVerticalJustification = idTopAlign.idBottomAlign
End Select
Rem set the paragraph alignment of the text to the dialog radio button choice.
Select Case myRadioButtonGroup.SelectedButton
Case 0
myAlignment = idJustification.idLeftAlign
Case 1
myAlignment = idJustification.idCenterAlign
Case Else
myAlignment = idJustification.idRightAlign
End Select
Rem Remove the dialog box from memory.
myDialog.Destroy
Rem Create a new document.
myMakeDocument myInDesign, myString, myPointSize, myParagraphAlignment,
myVerticalJustification
Else
myDialog.Destroy
End If
このスクリプトで参照されている myMakeDocument 関数を次に示します。
130
第 7 章 ユーザーインターフェイス
ScriptUI の使用
131
Function myMakeDocument(myInDesign, myString, myPointSize, myAlignment, myVerticalJustification)
Rem Create a new document.
Set myDocument = myInDesign.Documents.Add
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
Rem Resize the text frame to the "live" area of the
Rem page (using the function "myGetBounds").
myBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
myTextFrame.GeometricBounds = myBounds
Rem Enter the text from the dialog box in the text frame.
myTextFrame.Contents = myString
Rem Set the size of the text to the size you entered
Rem in the dialog box.
myTextFrame.Texts.Item(1).PointSize = myPointSize
Rem Set the paragraph alignment to the alignment you
Rem selected in the dialog box.
myTextFrame.Texts.Item(1).Justification = myAlignment
Rem Set the text frame vertical justification to the vertical justification
Rem you selected in the dialog box.
myTextFrame.TextFramePreferences.VerticalJustification = myVerticalJustification
End Function
ScriptUI の使用
JavaScript では、ScriptUI というアドビ システムズ社独自のスクリプティングコンポーネントを使用して、
ユーザーインターフェイス要素の作成や定義が行えます。ScriptUI を使用すれば、InDesign の組み込みの
dialog オブジェクトよりも格段に複雑なインタラクティブダイアログボックスを作成できます。また、フ
ローティングパレットやプログレスバーも作成できます。
AppleScript や VBScript でも、ScriptUI を使用して定義されたユーザーインターフェイス要素にアクセスするこ
とができます。do script メソッド(AppleScript の場合)や DoScript メソッド(VBScript の場合)を使用すれ
ば、他のスクリプト言語で書かれたスクリプトを実行できます。
ScriptUI を使用したプログレスバーの作成
JavaScript で ScriptUI を使用してプログレスバーを作成する方法を、次のスクリプトに示します(完全なスク
リプトについては、ProgressBar を参照してください)。このスクリプトで作成したプログレスバーは、
VBScript で使用することが可能です。
#targetengine "session"
//Because these terms are defined in the "session" engine,
//they will be available to any other JavaScript running
//in that instance of the engine.
var myMaximumValue = 300;
var myProgressBarWidth = 300;
var myIncrement = myMaximumValue/myProgressBarWidth;
myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
function myCreateProgressPanel(myMaximumValue, myProgressBarWidth){
myProgressPanel = new Window('window', 'Progress');
with(myProgressPanel){
myProgressPanel.myProgressBar = add('progressbar', [12, 12,
myProgressBarWidth, 24], 0, myMaximumValue);
}
}
前のスクリプトで作成したプログレスバーを VBScript で呼び出す方法を、次のスクリプトに示します(完全
なスクリプトについては、CallProgressBar を参照してください)。
第 7 章 ユーザーインターフェイス
Rem Create a document and add pages to it-Rem if you do not do this, the progress bar
Rem will go by too quickly.
Set myDocument = myInDesign.Documents.Add
Rem Note that the JavaScripts must use the "session"
Rem engine for this to work.
myString = "#targetengine ""session""" & vbCr
myString = myString & "myCreateProgressPanel(100, 400);" & vbcr
myString = myString & "myProgressPanel.show();" & vbcr
myInDesign.DoScript myString, idScriptLanguage.idJavascript
For myCounter = 1 to 100
Rem Add a page to the document.
myInDesign.Documents.Item(1).Pages.Add
myString = "#targetengine ""session""" & vbCr
myString = myString & "myProgressPanel.myProgressBar.value = "
myString = myString & cstr(myCounter) & "/myIncrement;" & vbcr
myInDesign.DoScript myString, idScriptLanguage.idJavascript
If(myCounter = 100) Then
myString = "#targetengine ""session""" & vbCr
myString = myString & "myProgressPanel.myProgressBar.value = 0;" & vbcr
myString = myString & "myProgressPanel.hide();" & vbcr
myInDesign.DoScript myString, idScriptLanguage.idJavascript
myDocument.Close idSaveOptions.idNo
End If
Next
ScriptUI の使用
132
8
イベント
章の更新ステータス
CS6
変更なし
InDesign スクリプティングでは、アプリケーションやドキュメントの一般的なイベント(ファイルのオープ
ン、新規ファイルの作成、プリント、ディスク上のテキストファイルやグラフィックファイルの読み込みな
ど)に応答することができます。アプリケーションで発生するイベントは、event オブジェクトによって表さ
れます。イベントにスクリプトを割り当てるには、EventListener というスクリプトオブジェクトを使用しま
す。イベントに割り当てるスクリプトは、通常のスクリプトとほとんど同じですが、通常のスクリプトは
ユーザーが(スクリプトパネルから)実行するのに対して、イベントに割り当てるスクリプトは自動的に
(目的のイベントが発生したときに)実行される点が異なります。
この章では、InDesign のイベントを使用したスクリプトについて説明します。最初は簡単なサンプルスクリ
プトから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。
メニューに関連するイベントについては、第 9 章「メニュー」を参照してください。
InDesign のイベントスクリプトモデルは、Worldwide Web Consortium(W3C)勧告のドキュメントオブジェ
クトモデルイベントに似ています。詳しくは、http://www.w3c.org を参照してください。
イベントスクリプトモデルについて
InDesign のイベントスクリプトモデルは、アプリケーションで発生する各種のイベントに相当する一連のオ
ブジェクトによって構成されています。その中心となるのが event オブジェクトです。これは、InDesign の
ユーザーインターフェイスで行われる特定のアクション(またはスクリプトの処理に相当するアクション)
を表します。
イベントに応答するには、そのイベントを受け取るオブジェクトに EventListener を登録します。そのオブ
ジェクトが指定のイベントを受け取ると、EventListener のハンドラー関数に定義されているスクリプト関
数(ディスク上のスクリプトファイルへの参照)が実行されます。
使用可能なイベントを確認するには、VBScript エディターのオブジェクトブラウザーを使用します。VBScript
エディターのオブジェクトブラウザーで、EventEvents モジュールを確認します。
イベントプロパティとイベントの伝達について
ユーザーやスクリプトによってアクションが実行されてイベントが発生すると、そのイベントに応答可能な
スクリプティングオブジェクトにイベントが伝達されます。特定のイベントに対する EventListener が登録
されているオブジェクトにそのイベントが伝達されると、その EventListener が呼び出されます。1 つのイベ
ントが複数のオブジェクトに伝達されて、複数のオブジェクトで処理が行われる場合もあります。
イベントの伝達には、次の 2 種類があります。

伝達しない — イベントターゲットに登録されている EventListener のみが呼び出されます。伝達しない
イベントの例としては、beforeDisplay イベントがあります。
133
第 8 章 イベント
イベントリスナーの操作

134
バブル — target から伝達が開始されます。まず、target に登録されている応答可能な EventListener
が呼び出されます。次に、スクリプトオブジェクトモデルの上方向にイベントが伝達されます。スクリ
プトオブジェクトモデルで target の上位にあるオブジェクトに登録されている、そのイベントに応答可
能な EventListener が呼び出されます。
次の表に、event のプロパティの詳細と、スクリプトオブジェクトモデルでのイベント伝達に与える影響を
示します。
プロパティ
説明
Bubbles
true の場合、event が発生したオブジェクトの上位にあるスクリプティングオ
ブジェクトにその event が伝達されます。
Cancelable
true の場合、target における event のデフォルトの動作をキャンセルできます。
これを行うには、PreventDefault メソッドを使用します。
CurrentTarget
event を処理している現在のスクリプティングオブジェクト。この表の Target
を参照してください。
DefaultPrevented
true の場合、現在の target における event のデフォルト動作が実行されず、ア
クションがキャンセルされます。この表の Target を参照してください。
EventPhase
event の伝達プロセスの現在のステージ。
EventType
event のタイプを表す文字列(
「beforeNew」など)
。
PropagationStopped
true の場合、current target 以降への伝達が中止されます(この表の Target を
参照してください)。イベントの伝達を中止するには、StopPropagation メソッ
ドを使用します。
Target
event を発生させたオブジェクト。例えば、beforeImport イベントの Target は
ドキュメントであり、beforeNew イベントの Target はアプリケーションです。
TimeStamp
event が発生した日時。
イベントリスナーの操作
EventListener を作成するときには、イベントのタイプとイベントハンドラー(関数またはファイル参照)
を指定します。特定のイベントに対して EventListener を追加する方法を、次のスクリプトに示します(完
全なスクリプトについては、AddEventListener を参照してください)。
Rem Given a reference to InDesign "myInDesign"...
myInDesign.AddEventListener "afterNew", GetRef("myDisplayEventType")
このスクリプトで参照されている関数を次に示します。
Function myDisplayEventType(en)
Rem "en" is the event passed to this script by the event listener.
MsgBox ("This event is the " & en.EventType & " event.")
End Function
このスクリプトで作成した EventListener を削除するには、次のスクリプトを実行します(チュートリアル
スクリプトの RemoveEventListener より)。
Rem Given a reference to InDesign "myInDesign"...
myInDesign.RemoveEventListener "afterNew", myDisplayEventType
1 つの EventListener でイベントが処理されても、そのイベントを監視している他の EventListener があれ
ば、そこでも処理が行われる場合があります(イベントの伝達方法によって異なります)。例えば、
afterOpen イベントは、アプリケーションとドキュメントの両方の EventListener で監視されている可能性
があります。
第 8 章 イベント
イベントリスナーの操作
135
EventListener は、現在の InDesign セッションを超えて保持されることはありません。すべての InDesign
セッションで EventListener を利用できるようにしたい場合は、スタートアップスクリプト用のフォルダー
である Startup Scripts にスクリプトを追加します (スクリプトのインストールについて詳しくは、『Adobe
InDesign スクリプティングチュートリアル』の「スクリプトのインストール」を参照してください)。ドキュ
メントに EventListener スクリプトを追加しても、ドキュメントとともに保存されたり、IDML に書き出され
たりすることはありません。
注意 : EventListener を定義するスクリプトで問題が発生した場合は、その EventListener を削除するスクリ
プトを実行するか、InDesign を終了して再起動します。
スクリプトオブジェクトモデルの中で 1 つのイベントが伝達されて、複数の EventListener が呼び出される
場合があります。次のサンプルスクリプトでは、様々なオブジェクトに登録されている EventListener が 1
つのイベントによって呼び出されます(完全なスクリプトについては、MultipleEventListeners を参照してく
ださい)。
Rem Given a reference to InDesign Application object "myInDesign"...
myInDesign.AddEventListener DocumentEvents.idBeforeImport, GetRef("myEventInfo")
Set myDocument = myInDesign.Documents.Add
myInDesign.Documents.Item(1).AddEventListener DocumentEvents.idBeforeImport,
GetRef("myEventInfo")
このスクリプトで参照されている myEventInfo 関数には、次のスクリプトコードが含まれています。
Function myEventInfo(en)
myString = "Current Target: " & en.currentTarget.name
MsgBox(myString)
End Function
このスクリプトを実行してファイルを配置すると、ドキュメントの名前を示す警告と、アプリケーションの
名前を示す警告が順に表示されます。このスクリプトで追加したイベントリスナーを削除するには、
RemoveMultipleEventListeners スクリプトを実行します。
次のサンプルスクリプトでは、ドキュメントの各イベントの EventListener を作成して、簡単なダイアログ
ボックスにイベントに関する情報を表示しています。完全なスクリプトについては、EventListenersOn を参照
してください。
Set myInDesign = CreateObject("InDesign.Application")
myEventNames = Array("beforeQuit", "afterQuit", "beforeNew", "afterNew", "beforeOpen",
"afterOpen", "beforeClose", "afterClose", "beforeSave", "afterSave", "beforeSaveAs",
"afterSaveAs", "beforeSaveACopy", "afterSaveACopy", "beforeRevert", "afterRevert", "beforePrint",
"afterPrint", "beforeExport", "afterExport", "beforeImport", "afterImport", "beforePlace",
"afterPlace")
For myCounter = 0 To UBound(myEventNames)
myInDesign.AddEventListener myEventNames(myCounter), "c:¥GetEventInfo.vbs", False
If myCounter < UBound(myEventNames) Then
myInDesign.EventListeners.Add myEventNames(myCounter), "c:¥GetEventInfo.vbs", False
End If
Next
このスクリプトで参照されているスクリプトを次に示します。このファイル参照で示されているディスク上
の場所に、該当するスクリプトファイルが存在している必要があります。完全なスクリプトについては、
GetEventInfo.vbs を参照してください。
第 8 章 イベント
「afterNew」イベントリスナーの例
136
main evt
Function main(myEvent)
myString = "Handling Event: " & myEvent.EventType
myString = myString & vbCr & vbCr & "Target: " & myEvent.Target & " " &
myEvent.Target.Name
myString = myString & vbCr & "Current: " & myEvent.CurrentTarget & " " &
myEvent.CurrentTarget.Name
myString = myString & vbCr & vbCr & "Phase: " &
myGetPhaseName(myEvent.EventPhase)
myString = myString & vbCr & "Bubbles: " & myEvent.Bubbles
myString = myString & vbCr & vbCr & "Cancelable: " & myEvent.Cancelable
myString = myString & vbCr & "Stopped: " & myEvent.PropagationStopped
myString = myString & vbCr & "Canceled: " & myEvent.DefaultPrevented
myString = myString & vbCr & vbCr & "Time: " & myEvent.TimeStamp
MsgBox myString, vbOKOnly, "Event Details"
end function
Rem Function returns a string corresponding to the event phase enumeration.
Function myGetPhaseName(myEventPhase)
Select Case myEventPhase
Case idEventPhases.idAtTarget
myPhaseName = "At Target"
Case idEventPhases.idBubblingPhase
myPhaseName = "Bubbling"
Case idEventPhases.idDone
myPhaseName = "Done"
Case idEventPhases.idNotDispatching
myPhaseName = "Not Dispatching"
end select
myGetPhaseName = myPhaseName
End Function
アプリケーションオブジェクトのすべての EventListener をオフにする方法を、次のサンプルスクリプトに
示します。完全なスクリプトについては、EventListenersOff を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
For myCounter = 1 To myInDesign.EventListeners.Count
myInDesign.EventListeners.Item(1).Delete
Next
「afterNew」イベントリスナーの例
afterNew イベントは、ユーザー名、ドキュメントの作成日、著作権情報、その他の作業に関する情報などを
ドキュメントに追加したい場合に便利です。ドキュメントの最初のマスタースプレッドの印刷可能領域にあ
るテキストフレームにこのような情報を追加する方法を、次のチュートリアルスクリプトに示します(完全
なスクリプトについては、AfterNew というチュートリアルを参照してください)。このスクリプトでは、ド
キュメントのメタデータ(ファイル情報または XMP 情報とも呼ばれます)も追加しています。
Rem Adds an event listener to the afterNew event. Calls
Rem a script on disk to set up basic document parameters
Rem and XMP metadata.
Set myInDesign = CreateObject("InDesign.Application")
Set myEventListener = myInDesign.EventListeners.Add("afterNew",
"c:¥IDEventHandlers¥AfterNewHandler.vbs")
このスクリプトで参照されているスクリプトを次に示します。このファイル参照で示されているディスク上
の場所に、該当するスクリプトファイルが存在している必要があります。完全なスクリプトについては、
AfterNewHandler.vbs を参照してください。
第 8 章 イベント
「afterNew」イベントリスナーの例
Rem AfterNewHandler.vbs
Rem An InDesign CS6 VBScript
Rem
Rem This script is called by the AfterNew.vbs tutorial script. It
Rem Sets up a basic document layout and adds XMP information
Rem to the document.
AfterNewHandler(evt)
Function AfterNewHandler(myEvent)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myEvent.Parent
Set myViewPreferences = myDocument.ViewPreferences
myViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
myViewPreferences.RulerOrigin = idRulerOrigin.idPageOrigin
Rem mySlugOffset is the distance from the bottom of the
Rem page to the top of the slug.
mySlugOffset = 24
Rem mySlugHeight is the height of the slug text frame.
mySlugHeight = 72
With myDocument.DocumentPreferences
.documentSlugUniformSize = false
.SlugBottomOffset = mySlugOffset + mySlugHeight
.SlugTopOffset = 0
.SlugInsideOrLeftOffset = 0
.SlugRightOrOutsideOffset = 0
End With
For myCounter = 1 To myDocument.MasterSpreads.Count
Set myMasterSpread = myDocument.MasterSpreads.Item(myCounter)
For myMasterPageCounter = 1 To myMasterSpread.Pages.Count
Set myPage = myMasterSpread.Pages.Item(myMasterPageCounter)
mySlugBounds = myGetSlugBounds(myDocument, myPage, mySlugOffset,
mySlugHeight)
Set mySlugFrame = myPage.TextFrames.Add
mySlugFrame.GeometricBounds = mySlugBounds
mySlugFrame.Contents = "Created: " & myEvent.TimeStamp & vbCr & "by: "
& myInDesign.UserName
Next
Next
With myDocument.MetadataPreferences
.Author = "Adobe Systems"
.Description = "This is a sample document with XMP metadata."
End With
End Function
Function myGetSlugBounds(myDocument, myPage, mySlugOffset, mySlugHeight)
myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
myX1 = myPage.MarginPreferences.Left
myY1 = myPageHeight + mySlugOffset
myX2 = myPageWidth - myPage.MarginPreferences.Right
myY2 = myY1 + mySlugHeight
myGetSlugBounds = Array(myY1, myX1, myY2, myX2)
End Function
137
第 8 章 イベント
「beforePrint」イベントリスナーの例
138
「beforePrint」イベントリスナーの例
beforePrint イベントは、様々なプリフライトチェックを行うスクリプトを実行したい場合に便利です。プリ
ントを行う前にドキュメントの特定の属性を確認するイベントリスナーの追加方法を、次のスクリプトに示
します(完全なスクリプトについては、BeforePrint を参照してください)。
Rem Adds an event listener that performs a preflight check on
Rem a document before printing. If the preflight check fails,
Rem the script gives the user the opportunity to cancel the print job.
Set myInDesign = CreateObject("InDesign.Application")
Set myEventListener = myInDesign.EventListeners.Add("beforePrint",
"c:¥IDEventHandlers¥BeforePrintHandler.vbs")
このスクリプトで参照されているスクリプトを次に示します。このファイル参照で示されているディスク上
の場所に、該当するスクリプトファイルが存在している必要があります。完全なスクリプトについては、
BeforePrintHandler.vbs を参照してください。
Rem BeforePrintHandler.vbs
Rem An InDesign CS6 VBScript
Rem
Rem Peforms a preflight check on a document. Called by the
Rem BeforePrint.applescript event listener example.
Rem "evt" is the event passed to this script by the event listener.
myBeforePrintHandler(evt)
Function myBeforePrintHandler(myEvent)
Rem The parent of the event is the document.
Set myDocument = myEvent.parent
If myPreflight(myDocument) = False Then
myEvent.stopPropagation
myEvent.preventDefault
myString = "Document did not pass preflight check." & vbCr
myString = myString & "Please fix the problems and try again."
msgbox(myString)
Else
msgbox("Document passed preflight check. Ready to print.")
myDocument.print(true)
End If
End Function
Function myPreflight(myDocument)
myPreflightCheck = True
myFontCheck = myCheckFonts(myDocument)
myGraphicsCheck = myCheckGraphics(myDocument)
If ((myFontCheck = false)Or(myGraphicsCheck = false)) Then
myPreflightCheck = false
End If
myPreflight = myPreflightCheck
End function
Function myCheckFonts(myDocument)
myFontCheck = true
For myCounter = 1 To myDocument.fonts.count
Set myFont = myDocument.fonts.item(myCounter)
if myFont.status <> idFontStatus.idinstalled Then
第 8 章 イベント
選択に関連するイベントリスナーの例
139
myFontCheck = false
End If
Next
myCheckFonts = myFontCheck
End function
function myCheckGraphics(myDocument)
myGraphicsCheck = true
for myCounter = 1 To myDocument.allGraphics.count
set myGraphic = myDocument.allGraphics.item(myCounter)
If myGraphic.itemLink.status <> idLinkStatus.idnormal Then
myGraphicsCheck = false
End If
Next
myCheckGraphics = myGraphicsCheck
End function
選択に関連するイベントリスナーの例
InDesign では、選択に関連するイベントに応答することができます。InDesign ドキュメントのオブジェクトを
選択したり選択解除したりしたときには、afterSelectionChanged イベントが発生します。選択したオブジェ
クトの属性(フォーマットや位置)を変更したときには、afterSelectionAttributeChanged イベントが発生
します。この 2 つのイベントは、ユーザーアクションに応答するスクリプトを作成する場合に便利です。
選択が変更されたときにオブジェクトの種類を取得して表示する方法を、次のスクリプトに示します。完全
なスクリプトについては、AfterSelectionChanged を参照してください。
Set myDocument = myInDesign.Documents.Add
myDocument.AddEventListener "afterSelectionChanged", GetRef("myDisplaySelectionType")
このスクリプトで参照されているイベントハンドラーを次に示します。
Function myDisplaySelectionType(en)
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
if myInDesign.Documents.Item(1).Selection.Count > 0 Then
Set mySelection = myInDesign.Documents.Item(1).Selection
myString = "Selection Contents:" & vbCr
for myCounter = 1 To mySelection.Count
myString = myString & TypeName(mySelection.Item(myCounter)) & vbCr
Next
MsgBox(myString)
End If
End If
End Function
このスクリプトで追加したイベントリスナーを削除するには、RemoveAfterSelectionChanged スクリプトを実
行します。
選択の属性の変更に応答する方法を、次のスクリプトに示します。この例では、選択で Registration スウォッ
チが適用されたかどうかをイベントハンドラーで確認します (Registration スウォッチを誤って適用すると、
業務用のプリンターで問題が発生する可能性があります)。Registration スウォッチが適用されていた場合、変
更が意図的に行われたものであるかどうかをユーザーに確認します。完全なスクリプトについては、
AfterSelectionAttributeChanged を参照してください。
Set myDocument = myInDesign.Documents.Add
myDocument.AddEventListener "afterSelectionAttributeChanged", GetRef("myCheckForRegistration")
このスクリプトで参照されているイベントハンドラーを次に示します。
第 8 章 イベント
「onIdle」イベントリスナーの例
140
Function myCheckForRegistration(en)
myRegistrationSwatchUsed = false
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
If myInDesign.Documents.Item(1).Selection.Count > 0 Then
Set mySelection = myInDesign.Documents.Item(1).Selection
For myCounter = 1 To mySelection.Count
Set myFillColor = mySelection.Item(myCounter).FillColor
Set myStrokeColor = mySelection.Item(myCounter).StrokeColor
If myFillColor.Name = "Registration" Or myStrokeColor.Name =
"Registration" Then
myRegistrationSwatchUsed = True
End If
Next
If myRegistrationSwatchUsed = True Then
MsgBox("The Registration swatch is applied to some of the" & vbCr & _
"objects in the selection. Did you really intend to apply this swatch?")
End If
End If
End If
End Function
このスクリプトで追加したイベントリスナーを削除するには、RemoveAfterSelectionAttributeChanged スクリ
プトを実行します。
「onIdle」イベントリスナーの例
InDesign のアイドルタスクは、アプリケーションのイベントキューに処理対象のイベントが存在しないとき
に実行されます。アイドルタスクは、スクリプトで簡単に実行できます。onIdle イベントにより、スクリプ
トベースのアイドルタスクを実行する方法が提供されます。このイベントを使用して、InDesign および
InCopy がアイドル状態のときに自動的にスクリプトを実行できます。イベントターゲットは IdleTask に、イ
ベントオブジェクトは IdleEvent になります。
アイドルタスクの Sleep プロパティは、タスクが再度呼び出されるまでの時間です。当然ですが、この待機
時間には、ユーザーの作業に支障が出ないだけの大きな値を設定する必要があります。ただし、この値は、
スクリプトで実行するタスクによって異なります。
待機時間をゼロに設定すると、タスクは削除されます(ただし、イベントリスナーは削除されません)。この
方法は、アイドルタスクを中止する場合に便利です。
イベントリスナーを追加し、アイドルタスクからメッセージボックスを表示する方法を、次のスクリプトに
示します(完全なスクリプトについては、Reminder を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myIdleTask = myInDesign.IdleTasks.Add()
myIdleTask.Name = "my_idle_task"
myIdleTask.Sleep = 10000
Rem You need to fill in your own file path.
fileName = "C:¥scripting¥OnIdleEventHandler.vbs"
Set onIdleEventListener = myIdleTask.AddEventListener("onIdle", fileName, False)
MsgBox("Created idle task " & myIdleTask.Name & "; added event listener on " &
onIdleEventListener.EventType)
イベントハンドラーは、OnIdleEventHandler.vbs というスクリプトファイルです。
第 8 章 イベント
「onIdle」イベントリスナーの例
141
Rem "evt" is the event passed to this script by the event listener.
onIdleEventtHandler(evt)
Function onIdleEventtHandler(myIdleEvent)
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count = 0 Then
Set myDoc = myInDesign.Documents.Add()
MsgBox("Created document " + myDoc.Name + " in idle task.")
Exit Function
End If
Set myTextFrames = myInDesign.ActiveDocument.Pages.Item(1).TextFrames
If myTextFrames.Count = 0 Then
Set myTextFrame = myTextFrames.Add()
myTextFrame.GeometricBounds = Array("72pt", "72pt", "288pt", "288pt")
myTextFrame.Contents = "Text frame created in idle task"
MsgBox("Created a text frame in idle task.")
Exit Function
End If
Rem Delete idle task by setting its sleep time to zero.
myIdleEvent.Parent.Sleep = 0
MsgBox("Nothing to do. Delete idle task.")
End Function
このスクリプトで作成したアイドルタスクを削除するには、次のスクリプトを実行します(完全なスクリプ
トについては、RemoveIdleTask を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
taskCount = myInDesign.IdleTasks.Count
If taskCount = 0 Then
MsgBox("There is no idle task.")
Else
myIdleTaskName = "my_idle_task"
For Each myIdleTask In myInDesign.IdleTasks
If myIdleTask.Name = myIdleTaskName Then
myIdleTask.Delete()
End If
MsgBox("Idle task " & myIdleTaskName & " removed.")
Next
End If
すべてのアイドルタスクを削除するには、次のスクリプトを実行します(完全なスクリプトについては、
RemoveAllIdleTasks を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
taskCount = myInDesign.IdleTasks.Count
If taskCount = 0 Then
MsgBox("There is no idle task.")
Else
For Each myIdleTask In myInDesign.IdleTasks
myIdleTask.Delete()
Next
MsgBox(taskCount & " idle task(s) removed.")
End If
既存のアイドルタスクを表示するには、次のスクリプトを実行します(完全なスクリプトについては、
ListIdleTasks を参照してください)。
第 8 章 イベント
「onIdle」イベントリスナーの例
Set myInDesign = CreateObject("InDesign.Application")
taskCount = myInDesign.IdleTasks.Count
If taskCount = 0 Then
MsgBox("There is no idle task.")
Else
str = ""
For i = 1 To taskCount
Set myIdleTask = myInDesign.IdleTasks.Item(i)
str = str & "idle task " & myIdleTask.id & ": " & myIdleTask.name & VbCrLf
Next
MsgBox(str)
End If
142
9
メニュー
章の更新ステータス
CS6
変更なし
InDesign スクリプティングでは、メニュー項目の追加と削除、任意のメニューコマンドの実行、メニュー項
目へのスクリプトの割り当てを行うことができます。
この章では、InDesign のメニューをスクリプトで操作する方法について説明します。最初は簡単なサンプル
スクリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。
メニューモデルについて
InDesign のメニュースクリプトモデルは、アプリケーションのユーザーインターフェイスに表示されるメ
ニューに対応する一連のオブジェクトによって構成されています(メインのメニューバーに表示されるメ
ニューだけでなく、パネルに用意されているメニューも含みます)。menu オブジェクトには、次のオブジェク
トが含まれています。

MenuItems — メニューに表示されるメニューオプション (サブメニューは含まれません)

MenuSeparators — メニュー内のメニューオプションを区切るために使用される線

Submenus — 更なるメニュー選択が含まれているメニューオプション

MenuElements — メニューに表示されるすべての MenuItems、MenuSeparators、Submenus

EventListeners — メニューに対するユーザーアクションやスクリプトアクションに応答するためのリス
ナー

Events — メニューによって発生した events
どの MenuItem にも、AssociatedMenuAction というプロパティによって MenuAction が割り当てられていま
す。そのメニュー項目が選択されたときの処理は、MenuAction のプロパティによって定義されています。
ユーザーインターフェイスで定義されている MenuAction に加えて、独自の ScriptMenuAction を作成して、
メニュー項目にスクリプトを割り当てることができます。
1 つの MenuAction や ScriptMenuAction は、0 個以上の MenuItem に関連付けることができます。
次の図に、様々なメニューオブジェクトの関係を示します。
143
第 9 章 メニュー
メニューモデルについて
144
application
menuActions
menuAction
area
checked
enabled
eventListeners
eventListener
id
eventListener
index
...
label
name
events
event
parent
event
title
...
scriptMenuActions
scriptMenuAction
same as menuAction
すべてのメニューアクションのリスト(テキストファイル)を作成するには、次のスクリプトを実行します
(チュートリアルスクリプトの GetMenuActions より)
。
Set
Set
Rem
Set
For
myInDesign = CreateObject("InDesign.Application")
myFileSystemObject = CreateObject("Scripting.FileSystemObject")
You'll need to fill in a valid file path on your system.
myTextFile = myFileSystemObject.CreateTextFile("c:¥menuactions.txt", True, False)
myCounter = 1 To myInDesign.MenuActions.Count
Set myMenuAction = myInDesign.MenuActions.Item(myCounter)
myTextFile.WriteLine myMenuAction.name
Next
myTextFile.Close
MsgBox "done!"
利用可能なメニューのリスト(テキストファイル)を作成するには、次のスクリプトを実行します(完全な
スクリプトについては、GetMenuNames を参照してください)。InDesign には多数のメニューがあるので、こ
のスクリプトの実行には時間がかかる場合があります。
第 9 章 メニュー
メニューモデルについて
145
Set
Set
Set
For
myInDesign = CreateObject("InDesign.Application")
myFileSystemObject = CreateObject("Scripting.FileSystemObject")
myTextFile = myFileSystemObject.CreateTextFile("c:¥menunames.txt", True, False)
myMenuCounter = 1 To myInDesign.Menus.Count
Set myMenu = myInDesign.Menus.Item(myMenuCounter)
myTextFile.WriteLine myMenu.Name
myProcessMenu myMenu, myTextFile
Next
myTextFile.Close
MsgBox "done!"
Function myProcessMenu(myMenuItem, myTextFile)
myString = ""
myMenuName = myMenuItem.Name
For myCounter = 1 To myMenuItem.MenuElements.Count
If TypeName(myMenuItem.MenuElements.Item(myCounter)) <>
"MenuSeparator" Then
myString = myGetIndent(myMenuItem.MenuElements.Item(myCounter),
myString, False)
myTextFile.WriteLine myString &
myMenuItem.MenuElements.Item(myCounter).Name
myMenuElementName = myMenuItem.MenuElements.Item(myCounter).Name
myString = ""
If TypeName(myMenuItem.MenuElements.Item(myCounter)) = "Submenu" Then
If myMenuItem.MenuElements.Count > 0 Then
myProcessMenu myMenuItem.MenuElements.Item(myCounter),
myTextFile
End If
End If
End If
Next
End Function
Function myGetIndent(myMenuItem, myString, myDone)
Do While myDone = False
If TypeName(myMenuItem.Parent) = "Application" Then
myDone = True
Else
myString = myString & vbTab
myGetIndent myMenuItem.Parent, myString, myDone
End If
Loop
myGetIndent = myString
End Function
ローカライゼーションとメニュー名
InDesign スクリプティングでは、MenuItem、Menu、MenuAction、Submenu はすべて名前で参照されます。した
がって、アプリケーションがインストールされているロケールに依存せずにオブジェクトを指定する方法が
必要になります。これを行うには、ロケールに依存せずに特定の項目を参照するための文字列が格納されて
いる内部データベースを使用します。例えば、次のスクリプトを使用すれば、ロケールに依存しないメ
ニューアクション名を取得することができます(完全なスクリプトについては、GetKeyStrings を参照してく
ださい)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Fill in the name of the menu action you want.
Set myMenuAction = myInDesign.MenuActions.Item("Convert to Note")
myKeyStrings = myInDesign.FindKeyStrings(myMenuAction.Name)
myString = ""
For Each myKeyString In myKeyStrings
myString = myString & myKeyString & vbCr
Next
MsgBox myString
注意 : ロケールに依存しない名前を取得する場合は、Menu、MenuItem、Submenu の名前を取得するよりも、
MenuAction の名前を取得するほうが便利です。MenuAction のタイトルは、単一の文字列である場合が多いか
第 9 章 メニュー
スクリプトからのメニューアクションの実行
146
らです。その他のメニューオブジェクトの多くからは、FindKeyStrings メソッドで複数の文字列が返されま
す。
ロケールに依存しない名前を取得したら、スクリプトで使用することができます。この文字列を使用したス
クリプトは、現在使用している InDesign と異なるロケールにインストールされている InDesign でも正常に機
能します。
ロケールに依存しない文字列を現在のロケールに変換するには、次のスクリプトを使用します(チュートリ
アルスクリプトの TranslateKeyString より)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Fill in the appropriate key string in the following line.
myString = myInDesign.TranslateKeyString("$ID/NotesMenu.ConvertToNote")
MsgBox myString
スクリプトからのメニューアクションの実行
InDesign に組み込まれている MenuAction は、いずれもスクリプトから実行することができます。すべての
MenuAction が MenuItem に割り当てられているとは限りませんが、その点を除けば、スクリプトから
MenuAction を実行することは、ユーザーインターフェイスでメニューオプションを選択することとまったく
同じです。例えば、あるメニューオプションを選択するとダイアログボックスが表示される場合、それに対
応する MenuAction をスクリプトから実行すると同じダイアログボックスが表示されます。
スクリプトから MenuAction を実行する方法を、次のスクリプトに示します(完全なスクリプトについては、
InvokeMenuAction を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Rem Get a reference to a menu action.
Set myMenuAction = myInDesign.MenuActions.Item("$ID/NotesMenu.ConvertToNote")
Rem Run the menu action. The example action will fail if you do not
Rem have text selected.
myMenuAction.Invoke
注意 : 一般的に、InDesign のプロセスをスクリプトで自動化する場合、メニューアクションやユーザーイン
ターフェイスを選択することで必要な処理を実行するのは、あまりよい方法とは言えません。InDesign のス
クリプトオブジェクトモデルを操作するほうが、はるかに確実で強力な処理を実現できます。メニューアク
ションは、選択やウィンドウの状態など、ユーザーインターフェイスの様々な条件に依存しています。オブ
ジェクトモデルを使用すれば、InDesign ドキュメント内のオブジェクトを直接操作できるので、ユーザーイ
ンターフェイスに依存することなく、一貫性のある高速な処理を実現できます。
メニューやメニュー項目の追加
InDesign のユーザーインターフェイスと同じように、スクリプトでもメニューやメニュー項目の作成や削除
が行えます。新しい場所に新しいメニューを作成して、あるサブメニューの内容をそのメニューに複製する
方法を、次のサンプルスクリプトに示します(完全なスクリプトについては、CustomizeMenu を参照してく
ださい)。
Set
Set
Set
Set
Set
Set
For
myInDesign = CreateObject("InDesign.Application")
myMainMenu = myInDesign.Menus.Item("Main")
myTypeMenu = myMainMenu.MenuElements.Item("Type")
myFontMenu = myTypeMenu.MenuElements.Item("Font")
myKozukaMenu = myFontMenu.Submenus.Item("Kozuka Mincho Pro ")
mySpecialFontMenu = myMainMenu.Submenus.Add("Kozuka Mincho Pro")
myCounter = 1 To myKozukaMenu.MenuItems.Count
Set myAssociatedMenuAction = myKozukaMenu.MenuItems.Item(myCounter).AssociatedMenuAction
mySpecialFontMenu.MenuItems.Add myAssociatedMenuAction
Next
このスクリプトで作成されたカスタムメニュー項目を削除するには、RemoveCustomMenu を使用します。
第 9 章 メニュー
メニューとイベント
147
Set myMainMenu = myInDesign.menus.item("$ID/Main")
On Error Resume Next
Set mySpecialFontMenu = myMainMenu.Submenus.Item("Kozuka Mincho Pro")
mySpecialFontMenu.Delete
On Error Goto 0
メニューとイベント
ユーザーインターフェイスでメニューやサブメニューを選択すると、イベントが生成されます。これと同じ
ように、MenuAction や ScriptMenuAction を実行した場合にも、イベントが生成されます。スクリプトを使
用すれば、これらのイベントに応答するために EventListener を登録することができます。様々なメニュー
スクリプティングコンポーネントのイベントを次の表に示します。
オブジェクト
イベント
説明
Menu
beforeDisplay
メニューの内容が表示される前に、登録したスクリプトが実
行されます。
MenuAction
afterInvoke
関連付けられている MenuItem が選択されて、onInvoke イベン
トが発生した後に、登録したスクリプトが実行されます。
beforeInvoke
関連付けられている MenuItem が選択されて、onInvoke イベン
トが発生する前に、登録したスクリプトが実行されます。
afterInvoke
関連付けられている MenuItem が選択されて、onInvoke イベン
トが発生した後に、登録したスクリプトが実行されます。
beforeInvoke
関連付けられている MenuItem が選択されて、onInvoke イベン
トが発生する前に、登録したスクリプトが実行されます。
beforeDisplay
ScriptMenuAction の有効/チェックのステータスに対する内
ScriptMenuAction
部要求が行われる前に、登録したスクリプトが実行されます。
onInvoke
ScriptMenuAction が呼び出されたときに、登録したスクリプ
トが実行されます。
Submenu
beforeDisplay
Submenu の内容が表示される前に、登録したスクリプトが実行
されます。
Event や EventListener について詳しくは、第 8 章「イベント」を参照してください。
メニューに表示する項目を変更するには、beforeDisplay Event に対する EventListener を追加します。メ
ニューが選択されると、登録したスクリプト(メニュー項目の有効化/無効化や名前の変更などの、メ
ニューに関連するタスクを実行するスクリプト)が EventListener によって実行されます。この仕組みは、
利用可能なフォント、最近使用したドキュメント、開いているウィンドウなどをメニューに表示するために、
内部的に使用されています。
第 9 章 メニュー
scriptMenuAction の操作
148
scriptMenuAction の操作
ScriptMenuAction を使用すると、MenuAction を新しく作成して、onInvoke Event の発生時に指定のスクリプ
トを実行することができます。
ScriptMenuAction を作成してメニュー項目に割り当てる方法を、次のスクリプトに示します(完全なスクリ
プトについては、MakeScriptMenuAction を参照してください)。このスクリプトでは、メニュー項目が選択さ
れると、単に警告が表示されます。
Set
Set
Set
Set
Set
myInDesign = CreateObject("InDesign.Application")
mySampleScriptAction = myInDesign.ScriptMenuActions.Add("Display Message")
myEventListener = mySampleScriptAction.EventListeners.Add("onInvoke", "c:¥message.vbs")
mySampleScriptMenu = myInDesign.Menus.Item("$ID/Main").Submenus.Add("Script Menu Action")
mySampleScriptMenuItem = mySampleScriptMenu.MenuItems.Add(mySampleScriptAction)
message.vbs スクリプトファイルには、次のコードが含まれます。
MsgBox("You selected an example script menu action.")
このスクリプトで作成した Menu、Submenu、MenuItem、ScriptMenuAction を削除するには、次のスクリプト
を実行します(チュートリアルスクリプトの RemoveScriptMenuAction より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set mySampleScriptAction = myInDesign.ScriptMenuActions.Item("Display Message")
mySampleScriptAction.Delete
Set mySampleScriptMenu = myInDesign.Menus.Item("$ID/Main").Submenus.Item("Script Menu Action")
mySampleScriptMenu.Delete
すべての ScriptMenuAction を削除することもできます。次のスクリプトにその例を示します(チュートリア
ルスクリプトの RemoveAllScriptMenuActions より)
。このスクリプトでは、ScriptMenuAction のメニューリス
トも削除されますが、作成したメニューやサブメニューは削除されません。
Set myInDesign = CreateObject("InDesign.Application")
For myCounter = myInDesign.ScriptMenuActions.Count To 1 Step -1
myInDesign.ScriptMenuActions.Item(myCounter).Delete
Next
現在のすべての ScriptMenuAction のリストを作成することができます。次のスクリプトにその例を示します
(チュートリアルスクリプトの ListScriptMenuActions より)
。
Set
Set
Rem
Set
For
myInDesign = CreateObject("InDesign.Application")
myFileSystemObject = CreateObject("Scripting.FileSystemObject")
You'll need to fill in a valid file path for your system.
myTextFile = myFileSystemObject.CreateTextFile("c:¥scriptmenuactionnames.txt", True, False)
myCounter = 1 To myInDesign.ScriptMenuActions.Count
Set myScriptMenuAction = myInDesign.ScriptMenuActions.Item(myMenuCounter)
myTextFile.WriteLine myScriptMenuAction.Name
Next
myTextFile.Close
ScriptMenuAction を使用して、beforeDisplay Event の発生時にスクリプトを実行することもできます。こ
の場合は、ScriptMenuAction の状態に対する内部要求が行われる前に(メニュー項目が表示される直前に)
スクリプトが実行されます。これは、スクリプトでメニュー名を変更したり、有効/チェックのステータス
を設定したりする場合に特に役立ちます。
次のサンプルスクリプトでは、beforeDisplay Event に対する EventListener を追加して、現在の選択を確認
するようにしています。何も選択されていない場合は、EventListener のスクリプトによってメニュー項目が
無効化されます。アイテムが選択されている場合は、メニュー項目が有効化されます。メニュー項目を選択
すると、選択されている最初のアイテムの種類が表示されます (完全なスクリプトについては、
BeforeDisplay を参照してください)。
第 9 章 メニュー
さらに複雑なメニュースクリプティングの例
149
Set myInDesign = CreateObject("InDesign.Application")
Set mySampleScriptAction = myInDesign.ScriptMenuActions.Add("Display Message")
Set myEventListener = mySampleScriptAction.EventListeners.Add("onInvoke",
"c:¥WhatIsSelected.vbs ")
Set mySampleScriptMenu = myInDesign.Menus.Item("$ID/Main").Submenus.Add("Script Menu Action")
Set mySampleScriptMenuItem = mySampleScriptMenu.MenuItems.Add(mySampleScriptAction)
mySampleScriptMenu.EventListeners.Add "beforeDisplay", "c:¥BeforeDisplayHandler.vbs"
BeforeDisplayHander チュートリアルスクリプトファイルには、次のスクリプトが含まれます。
Set myInDesign = CreateObject("InDesign.Application")
Set mySampleScriptAction = myInDesign.ScriptMenuActions.Item("Display Message")
If myInDesign.Selection.Count > 0 Then
mySampleScriptAction.Enabled = True
Else
mySampleScriptAction.Enabled = False
End If
WhatIsSelected チュートリアルスクリプトファイルには、次のスクリプトが含まれます。
Set myInDesign = CreateObject("InDesign.Application")
myString = TypeName(myInDesign.Selection.Item(1))
MsgBox "The first item in the selection is a " & myString & "."
さらに複雑なメニュースクリプティングの例
InDesign のユーザーインターフェイスで別の項目を選択すると、コンテキストメニューの内容が変わります。
選択したオブジェクトのプロパティに基づいてコンテキストメニューを変更する方法を、次のサンプルスク
リプトに示します。このサンプルスクリプトは断片的なスクリプトです。完全なスクリプトについては、
LayoutContextMenu を参照してください。
次のスクリプトでは、レイアウトコンテキストメニュー(ページアイテムを選択すると表示されるコンテキ
ストメニュー)に新規のメニュー項目を追加する方法を示します。このスクリプトでは、beforeDisplay
EventListener が追加されています。このイベントリスナーは、MenuItem が既に存在するかどうかを確認し、
存在する場合は削除します。これにより、グラフィックが選択されていない場合はコンテキストメニューに
MenuItem が表示されず、コンテキストメニューに複数のメニュー項目が追加されるのを防ぎます。
EventListener では、次に、グラフィックが選択されているかどうかを確認し、選択されている場合は新規
の ScriptMenuItem が作成されます。
Set myInDesign = CreateObject("InDesign.Application")
Rem The locale-independent name (aka "key string") for the
Rem Layout context menu is "$ID/RtMouseLayout".
Set myLayoutContextMenu = myInDesign.Menus.Item("$ID/RtMouseLayout")
Rem Create the event handler for the "beforeDisplay" event
Rem of the Layout context menu.
Set myBeforeDisplayListener = myLayoutContextMenu.addEventListener("beforeDisplay",
"c:¥IDEventHandlers¥LabelGraphicBeforeDisplay.vbs", false)
この例で参照されている LabelGraphicBeforeDisplay.vbs ファイルには、次のコードが含まれています。
第 9 章 メニュー
さらに複雑なメニュースクリプティングの例
myBeforeDisplayHandler evt
function myBeforeDisplayHandler(myEvent)
ReDim myObjectList(0)
Set myInDesign = CreateObject("InDesign.Application")
Set myLayoutContextMenu = myInDesign.Menus.Item("$ID/RtMouseLayout")
Rem Check for open documents is a basic sanity check-Rem it should never be needed, as this menu won't be
Rem displayed unless an item is selected. But it's best
Rem to err on the side of safety.
If myInDesign.Documents.Count > 0 Then
If myInDesign.Selection.Count > 0 Then
Rem Does the selection contain any graphics?
for myCounter = 1 To myInDesign.Selection.Count
Select Case TypeName(myInDesign.Selection.Item(myCounter))
Case "PDF","EPS", "Image":
If Not (IsEmpty(myObjectList(0))) Then
ReDim Preserve myObjectList(UBound(myObjectList) + 1)
End If
Set myObjectList(UBound(myObjectList)) =
myInDesign.Selection.Item(myCounter)
Case "Rectangle", "Oval", "Polygon":
If myInDesign.selection.Item(myCounter).
Graphics.Count > 0 Then
If Not (IsEmpty(myObjectList(0))) Then
ReDim Preserve myObjectList(UBound(myObjectList) + 1)
End If
Set myObjectList(UBound(myObjectList)) =
myInDesign.Selection.Item(myCounter).Graphics.Item(1)
End If
End Select
Next
If Not (IsEmpty(myObjectList(0))) Then
Rem Add the menu item if it does not already exist.
If myCheckForMenuItem(myLayoutContextMenu,
"Create Graphic Label") = False Then
myMakeLabelGraphicMenuItem myInDesign
End If
Else
Rem Remove the menu item, if it exists.
If myCheckForMenuItem(myLayoutContextMenu,
"Create Graphic Label") = True Then
myLayoutContextMenu.MenuItems.Item("Create Graphic
Label").delete
End If
End If
End If
End If
End Function
Function myMakeLabelGraphicMenuItem(myInDesign)
Rem alert("Got to the myMakeLabelGraphicMenuItem function!")
If myCheckForScriptMenuItem(myInDesign, "Create Graphic Label") =
False Then
msgbox "Making a new script menu action!"
Set myLabelGraphicMenuAction = myInDesign.ScriptMenuActions.add("Create
Graphic Label")
Set myLabelGraphicEventListener = myLabelGraphicMenuAction.
EventListeners.Add("onInvoke", "c:¥IDEventHandlers¥
LabelGraphicOnInvoke.vbs", false)
End If
Set myLabelGraphicMenuItem = myInDesign.Menus.Item("$ID/RtMouseLayout").
menuItems.add(myInDesign.scriptMenuActions.item("Create Graphic Label"))
End Function
この例で参照されている LabelGraphicOnInvoke.vbs では、menu item が選択されるとアクティブになる
(onInvoke イベント)script menu action が定義されます。
150
第 9 章 メニュー
さらに複雑なメニュースクリプティングの例
myLabelGraphicEventHandler evt
Function myLabelGraphicEventHandler(myEvent)
ReDim myObjectList(0)
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Selection.Count > 0 Then
Rem Does the selection contain any graphics?
for myCounter = 1 To myInDesign.Selection.Count
Select Case TypeName(myInDesign.Selection.Item(myCounter))
Case "PDF","EPS", "Image":
If Not (IsEmpty(myObjectList(0))) Then
ReDim Preserve myObjectList(UBound(myObjectList) + 1)
End If
Set myObjectList(UBound(myObjectList)) =
myInDesign.Selection.Item(myCounter)
Case "Rectangle", "Oval", "Polygon":
If myInDesign.selection.Item(myCounter).Graphics.Count > 0
Then
If Not (IsEmpty(myObjectList(0))) Then
ReDim Preserve myObjectList(UBound(myObjectList) + 1)
End If
Set myObjectList(UBound(myObjectList)) = myInDesign.
Selection.Item(myCounter).Graphics.Item(1)
End If
End Select
Next
If Not (IsEmpty(myObjectList(0))) Then
myDisplayDialog myInDesign, myObjectList
End If
End If
End Function
Rem Function that adds the label.
Function myAddLabel(myInDesign, myGraphic, myLabelType, myLabelHeight, myLabelOffset,
myLabelStyleName, myLayerName)
Set myDocument = myInDesign.documents.Item(1)
myLabelStyle = myDocument.paragraphStyles.item(myLabelStyleName)
Set myLink = myGraphic.ItemLink
Rem Create the label layer if it does not already exist.
On Error Resume Next
Set myLabelLayer = myDocument.layers.item(myLayerName)
If Err.Number <> 0 Then
Set myLabelLayer = myDocument.Layers.Add
myLabelLayer.Name = myLayerName
Err.Clear
End If
On Error Goto 0
Rem Label type defines the text that goes in the label.
Select Case myLabelType
Rem File name
case 0:
myLabel = myLink.Name
Rem File path
case 1:
myLabel = myLink.FilePath
Rem XMP description
case 2:
On Error Resume Next
myLabel = myLink.LinkXmp.Description
If Err.Number <> 0 Then
myLabel = "No description available."
Err.Clear
End If
On Error Goto 0
Rem XMP author
case 3:
On Error Resume Next
myLabel = myLink.LinkXmp.Author
151
第 9 章 メニュー
さらに複雑なメニュースクリプティングの例
If Err.Number <> 0 Then
myLabel = "No author available."
Err.Clear
End If
On Error Goto 0
End Select
Set myFrame = myGraphic.Parent
myBounds = myFrame.GeometricBounds
myX1 = myBounds(1)
myY1 = myBounds(2) + myLabelOffset
myX2 = myBounds(3)
myY2 = myY1 + myLabelHeight
Set myTextFrame = myFrame.Parent.TextFrames.Add(myLabelLayer)
myTextFrame.GeometricBounds = Array(myY1, myX1, myY2, myX2)
myTextFrame.Contents = myLabel
myTextFrame.TextFramePreferences.FirstBaselineOffset =
idFirstBaseline.idLeadingOffset
myTextFrame.Paragraphs.Item(1).AppliedParagraphStyle =
myInDesign.Documents.Item(1).ParagraphStyles.Item(myLabelStyle)
End Function
Function myDisplayDialog(myInDesign, myObjectList)
myLabelWidth = 100
myStyleNames = myGetParagraphStyleNames(myInDesign.Documents.Item(1))
myLayerNames = myGetLayerNames(myInDesign.Documents.Item(1))
Set myDialog = myInDesign.Dialogs.Add
myDialog.Name = "LabelGraphics"
With myDialog.DialogColumns.Add
Rem Label type
With .DialogRows.Add
With .DialogColumns.Add
With .StaticTexts.add
.StaticLabel = "Label Type"
.MinWidth = myLabelWidth
End With
End With
With .DialogColumns.Add
Set myLabelTypeDropdown = .Dropdowns.Add
myLabelTypeDropdown.StringList = Array("File name", "File path",
"XMP description", "XMP author")
myLabelTypeDropdown.SelectedIndex = 0
End With
End With
Rem Text frame height
With .DialogRows.Add
With .DialogColumns.Add
With .StaticTexts.add
.StaticLabel="Label Height"
.MinWidth=myLabelWidth
End With
End With
With .DialogColumns.Add
Set myLabelHeightField = .MeasurementEditboxes.Add
myLabelHeightField.EditValue = 24
myLabelHeightField.EditUnits = idMeasurementUnits.idPoints
End With
End With
Rem Text frame offset
With .DialogRows.Add
With .DialogColumns.Add
With .staticTexts.add
.staticLabel="Label Offset"
.minWidth=myLabelWidth
End With
End With
With .DialogColumns.Add
Set myLabelOffsetField = .MeasurementEditboxes.Add
152
第 9 章 メニュー
さらに複雑なメニュースクリプティングの例
myLabelOffsetField.editValue=0
myLabelOffsetField.editUnits=idMeasurementUnits.idPoints
End With
End With
Rem Style to apply
With .DialogRows.Add
With .DialogColumns.Add
With .StaticTexts.Add
.StaticLabel="Label Style"
.MinWidth=myLabelWidth
End With
End With
With .DialogColumns.Add
Set myLabelStyleDropdown = .Dropdowns.Add
myLabelStyleDropdown.StringList=myStyleNames
myLabelStyleDropdown.SelectedIndex=0
End With
End With
Rem Layer
With .DialogRows.Add
With .DialogColumns.Add
With .StaticTexts.Add
.StaticLabel="Layer"
.MinWidth=myLabelWidth
End With
End With
With .DialogColumns.Add
Set myLayerDropdown = .Dropdowns.Add
myLayerDropdown.StringList=myLayerNames
myLayerDropdown.SelectedIndex=0
End With
End With
End With
myResult = myDialog.show
If myResult = True Then
myLabelType = myLabelTypeDropdown.selectedIndex
myLabelHeight = myLabelHeightField.editValue
myLabelOffset = myLabelOffsetField.editValue
myLabelStyle = myStyleNames(myLabelStyleDropdown.selectedIndex)
myLayerName = myLayerNames(myLayerDropdown.selectedIndex)
myDialog.Destroy
myOldXUnits = myInDesign.documents.item(1).viewPreferences.
horizontalMeasurementUnits
myOldYUnits = myInDesign.documents.item(1).viewPreferences.
verticalMeasurementUnits
myInDesign.documents.item(1).viewPreferences.horizontalMeasurementUnits
= idMeasurementUnits.idPoints
myInDesign.documents.item(1).viewPreferences.verticalMeasurementUnits =
idMeasurementUnits.idPoints
for myCounter = 0 To UBound(myObjectList)
Set myGraphic = myObjectList(myCounter)
myAddLabel myInDesign, myGraphic, myLabelType, myLabelHeight,
myLabelOffset, myLabelStyle, myLayerName
Next
myInDesign.documents.item(1).viewPreferences.horizontalMeasurementUnits
= myOldXUnits
myInDesign.documents.item(1).viewPreferences.verticalMeasurementUnits =
myOldYUnits
Else
myDialog.Destroy
End If
End Function
153
10
プリフライトの操作
章の更新ステータス
CS6
変更なし
プリフライトを実行すると、パブリケーションを出力デバイスに送る前に、ファイルやフォント、アセット
(配置画像や PDF ファイルなど)、プリンター設定、トラップスタイルなど、必要なものがすべてそろってい
るかどうかを検証できます。例えば、画像を低解像度プロキシで配置しているが、使用中のハードディスク
(またはワークグループのサーバー)で高解像度の元の画像にアクセスできない場合、プリント処理時にエ
ラーが発生することがあります。プリフライトは、このような問題を検証します。プリフライトは、ユー
ザーの作業中にバックグラウンドで実行できます。
この章では、スクリプトを使用して、インタラクティブにプリフライトシステムを操作する方法について説
明します。説明のため、ページサイズがレターサイズ(8.5" x 11")以外のときにエラーを発生させるように、
プリフライトを設定する方法を紹介します。ユーザーインターフェイスでの設定方法を簡単に紹介し、その
後でスクリプトを使用して同じ設定を行う方法について説明します。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。
プリフライトプロファイルの調査
InDesign のプリフライト機能は、プロファイルベースで、ルールに従って実行されます。また、パラメー
ターを使用します。プリフライトプロファイルは、1 つ以上存在します。最初は、[ 基本 ] という名前のプロ
ファイルが 1 つ用意されています。このプロファイルは読み取り専用で、変更したり削除したりできません。
プリフライトプロファイルには、様々なプリフライトルールが含まれています。各ルールは、名前と複数の
データオブジェクトを保持しています。各データオブジェクトには、名前、データ型、データ値があります。
データ値は変更することができます。各ルールは、次のように設定できます。

無効 — プリフライトルールは無効化されます。

エラーを返す — プリフライトルールは、エラーレベルのフィードバックを返します。

警告を返す — プリフライトルールは、警告レベルのフィードバックを返します。

通知を返す — プリフライトルールは、通知レベルのフィードバックを返します。
InDesign でプロファイルを確認するには、プリフライトパネル/プロファイルを定義を選択します。また、
スクリプトでもプロファイル情報を取得できます。
154
第 10 章 プリフライトの操作
プリフライトプロファイルの調査
155
プリフライトプロファイルの一覧表示
すべてのプリフライトプロファイルを一覧表示する方法を、次のスクリプトに示します。完全なスクリプト
については、ListPreflightProfiles を参照してください。
Set profiles = myInDesign.PreflightProfiles
profileCount = profiles.Count
str = "Preflight profiles: "
For i = 1 To profileCount
If i > 1 Then
str = str & ", "
End If
str = str & profiles.Item(i).Name
Next
MsgBox(str)
プリフライトルールの一覧表示
プロファイル内のすべてのプリフライトルールを一覧表示する方法を、次のスクリプトに示します。完全な
スクリプトについては、ListPreflightRules を参照してください。
Rem Assume the [Basic] profile exists
Set myProfile = myInDesign.PreflightProfiles.Item(1)
Set myRules = myProfile.PreflightProfileRules
ruleCount = myRules.Count
str = "Preflight rules of " & myProfile.Name + ": "
For i = 1 To ruleCount
If i > 1 Then
str = str & ", "
End If
str = str & myRules.Item(i).Name
Next
MsgBox(str)
プリフライトデータオブジェクトの一覧表示
プロファイルのルール内のすべてのプリフライトデータオブジェクトを一覧表示する方法を、次のスクリプ
トに示します。完全なスクリプトについては、ListPreflightDataObjects を参照してください。
Rem Assume the [Basic] profile exists
Set myProfile = myInDesign.PreflightProfiles.Item(1)
Rem rule ADBE_BlankPages
Set myRule = myProfile.PreflightProfileRules.Item(1)
Set dataObjects = myRule.ruleDataObjects
dataObjectCount = dataObjects.Count
str = "Preflight rule data objects of " & myProfile.Name + "." + myRule.Name + ": "
For i = 1 To dataObjectCount
If i > 1 Then
str = str & "; "
End If
Set dataObject = dataObjects.Item(i)
str = str & dataObject.Name & ", "
str = str & getDataObjectDataType(dataObject.dataType) & ", "
str = str & dataObject.dataValue
Next
MsgBox(str)
Function getDataObjectDataType(dataType)
If dataType = idRuleDataType.idBooleanDataType Then
第 10 章 プリフライトの操作
プリフライトプロファイルの読み込み
156
getDataObjectDataType = "Boolean"
Elseif dataType = idRuleDataType.idIntegerDataType Then
getDataObjectDataType = "Integer"
Elseif dataType = idRuleDataType.idListDataType Then
getDataObjectDataType = "List"
Elseif dataType = idRuleDataType.idObjectDataType Then
getDataObjectDataType = "Object"
Elseif dataType = idRuleDataType.idRealDataType Then
getDataObjectDataType = "Real"
Elseif dataType = idRuleDataType.idShortIntegerDataType Then
getDataObjectDataType = "Short Integer"
Elseif dataType = idRuleDataType.idStringDataType Then
getDataObjectDataType = "String"
End If
End Function
プリフライトプロファイルの読み込み
プリフライトパネルからプリフライトプロファイルを読み込むには、プリフライトパネル/プロファイルを
定義を選択します。続いて、プリフライトプロファイルウィンドウのドロップダウンメニューで「プロファ
イルを読み込み」を選択します。
また、スクリプトでプロファイルを読み込むこともできます。次のスクリプトでは、Test という名前のプロ
ファイルを読み込みます。完全なスクリプトについては、ImportPreflightProfile を参照してください。
Set myProfile = myInDesign.LoadPreflightProfile("c:¥Test.idpp")
MsgBox("Preflight profile " & myProfile.Name & " is loaded.")
第 10 章 プリフライトの操作
プリフライトプロファイルの作成
157
プロファイルの作成には、スクリプトよりもプリフライトパネルを使用したほうが簡単です。1 つのワークフ
ローとしては、ユーザーインターフェイスですべてのプロファイルを作成し、プロファイルをファイルに書
き出し、書き出したファイルをスクリプトで読み込むといった流れが考えられます。この方法を使用すると、
スクリプトを使用して手動でルールを追加する手間を省くことできます。
プリフライトプロファイルの作成
プリフライトパネルからプリフライトプロファイルを作成するには、プリフライトパネル/プロファイルを
定義を選択し、プラス記号(+)を選択して新しいプリフライトプロファイルを追加します。プロファイルに
名前を付け、使用可能なルールのデータ値をすべて入力します。
また、スクリプトでプロファイルを作成することもできます。次のスクリプトでは、Test という名前のプロ
ファイルを 1 つ追加します。完全なスクリプトについては、CreatePreflightProfile を参照してください。
Set myProfile = myInDesign.PreflightProfiles.Add()
myProfile.Name = "Test"
myProfile.Description = "Test description"
MsgBox("Preflight profile " & myProfile.Name & " is created.")
プリフライトプロファイルの名前は、一意である必要があります。このスクリプトを同じインスタンスの
InDesign で 2 回以上実行すると、エラーが発生し、該当する名前のプロファイルは既に存在していると通知
されます。この問題を回避するには、app.preflightProfiles.itemByName() を使用して既存のプロファイル
にアクセスするか、プロファイルが存在するかどうかを確認して削除します。次のスクリプトにその例を示
します。完全なスクリプトについては、DeletePreflightProfile を参照してください。
第 10 章 プリフライトの操作
ルールの追加
158
Function removeProfile(myInDesign, profileName)
Set myProfiles= myInDesign.PreflightProfiles
profileCount = myProfiles.Count
For i = 1 To profileCount
If (myProfiles.Item(i).Name = profileName) Then
myProfiles.Item(i).Delete()
End If
Next
End Function
ルールの追加
プリフライトプロファイルには、相互排他的なルール一式が含まれます。プロファイルにルールを追加する
には、次の手順に従います。
1.
プロファイルに、名前による指定方式でルールを追加します。
名前による指定方式でルールが追加されます。 ルール名について詳しくは、160 ページの「使用可能な
ルール」を参照してください。次のスクリプトでは、プロファイルに ADBE_PageSizeOrientation のルール
を追加しています。
Rem Add a rule that requires a specific page size and orientation
Rem (portrait or landscape).
const RULE_NAME = "ADBE_PageSizeOrientation"
Set myRule = myProfile.PreflightProfileRules.Add(RULE_NAME)
2.
ルールのデータ値を設定します。
すべてではありませんが、多くのルールにはデータプロパティが含まれています。InDesign で使用可能な
ルールの完全な仕様について詳しくは、160 ページの「使用可能なルール」を参照してください。
ADBE_PageSizeOrientation のルールには、固有のデータプロパティが含まれており、このプロパティでは
ページサイズを指定できます。次のスクリプトでは、許可するページの高さと幅、許容範囲(誤差)、
ページ方向の処理オプションを設定しています。
Rem Requires the page size to be 8.5in x 11in (Letter Size)
Rem enters a value for tolerance
myRule.RuleDataObjects.Add "tolerance", idRuleDataType.idRealDataType, 0.01
Rem Sets the width to the point equivalent of 8.5 inches
myRule.RuleDataObjects.Add "width", idRuleDataType.idRealDataType, 612
Rem Sets the width to the point equivalent of 11 inches
myRule.RuleDataObjects.Add "height", idRuleDataType.idRealDataType, 792
Rem true = ignore orientation is checked
myRule.RuleDataObjects.Add "ignore_orientation", idRuleDataType.idBooleanDataType, true
3.
ルールのレポート状態を設定します。
この設定を行うには、ルールの flag プロパティを使用します。いくつかの選択肢(無効、通知、警告、
エラー)があり、この選択肢は PreflightRuleFlag 列挙法で制御されます。
Rem set the rule to return an error
myRule.Flag = idPreflightRuleFlag.idReturnAsError
第 10 章 プリフライトの操作
プロファイルの処理
159
プロファイルの処理
デスクトップ版の InDesign では、プリフライトエラーはユーザーインターフェイスでレポートされます。
(特に InDesign Server の)スクリプトでは、エラーは必要に応じて生成されます。次のスクリプトでは、
InDesign ドキュメントに対する処理を行います (完全なスクリプトについては、ProcessPreflightProfile を参
照してください)。エラーが発生した場合は、新しい PDF ファイルにエラー結果が書き込まれます。出力結果
の例については、スクリプトの後のスクリーンショットを参照してください。
Rem
Set
Rem
Set
Assume there is an document.
myDoc = myInDesign.Documents.Item(1)
Use the second preflight profile
myProfile = myInDesign.PreflightProfiles.Item(2)
Rem Process the doc with the rule
Set myProcess = myInDesign.PreflightProcesses.Add(myDoc, myProfile)
myProcess.WaitForProcess()
results = myProcess.ProcessResults
Rem If Errors were found
If results <> "None" Then
Rem Export the file to PDF. The "true" value selects to open the file after export.
myProcess.SaveReport("c:¥PreflightResults.pdf")
End If
Rem Cleanup
myProcess.Delete()
テキストファイルでの作成が望ましい場合は、単純に、出力ファイルの名前に .txt の拡張子を付けます。
また、エラーに対する繰り返し処理をユーザー自身が行いたい場合も考えられます。エラー配列にアクセス
する方法を、次のスクリプトに示します。完全なスクリプトについては、ProcessPreflightProfileShowErrors を
参照してください。
第 10 章 プリフライトの操作
カスタムルール
160
Rem If errors were found
If myResults <> "None" Then
Rem array containing detailed results
errors = myProcess.AggregatedResults
Rem Show the errors in a message box.
str = "Document Name: " & errors(0) & ", Profile Name: " & errors(1) & ", Results: ["
errorResults = errors(2)
For i = 0 to UBound(errorResults)
If i > 1 Then
str = str & ", "
End If
str = str & errorResults(i)(1)
Next
str = str & "]"
MsgBox(str)
End If
カスタムルール
プリフライトパネルやスクリプトからはカスタムルールを作成できません。ただし、C++ プラグインを使用
すると、カスタムルールを作成することができます。InDesign Products SDK にはサンプルの PreflightRule が含
まれおり、この中に、プラグインを使用してカスタムルールを追加する方法が示されています。
使用可能なルール
スクリプトでルールを使用する際に苦労する点は、ルールの名前とプロパティを把握しておくことです。
ルールの動的な性質上(ルールは実際には単なる文字列であるため)、ルールの具体的な名前とプロパティは
ExtendScript Toolkit のオブジェクトモデルビューアに表示されません。これらの情報を確認する方法について
詳しくは、154 ページの「プリフライトプロファイルの調査」を参照してください。ご参考までに、SDK には
DumpPreflightRules.jsx スクリプトが用意されています。このスクリプトは、次のような出力の HTML ファ
イルを作成します(SDK¥docs¥references¥PreflightRules.html)
。カスタムルールを追加するプラグインを使用
している場合、スクリプトを実行して新しい名前とプロパティを取得できます。
ルール名
ルールのプロパティ
ADBE_BlankPages
161 ページの「ADBE_BlankPages」
ADBE_BleedSlug
161 ページの「ADBE_BleedSlug」
ADBE_BleedTrimHazard
162 ページの「ADBE_BleedTrimHazard」
ADBE_CMYPlates
なし
ADBE_Colorspace
163 ページの「ADBE_Colorspace」
ADBE_ConditionIndicators
なし
ADBE_CrossReferences
163 ページの「ADBE_CrossReferences」
ADBE_FontUsage
163 ページの「ADBE_FontUsage」
ADBE_ImageColorManagement
163 ページの「ADBE_ImageColorManagement」
ADBE_ImageResolution
164 ページの「ADBE_ImageResolution」
ADBE_InteractiveContent
なし
ADBE_LayerVisibility
なし
ADBE_MissingFonts
なし
第 10 章 プリフライトの操作
使用可能なルール
ルール名
ルールのプロパティ
ADBE_MissingGlyph
なし
ADBE_MissingModifiedGraphics
なし
ADBE_OPI
なし
ADBE_Overprint
なし
ADBE_OversetText
なし
ADBE_PageCount
164 ページの「ADBE_PageCount」
ADBE_PageSizeOrientation
164 ページの「ADBE_PageSizeOrientation」
ADBE_Registration
なし
ADBE_ScaledGraphics
165 ページの「ADBE_ScaledGraphics」
ADBE_ScaledType
165 ページの「ADBE_ScaledType」
ADBE_SmallText
165 ページの「ADBE_SmallText」
ADBE_SpellCheck
なし
ADBE_SpotColorSetup
165 ページの「ADBE_SpotColorSetup」
ADBE_StrokeRequirements
165 ページの「ADBE_StrokeRequirements」
ADBE_TextOverrides
166 ページの「ADBE_TextOverrides」
ADBE_TransparencyBlending
166 ページの「ADBE_TransparencyBlending」
ADBE_TransparencyUsage
なし
ADBE_WhiteOverprint
なし
ADBE_BlankPages
データ型
名前
デフォルト値
Boolean
ignore_master
true
Boolean
ignore_nonprinting
true
データ型
名前
デフォルト値
Real
bleed_b
9
Real
bleed_b_aux
9
Integer
bleed_comparison_type
3
Boolean
bleed_enabled
true
Real
bleed_l
9
ADBE_BleedSlug
161
第 10 章 プリフライトの操作
使用可能なルール
データ型
名前
デフォルト値
Real
bleed_l_aux
9
Real
bleed_r
9
Real
bleed_r_aux
9
Real
bleed_t
9
Real
bleed_t_aux
9
Real
slug_b
18
Real
slug_b_aux
18
Integer
slug_comparison_type
3
Boolean
slug_enabled
false
Real
slug_l
18
Real
slug_l_aux
18
Real
slug_r
18
Real
slug_r_aux
18
Real
slug_t
18
Real
slug_t_aux
18
Real
tolerance
0.01
データ型
名前
デフォルト値
Boolean
binding_enabled
false
Real
binding_width
1
Real
live_b
18
Real
live_l
18
Real
live_r
18
Real
live_t
18
Real
tolerance
0.01
ADBE_BleedTrimHazard
162
第 10 章 プリフライトの操作
使用可能なルール
ADBE_Colorspace
データ型
名前
デフォルト値
Boolean
no_cmyk
false
Boolean
no_gray
false
Boolean
no_lab
false
Boolean
no_rgb
false
Boolean
no_spot
false
データ型
名前
デフォルト値
Boolean
xrefs_out_of_date
true
Boolean
xrefs_unresolved
true
データ型
名前
デフォルト値
Boolean
no_ATC
false
Boolean
no_Bitmap
false
Boolean
no_CID
false
Boolean
no_MultipleMaster
false
Boolean
no_OpenTypeCFF
false
Boolean
no_OpenTypeCID
false
Boolean
no_OpenTypeTT
false
Boolean
no_TrueType
false
Boolean
no_Type1
false
Boolean
no_protected
true
ADBE_CrossReferences
ADBE_FontUsage
ADBE_ImageColorManagement
データ型
名前
デフォルト値
Boolean
no_cmyk_profiles
true
Boolean
no_image_overrides
true
Boolean
overrides_exclude_uncal
true
163
第 10 章 プリフライトの操作
使用可能なルール
ADBE_ImageResolution
データ型
名前
デフォルト値
Boolean
bw_max_enabled
false
Real
bw_max_res
2400
Boolean
bw_min_enabled
true
Real
bw_min_res
800
Boolean
color_max_enabled
false
Real
color_max_res
1200
Boolean
color_min_enabled
true
Real
color_min_res
250
Boolean
gray_max_enabled
false
Real
gray_max_res
1200
Boolean
gray_min_enabled
true
Real
gray_min_res
250
Real
tolerance
0.5
データ型
名前
デフォルト値
Integer
comparison_type
2
Integer
comparison_value
1
Integer
comparison_value_aux
1
データ型
名前
デフォルト値
Real
height
792
Boolean
ignore_orientation
false
Real
tolerance
0.01
Real
width
612
ADBE_PageCount
ADBE_PageSizeOrientation
164
第 10 章 プリフライトの操作
使用可能なルール
ADBE_ScaledGraphics
データ型
名前
デフォルト値
Real
max_scale
100.5
データ型
名前
デフォルト値
Boolean
ignore_justification
true
Real
max_scale
100.5
データ型
名前
デフォルト値
Real
minSize
4
Boolean
minSize_trap_safe_only
false
データ型
名前
デフォルト値
Boolean
lab_spots
true
Boolean
lab_spots_enabled
false
Integer
max_spots
1
Boolean
max_spots_enabled
true
データ型
名前
デフォルト値
Real
min_width
0.125
Boolean
min_width_trap_safe_only
false
ADBE_ScaledType
ADBE_SmallText
ADBE_SpotColorSetup
ADBE_StrokeRequirements
165
第 10 章 プリフライトの操作
使用可能なルール
ADBE_TextOverrides
データ型
名前
デフォルト値
Boolean
ignore_color_overrides
false
Boolean
ignore_font_overrides
false
Boolean
ignore_kerning_tracking_overrides
false
Boolean
ignore_language_overrides
false
ADBE_TransparencyBlending
データ型
名前
デフォルト値
Integer
space
3
166
ダイナミックドキュメントの作成
11
章の更新ステータス
CS6
変更なし
InDesign では、Web やオンラインで使用するドキュメントを作成できます。これは、Rich Interactive
Document(RID)とも呼びます。ダイナミックドキュメントには、サウンド、アニメーション、ハイパーリ
ンクなどインタラクティブなコンテンツが含まれます。InDesign ドキュメントは、SWF や XFL、PDF に書き出
すことができます。SWF および XFL ファイルの場合は、ドキュメントにアニメーション、ボタン、マルチス
テートオブジェクト、ムービー、サウンドクリップを含めることができます。InDesign のプレビューパネル
を使用すると、書き出す前に、いくつかの種類のダイナミックコンテンツをテストすることができます。
この章では、スクリプトを使用してダイナミックドキュメントを作成する方法について説明します。PDF、
SWF および XFL 形式で書き出す方法について詳しくは、ユーザーガイドの「ドキュメントを使用した作業」
の章を参照してください。
ムービーとサウンドの読み込み
InDesign では、ムービーファイルやサウンドファイルを読み込み、書き出し後の PDF、SWF、XFL ドキュメン
トで表示したり再生したりすることができます。InDesign ドキュメント内のムービーとサウンドは、InDesign
ページ上のコンテナオブジェクトに含まれるという点でグラフィックによく似ています。ただし、グラ
フィックとは異なり、読み込んだマルチメディアファイルのコンテンツは InDesign ページ上で表示(または
再生)できません。ファイルを表示するには、プレビューパネルでページを表示するか、ファイルを書き出
してコンテンツを表示可能なビューア(Adobe Reader や Web ブラウザーなど)でそのファイルを開く必要が
あります。
スクリプトを使用して、書き出し後のダイナミックドキュメント内のサウンドやムービーの再生プロパティ
を制御できます。また、サウンドやムービーが含まれているページアイテムに、プレビュー画像(「ポス
ター」画像)を追加することもできます。
ムービーを読み込み、書き出し後のドキュメントのムービーの表示と再生仕様を制御する方法を、次のスク
リプトに示します(完全なスクリプトについては、PlaceMovie を参照してください)。
Rem Given a page "myPage"...
Set myFrame = myPage.Rectangles.Add
myFrame.GeometricBounds = Array(72, 72, 288, 288)
Rem Import a movie file (you'll have to provide a valid file path on your system)
Set myMovie = myFrame.Place("c:¥movie.avi").item(1)
Rem Set movie properties.
myMovie.EmbedInPDF = True
myMovie.ShowControls = True
Rem Add a preview image. You'll have to provide a valid path on your system.
myMovie.PosterFile = "c:¥movie poster.jpg"
サウンドファイルを読み込み、書き出し後のドキュメントのサウンドの再生と表示を制御する方法を、次の
スクリプトに示します(完全なスクリプトについては、PlaceSound を参照してください)。
167
第 11 章 ダイナミックドキュメントの作成
ボタンの作成
168
Rem Given a page "myPage"...
Rem Import a sound file (you'll have to provide a valid file path on your system)
Set mySound = myPage.Place("c:¥sound.mp3", Array(72, 72)).Item(1)
Rem Set sound properties.
mySound.EmbedInPDF = True
mySound.DoNotPrintPoster = True
mySound.SoundLoop = True
mySound.StopOnPageTurn = True
Rem Add a preview image. You'll have to provide a valid path on your system.
mySound.PosterFile = "c:¥sound poster.jpg"
ボタンを使用して、サウンドやムービーの再生を制御することもできます。スクリプトでボタンを操作する
方法について詳しくは、次の節を参照してください。
ボタンの作成
ボタンは多くの場合、ダイナミックドキュメントでのナビゲーションに使用します。ボタンには、「通常」、
「ロールオーバー」、「クリック」の 3 つのステートが含まれていますが、さらに、ページアイテム(長方形、
楕円形、テキストフレーム、画像など)を含めることもできます。ボタンは一度に 1 つのステートしか表示
できません。その他のステートは、マウスアクションによって呼び出されたときに表示されます。
動作は、ユーザーが特定のマウスアクションを実行したときに、ボタンがどのように反応するかを制御しま
す。動作は、InDesign のユーザーインターフェイスのボタンパネルに表示されるアクションに対応します。ボ
タンには、複数の動作を含めることができます。
書き出し後の PDF または SWF で次のページを表示する簡単なボタンを作成する方法を、次のスクリプトに示
します(完全なスクリプトについては、SimpleButton を参照してください)。このボタンでは、「通常」ス
テートのみを使用しています。
Rem Given a page "myPage" and a document containing the color "Red"...
Rem Make a button by converting a page item.
Set myRightArrow = myPage.Polygons.Add
myRightArrow.fillColor = myDocument.Colors.Item("Red")
myRightArrow.name = "GoToNextPageButton"
myRightArrow.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(144, 108), Array(72, 144))
Set myButton = myPage.Buttons.Add
myButton.geometricBounds = Array(72, 72, 144, 144)
myButton.States.Item(1).AddItemsToState myRightArrow
Set myGoToNextPageBehavior = myButton.GotoNextPageBehaviors.Add
myGoToNextPageBehavior.behaviorEvent = idBehaviorEvents.idMouseUp
3 種類の各ボタンステートの外観を変更するページアイテムが含まれた、もう少し複雑なボタンを作成する
方法を、次のスクリプトに示します (完全なスクリプトについては、ButtonStates を参照してください)。
第 11 章 ダイナミックドキュメントの作成
ボタンの作成
169
Rem Given a page "myPage" in a document "myDocument," containing the colors
Rem "Blue" and "Red"...
Rem Make a button "from scratch."
Set myButton = myPage.Buttons.Add
myButton.GeometricBounds = Array(72, 72, 144, 144)
myButton.Name = "GoToNextPageButton"
Set myRightArrow = myButton.States.Item(1).Polygons.Add
myRightArrow.fillColor = myDocument.Colors.Item("Red")
myRightArrow.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(144, 108), Array(72, 144))
Rem Add the Rollover state.
Set myRolloverState = myButton.States.Add
Rem Add a shadow to the polygon in the Rollover state.
Set myRolloverArrow = myRolloverState.Polygons.Add
myRolloverArrow.FillColor = myDocument.Colors.Item("Red")
myRolloverArrow.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(144, 108), Array(72, 144))
Set myFillTransparencySettings = myRolloverArrow.FillTransparencySettings
myFillTransparencySettings.DropShadowSettings.Mode = idShadowMode.idDrop
myFillTransparencySettings.DropShadowSettings.Angle = 90
myFillTransparencySettings.DropShadowSettings.XOffset = 0
myFillTransparencySettings.DropShadowSettings.YOffset = 0
myFillTransparencySettings.DropShadowSettings.Size = 6
Rem Add a shadow to the polygon in the Click state.
Set myClickState = myButton.States.Add
Set myClickArrow = myClickState.Polygons.Add
myClickArrow.FillColor = myDocument.Colors.Item("Blue")
myClickArrow.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(144, 108), Array(72, 144))
Rem Set the behavior for the button.
Set myGoToNextPageBehavior = myButton.GotoNextPageBehaviors.Add
myGoToNextPageBehavior.BehaviorEvent = idBehaviorEvents.idMouseUp
ボタンを使用して、ムービーファイルやサウンドファイルの再生を制御することもできます。ムービーファ
イルの再生を制御するボタン一式を使用した例を、次のスクリプトに示します(完全なスクリプトについて
は、MovieControl を参照してください)。
Rem Given a page "myPage" in a document "myDocument,"
Rem containing the colors "Gray" and "Red"...
Set myFrame = myPage.Rectangles.Add
myFrame.geometricBounds = Array(72, 72, 288, 288)
Rem Import a movie file (you'll have to provide a valid file path on your system)
myFrame.Place "c:¥movie.avi"
Rem Create the movie "Start" button.
Set myPlayButton = myPage.Buttons.Add
myPlayButton.geometricBounds = Array(294, 186, 354, 282)
myPlayButton.name = "PlayMovieButton"
Set myRightArrow = myPlayButton.States.Item(1).Polygons.Add
myRightArrow.fillColor = myDocument.Colors.Item("Gray")
myRightArrow.Paths.Item(1).EntirePath = Array(Array(186, 294), Array(186, 354), Array(282, 324))
Rem Add the Rollover state.
Set myRolloverState = myPlayButton.States.Add
Rem Add a shadow to the polygon in the Rollover state.
Set myRolloverArrow = myRolloverState.Polygons.Add
myRolloverArrow.fillColor = myDocument.Colors.Item("Gray")
myRolloverArrow.Paths.Item(1).EntirePath = Array(Array(186, 294), Array(186, 354), Array(282,
324))
Set myFillTransparencySettings = myRolloverArrow.FillTransparencySettings
myFillTransparencySettings.DropShadowSettings.Mode = idShadowMode.idDrop
myFillTransparencySettings.DropShadowSettings.Angle = 90
myFillTransparencySettings.DropShadowSettings.XOffset = 0
myFillTransparencySettings.DropShadowSettings.YOffset = 0
myFillTransparencySettings.DropShadowSettings.Size = 6
Rem Add a shadow to the polygon in the Click state.
set myClickState = myPlayButton.States.Add()
Set myClickArrow = myClickState.Polygons.Add
myClickArrow.fillColor = myDocument.Colors.Item("Red")
myClickArrow.Paths.Item(1).EntirePath = Array(Array(186, 294), Array(186, 354), Array(282, 324))
Rem Set the behavior for the button.
第 11 章 ダイナミックドキュメントの作成
マルチステートオブジェクトの作成
170
Set myMovieStartBehavior = myPlayButton.MovieBehaviors.Add
myMovieStartBehavior.MovieItem = myFrame.Movies.Item(1)
myMovieStartBehavior.behaviorEvent = idBehaviorEvents.idMouseUp
myMovieStartBehavior.operation = idMoviePlayOperations.idPlay
Rem Create the movie "Stop" button.
Set myStopButton = myPage.Buttons.Add
myStopButton.geometricBounds = Array(294, 78, 354, 174)
myStopButton.name = "StopMovieButton"
Set myNormalRectangle = myStopButton.States.Item(1).Rectangles.Add
myNormalRectangle.geometricBounds = Array(294, 78, 354, 174)
myNormalRectangle.fillColor = myDocument.Colors.Item("Gray")
Set myRolloverState = myStopButton.States.Add
Set myRolloverRectangle = myRolloverState.Rectangles.Add
myRolloverRectangle.geometricBounds = Array(294, 78, 354, 174)
myRolloverRectangle.fillColor = myDocument.Colors.Item("Gray")
Set myFillTransparencySettings = myRolloverRectangle.FillTransparencySettings
myFillTransparencySettings.DropShadowSettings.Mode = idShadowMode.idDrop
myFillTransparencySettings.DropShadowSettings.Angle = 90
myFillTransparencySettings.DropShadowSettings.XOffset = 0
myFillTransparencySettings.DropShadowSettings.YOffset = 0
myFillTransparencySettings.DropShadowSettings.Size = 6
Set myClickState = myStopButton.States.Add
Set myClickRectangle = myClickState.Rectangles.Add
myClickRectangle.geometricBounds = Array(294, 78, 354, 174)
myClickRectangle.fillColor = myDocument.Colors.Item("Red")
Set myMovieStopBehavior = myStopButton.MovieBehaviors.Add
myMovieStopBehavior.MovieItem = myFrame.Movies.Item(1)
myMovieStopBehavior.behaviorEvent = idBehaviorEvents.idMouseUp
myMovieStopBehavior.operation = idMoviePlayOperations.idStop
また、ボタンはマルチステートオブジェクトの外観を制御する場合に重要です。この点については、次の節
で説明します。
マルチステートオブジェクトの作成
マルチステートオブジェクト(MSO)は、複数のステートを含んでいる点と、一度に 1 つのステートしか表
示できない点がボタンに似ています。ボタンと異なる点は、マルチステートオブジェクトにはいくつでもス
テートを含めることができることです。ボタンには最大 3 つまでしかステートを含めることができません。
マルチステートオブジェクトは、ステートの表示方法を変更する場合はボタンに依存します。
簡単なマルチステートオブジェクトを作成し、このオブジェクトのステート表示を制御するボタンを追加す
る方法を、次のスクリプトに示します(完全なスクリプトについては、MakeMultiStateObject を参照してく
ださい)
。
第 11 章 ダイナミックドキュメントの作成
マルチステートオブジェクトの作成
171
Rem Given a document "myDocument" and a page "myPage" and
Rem four colors "myColorA," "myColorB," "myColorC," and "myColorD"...
Set myMSO = myPage.MultiStateObjects.Add
myMSO.name = "Spinner"
myMSO.geometricBounds = Array(72, 72, 144, 144)
Rem New multistate objects contain two states when they're created. Add two more.
myMSO.States.Item(1).name = "Up"
myMSO.States.Item(2).name = "Right"
Rem Add two more states.
Set myDownState = myMSO.States.Add
myDownState.name = "Down"
Set myLeftState = myMSO.States.Add
myLeftState.name = "Left"
Rem Add page items to the states.
Set myPolygon = myMSO.States.Item(1).Polygons.Add
myPolygon.fillColor = myColorA
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 144), Array(144, 144), Array(108, 72))
Set myPolygon = myMSO.States.Item(2).Polygons.Add
myPolygon.fillColor = myColorB
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144), Array(144, 108))
Set myPolygon = myMSO.States.Item(3).Polygons.Add
myPolygon.fillColor = myColorC
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(108, 144), Array(144, 72))
Set myPolygon = myMSO.States.Item(4).Polygons.Add
myPolygon.fillColor = myColorD
myPolygon.strokeColor = myDocument.Swatches.Item("None")
一般的に、マルチステートオブジェクトのステート表示を制御するには、ボタンを使用します。次のスクリ
プトにその例を示します(完全なスクリプトについては、MultiStateObjectControl を参照してください)。
Rem Given a document "myDocument" and a page "myPage" and
Rem four colors "myColorA," "myColorB," "myColorC," and "myColorD"...
Set myMSO = myPage.MultiStateObjects.Add
myMSO.name = "Spinner"
myMSO.geometricBounds = Array(72, 72, 144, 144)
Rem New multistate objects contain two states when they're created. Add two more.
myMSO.States.Item(1).name = "Up"
myMSO.States.Item(2).name = "Right"
Rem Add two more states.
Set myDownState = myMSO.States.Add
myDownState.name = "Down"
Set myLeftState = myMSO.States.Add
myLeftState.name = "Left"
Rem Add page items to the states.
Set myPolygon = myMSO.States.Item(1).Polygons.Add
myPolygon.fillColor = myColorA
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 144), Array(144, 144),
Array(108, 72))
Set myPolygon = myMSO.States.Item(2).Polygons.Add
myPolygon.fillColor = myColorB
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Set myPolygon = myMSO.States.Item(3).Polygons.Add
myPolygon.fillColor = myColorC
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(108, 144),
Array(144, 72))
Set myPolygon = myMSO.States.Item(4).Polygons.Add
myPolygon.fillColor = myColorD
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(144, 72), Array(72, 108),
第 11 章 ダイナミックドキュメントの作成
アニメーションの操作
172
Array(144, 144))
Set myButton = myPage.Buttons.Add
myButton.geometricBounds = Array(72, 72, 144, 144)
Rem var myNormalState = myButton.states.item(0)
Rem myNormalState.rectangles.add({geometricBounds:Array(72, 72, 144, 144)})
Set myRolloverState = myButton.States.Add
Set myRolloverRectangle = myRolloverState.Rectangles.Add
myRolloverRectangle.geometricBounds = Array(72, 72, 144, 144)
Set myFillTransparencySettings = myRolloverRectangle.StrokeTransparencySettings
myFillTransparencySettings.DropShadowSettings.Mode = idShadowMode.idDrop
myFillTransparencySettings.DropShadowSettings.Angle = 90
myFillTransparencySettings.DropShadowSettings.XOffset = 0
myFillTransparencySettings.DropShadowSettings.YOffset = 0
myFillTransparencySettings.DropShadowSettings.Size = 6
Set myClickState = myButton.States.Add
Set myNextStateBehavior = myButton.GotoNextStateBehaviors.Add
myNextStateBehavior.associatedMultiStateObject = myMSO
myNextStateBehavior.behaviorEvent = idBehaviorEvents.idMouseDown
myNextStateBehavior.enableBehavior = True
myNextStateBehavior.loopsToNextOrPrevious = True
アニメーションの操作
ページアイテムはアニメーション化することができます。アニメーション化するには、InDesign で作成した
ダイナミックドキュメントにモーションを追加します。オブジェクトにアニメーションを適用するにはモー
ションプリセットを、アニメーションオブジェクトの動作を定義するにはモーションパスを、アニメーショ
ンの長さを制御するにはタイミング設定、タイミングリスト、タイミンググループを使用します。
オブジェクトの AnimationSettings は、オブジェクトに適用されるアニメーションを制御します。オブジェ
クトにアニメーション設定が適用されている場合、オブジェクトの HasCustomSettings プロパティには true
が設定されます。オブジェクトがアニメーション化されない場合は、false が設定されます。
アニメーションの再生が開始される位置は、アニメーションを呼び出すイベントを基準に、ページアイテム
または親コンテナの 1 つ(通常はスプレッド)に割り当てられている TimingSettings オブジェクトのオブ
ジェクトとプロパティによって制御されます。
基本的なアニメーション
簡単なアニメーションの作成方法を、次のスクリプトに示します(完全なスクリプトについては、
SimpleAnimation を参照してください)。最も基本的な形式のアニメーションは、タイミング設定を使用せず
に適用することができます。
Rem Given a document "myDocument" and a page "myPage" and a color "myColorA"...
Rem Add a page item to animate.
Set myPolygon = myPage.Polygons.Add
myPolygon.fillColor = myColorA
myPolygon.strokeColor = myDocument.Swatches.Item("None")
myPolygon.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144), Array(144, 108))
Rem Create a motion path.
myMotionPathPoints = Array(Array(Array(Array(108, 108), Array(108, 108), Array(108, 108)),
Array(Array(516, 108), Array(516, 108), Array(516, 108))), True)
Rem Set animation preferences for the polygon. We havent' set a dynamic trigger
Rem for the animation, so the polygon's animation will be triggered by
Rem DynamicTriggerEvents.onPageLoad (the default).
myPolygon.AnimationSettings.Duration = 2
myPolygon.AnimationSettings.MotionPathPoints = myMotionPathPoints
第 11 章 ダイナミックドキュメントの作成
アニメーションの操作
173
タイミング設定
スプレッド、ページおよびページアイテムの TimingSettings オブジェクトは、そのオブジェクトや、そのオ
ブジェクトに含まれているすべてのオブジェクトに適用されるアニメーションのタイミングを制御します。
TimingSettings には、次のプロパティが含まれます。

TimingLists。アニメーションを開始するトリガーイベント(ページの読み込みやページのクリックな
ど)を定義します。

TimingGroups。1 つまたは複数のページアイテムを特定のタイミングに関連付けます。また、アニメー
ションが表示される順番を定義します。
TimingGroups には TimingTargets が含まれています。このプロパティは、特定の TimingGroup に関連付けら
れているオブジェクトを定義します。また、TimingTargets は、ページアイテムに適用されるアニメーショ
ンの遅延値も指定します。この値は、TimingGroup のアニメーションの開始に対する相対値で指定するか
(TimingGroup 内の最初のアイテムの場合)、TimingGroup 内の前のアイテムの開始からの値で指定します
(TimingGroup 内のその他のアイテムの場合)。
様々なタイミングオブジェクトを使用して、オブジェクトのアニメーションのタイミングを制御する方法を、
次のスクリプトに示します(完全なスクリプトについては、TimingSettings を参照してください)。
TimingGroup の作成に使用するパラメーターにより、TimingGroup 内の最初の TimingTarget のプロパティが
指定されます。続いて、(存在する場合は)TimingTargets を個別に追加できます。
Rem Given a document "myDocument" and a page "myPage" and the color "myColorA",
Rem "myColorB", and "myColorC"...
Rem Add a page items to animate.
Set myPolygonA = myPage.Polygons.Add
myPolygonA.fillColor = myColorA
myPolygonA.strokeColor = myDocument.Swatches.Item("None")
myPolygonA.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Set myPolygonB = myPage.Polygons.Add
myPolygonB.fillColor = myColorB
myPolygonB.strokeColor = myDocument.Swatches.Item("None")
myPolygonB.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Set myPolygonC = myPage.Polygons.Add
myPolygonC.fillColor = myColorC
myPolygonC.strokeColor = myDocument.Swatches.Item("None")
myPolygonC.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Rem Create a motion path.
myMotionPathPoints = Array(Array(Array(Array(108, 108), Array(108, 108), Array(108, 108)),
Array(Array(516, 108), Array(516, 108), Array(516, 108))), True)
Rem Set animation preferences for the polygons.
myPolygonA.AnimationSettings.Duration = 2
myPolygonA.AnimationSettings.MotionPathPoints = myMotionPathPoints
myPolygonB.AnimationSettings.Duration = 2
myPolygonB.AnimationSettings.MotionPathPoints = myMotionPathPoints
myPolygonC.AnimationSettings.Duration = 2
myPolygonC.AnimationSettings.MotionPathPoints = myMotionPathPoints
Set myTimingSettings = myPage.Parent.TimingSettings
Rem Remove the default timing list.
myTimingSettings.TimingLists.Item(1).Delete
Rem Add a new timing list that triggers when the page is clicked.
Set myTimingList = myTimingSettings.TimingLists.Add(idDynamicTriggerEvents.idOnPageClick)
Rem Add the polygons to a single timing group.
Set myTimingGroup = myTimingList.TimingGroups.Add(myPolygonA, 0)
myTimingGroup.TimingTargets.Add myPolygonB, 2
myTimingGroup.TimingTargets.Add myPolygonC, 2
(ページアイテムの AnimationSettings オブジェクトの)HasCustomSettings プロパティが false のページアイ
テムを TimingTarget に追加しようとすると、エラーが発生することに注意してください。
第 11 章 ダイナミックドキュメントの作成
アニメーションの操作
174
ページ上のオブジェクトに適用されるアニメーションの順番を制御する方法を、次のスクリプトに示します
(完全なスクリプトについては、MultipleTimingGroups を参照してください)。TimingList に TimingGroups が
追加された順番により、TimingList で指定されたトリガーイベントが発生したときのアニメーションの再生
順が決まります。一部のトリガーイベント(idDynamicTriggerEvents.idOnPageLoad など)は、TimingList
のアニメーションを(順番に)呼び出しますが、それ以外のトリガーイベント
(idDynamicTriggerEvents.idOnPageClick など)は、イベントの各インスタンスで 1 つずつ(順番に)アニ
メーションを呼び出します。例えば、idDynamicTriggerEvents.idOnPageClick のトリガーイベントが設定さ
れた TimingList に 5 つの TimingGroups が含まれ、それぞれに 1 つの TimingTarget が含まれている場合、す
べてのアニメーションを処理するにはマウスを 5 回クリックする必要があります。
Rem Given a document "myDocument" and a page "myPage" and the color "myColorA",
Rem "myColorB", and "myColorC"...
Rem Add a page items to animate.
Set myPolygonA = myPage.Polygons.Add
myPolygonA.fillColor = myColorA
myPolygonA.strokeColor = myDocument.Swatches.Item("None")
myPolygonA.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Set myPolygonB = myPage.Polygons.Add
myPolygonB.fillColor = myColorB
myPolygonB.strokeColor = myDocument.Swatches.Item("None")
myPolygonB.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Set myPolygonC = myPage.Polygons.Add
myPolygonC.fillColor = myColorC
myPolygonC.strokeColor = myDocument.Swatches.Item("None")
myPolygonC.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Set myPolygonD = myPage.Polygons.Add
myPolygonD.fillColor = myColorA
myPolygonD.strokeColor = myDocument.Swatches.Item("None")
myPolygonD.Paths.Item(1).EntirePath = Array(Array(72, 144), Array(72, 216),
Array(144, 180))
Set myPolygonE = myPage.Polygons.Add
myPolygonE.fillColor = myColorB
myPolygonE.strokeColor = myDocument.Swatches.Item("None")
myPolygonE.Paths.Item(1).EntirePath = Array(Array(72, 144), Array(72, 216),
Array(144, 180))
Set myPolygonF = myPage.Polygons.Add
myPolygonF.fillColor = myColorC
myPolygonF.strokeColor = myDocument.Swatches.Item("None")
myPolygonF.Paths.Item(1).EntirePath = Array(Array(72, 144), Array(72, 216),
Array(144, 180))
Rem Create a motion path.
myMotionPathPointsA = Array(Array(Array(Array(108, 108), Array(108, 108), Array(108, 108)),
Array(Array(516, 108), Array(516, 108), Array(516, 108))), True)
myMotionPathPointsB = Array(Array(Array(Array(108, 180), Array(108, 180), Array(108, 180)),
Array(Array(516, 180), Array(516, 180), Array(516, 180))), True)
Rem Set animation preferences for the polygons.
Rem DynamicTriggerEvents.onPageLoad (the default).
myPolygonA.AnimationSettings.Duration = 2
myPolygonA.AnimationSettings.MotionPathPoints = myMotionPathPointsA
myPolygonB.AnimationSettings.Duration = 2
myPolygonB.AnimationSettings.MotionPathPoints = myMotionPathPointsA
myPolygonC.AnimationSettings.Duration = 2
myPolygonC.AnimationSettings.MotionPathPoints = myMotionPathPointsA
myPolygonD.AnimationSettings.Duration = 2
myPolygonD.AnimationSettings.MotionPathPoints = myMotionPathPointsB
myPolygonE.AnimationSettings.Duration = 2
myPolygonE.AnimationSettings.MotionPathPoints = myMotionPathPointsB
myPolygonF.AnimationSettings.Duration = 2
第 11 章 ダイナミックドキュメントの作成
アニメーションの操作
175
myPolygonF.AnimationSettings.MotionPathPoints = myMotionPathPointsB
Set myTimingSettings = myPage.Parent.TimingSettings
Rem Remove the default timing list.
myTimingSettings.TimingLists.Item(1).Delete
Rem Add a new timing list that triggers when the page is clicked.
Set myTimingList = myTimingSettings.TimingLists.Add(idDynamicTriggerEvents.idOnPageClick)
Rem Add the polygons to a single timing group.
Set myTimingGroupA = myTimingList.TimingGroups.Add(myPolygonA, 0)
myTimingGroupA.TimingTargets.Add myPolygonB, 2
myTimingGroupA.TimingTargets.Add myPolygonC, 2
Rem myTimingGroupB will play on the second page click.
Set myTimingGroupB = myTimingList.TimingGroups.Add(myPolygonD, 0)
myTimingGroupB.TimingTargets.Add myPolygonE, 2
myTimingGroupB.TimingTargets.Add myPolygonF, 2
任意の TimingSettings オブジェクトに複数の TimingList オブジェクトを含めて、それぞれのオブジェクト
で別々のトリガーイベントに応答することができます。次のスクリプトでは、
idDynamicTriggerEvents.idOnPageLoad および idDynamicTriggerEvents.idOnPageClick によって呼び出され
た一連のアニメーションを表示します(完全なスクリプトについては、MultipleTimingLists を参照してくださ
い)
。
Rem Given a document "myDocument" and a page "myPage" containg 6 polygons:
Rem "myPolygonA", "myPolygonB", "myPolygonC", "myPolygonD", "myPolygonE", "myPolygonF".
Set myTimingSettings = myPage.Parent.TimingSettings
Rem At this point, all of the polygons have already been added as timing targets
Rem of the default timing list. Change the delay of myPolygonB and myPolygonC,
Rem which are the targets of the second and third timing groups (item(1) and item(2)).
Set myTimingListA = myTimingSettings.TimingLists.Item(1)
Set myTimingGroup = myTimingListA.TimingGroups.Item(1)
myTimingGroup.TimingTargets.Item(1).DelaySeconds = 2
Set myTimingGroup = myTimingListA.TimingGroups.Item(2)
myTimingGroup.TimingTargets.Item(1).DelaySeconds = 2
Rem Remove the last three timing groups in the timing list.
Rem We have to do this, because we don't want these polygons to be
Rem animated when the page loads.
myTimingListA.TimingGroups.Item(-1).Delete
myTimingListA.TimingGroups.Item(-1).Delete
myTimingListA.TimingGroups.Item(-1).Delete
Rem Add a new timing list that triggers when the page is clicked.
Set myTimingListB = myTimingSettings.TimingLists.Add(idDynamicTriggerEvents.idonPageClick)
Set myTimingGroupB = myTimingListB.TimingGroups.Add(myPolygonD, 0)
myTimingGroupB.TimingTargets.Add myPolygonE, 2
myTimingGroupB.TimingTargets.Add myPolygonF, 2
前述の例では、アニメーション化したいページアイテムが含まれているスプレッドの TimingSettings を操作
しました。ユーザーがクリックしたときにページアイテムをアニメーション化したい場合は、ページアイテ
ム自体の TimingSettings を使用する必要があります。次のスクリプトにその例を示します(完全なスクリプ
トについては、PageItemTimingSettings を参照してください)。
Rem Given a document "myDocument" and a page "myPage" containg a polygon
Rem "myPolygonA" and a motion path myMotionPathPointsA...
Rem Remove the default timing list in the timing settings for the spread.
Rem Set animation preferences for the polygon.
myPolygonA.AnimationSettings.Duration = 2
myPolygonA.AnimationSettings.MotionPathPoints = myMotionPathPointsA
myPage.Parent.TimingSettings.TimingLists.Item(1).Delete
Set myTimingSettings = myPolygonA.TimingSettings
Set myTimingList = myTimingSettings.TimingLists.Add(idDynamicTriggerEvents.idOnClick)
Set myTimingGroup = myTimingList.TimingGroups.Add(myPolygonA, 0)
第 11 章 ダイナミックドキュメントの作成
アニメーションの操作
176
変形のアニメーション化
ページアイテムのアニメーションを再生するときに、ページアイテムのサイズ、回転または角度の歪み、不
透明度および表示/非表示を変更できます。ページアイテムの AnimationSettings にはプロパティ
(RotationArray、HiddenAfter など)が含まれていて、このプロパティでアニメーション中に適用される変
形を定義できます。モーションパスに従ってページアイテムを回転する方法を、次のスクリプトに示します
(完全なスクリプトについては、AnimateRotation を参照してください)。
Rem Given a document "myDocument" and a page "myPage" and the color "myColorA"...
Rem Add a page items to animate.
Set myPolygonA = myPage.Polygons.Add
myPolygonA.FillColor = myColorA
myPolygonA.StrokeColor = myDocument.Swatches.Item("None")
myPolygonA.Paths.Item(1).EntirePath = Array(Array(72, 72), Array(72, 144),
Array(144, 108))
Rem Create a motion path.
myMotionPathPoints = Array(Array(Array(Array(108, 108), Array(108, 108), Array(108, 108)),
Array(Array(516, 108), Array(516, 108), Array(516, 108))), True)
Rem Set animation preferences for the polygon.
myPolygonA.AnimationSettings.Duration = 2
myPolygonA.AnimationSettings.MotionPathPoints = myMotionPathPoints
Rem Assuming 24 Frames Per Second (FPS)
Rem 23 = 1 second, 47 = 2 seconds, 71 = 3 seconds, 95 = 4 seconds, 119 = 5 seconds,
Rem 143 = 6 seconds
Rem Since the duration of our animation is 2 seconds, the following line will
Rem make the polygon rotate 360 degrees from the start to the end
Rem of the animation.
myPolygonA.AnimationSettings.RotationArray = Array(Array(0, 0), Array(47, 360))
Set myTimingSettings = myPage.Parent.TimingSettings
Rem Remove the default timing list.
myTimingSettings.TimingLists.Item(1).Delete
Rem Add a new timing list that triggers when the page is clicked.
Set myTimingList = myTimingSettings.TimingLists.Add(idDynamicTriggerEvents.idOnPageClick)
Rem Add the polygons to a single timing group.
Set myTimingGroup = myTimingList.TimingGroups.Add(myPolygonA, 0)
スクリプトを使用すると、InDesign のユーザーインターフェイスを使用した場合よりも、アニメーションを
細かく制御できます。例えば、スクリプトを使用したアニメーションの場合、任意のモーションパスの各
キーフレームで変形を適用できます。詳しくは、この章で後述する「キーフレーム」を参照してください。
モーションプリセット
前述の例では、InDesign のユーザーインターフェイスで基本レベルからアニメーションを作成するように、
モーションパスを構成してアニメーション設定を行いました。しかし、InDesign では、モーションプリセッ
トを使用して、レイアウト内のページアイテムのアニメーションを定義することもできます。モーションプ
リセットは、一度に複数のアニメーションのプロパティに適用できます。次のスクリプトにその例を示しま
す(完全なスクリプトについては、MotionPreset を参照してください)。InDesign には、多くのモーションプ
リセットが付属しています。また、ユーザーインターフェイスまたはスクリプトを使用して、新しいプリ
セットを追加することもできます。
Rem Given a page containing the ovals "myOvalA"...
Set myMotionPreset = app.MotionPresets.Item("move-right-grow")
myOvalA.AnimationSettings.Duration = 2
myOvalA.AnimationSettings.PlaysLoop = True
myOvalA.AnimationSettings.Preset = myMotionPreset
第 11 章 ダイナミックドキュメントの作成
アニメーションの操作
177
デザインオプション
デザインオプションは、オブジェクトのアニメーション設定で指定したモーションに関連して、アニメー
ションオブジェクトの表示仕様に影響を与えます。次のスクリプトでは、アニメーションシェイプのデザイ
ンオプションが、アニメーションの再生にどのような影響を与えるかを示します(完全なスクリプトについ
ては、DesignOptions を参照してください)。
Rem Given a page containing the ovals "myOvalA" and "myOvalB"...
Set myMotionPreset = myInDesign.MotionPresets.Item("move-right-grow")
myOvalA.AnimationSettings.Duration = 2
myOvalA.AnimationSettings.PlaysLoop = True
myOvalA.AnimationSettings.Preset = myMotionPreset
myOvalA.AnimationSettings.DesignOption = idDesignOptions.idFromCurrentAppearance
myOvalB.AnimationSettings.Duration = 2
myOvalB.AnimationSettings.PlaysLoop = True
myOvalB.AnimationSettings.Preset = myMotionPreset
myOvalB.AnimationSettings.DesignOption = idDesignOptions.idToCurrentAppearance
キーフレーム
キーフレームは、アニメーションのタイムライン内における時点です。InDesign のスクリプティングでは、
キーフレームをアニメーションの任意の時点に追加することで、オブジェクトがアニメーションするときに
変更を適用できます。キーフレームは、アニメーションするページアイテムに適用されるモーションパスの
一部で、アニメーションの長さと速度を基準にして指定します。例えば、長さ 2 秒のアニメーションの場合、
1 秒間に 24 フレームで再生すると、アニメーションの最後のフレームはフレーム 48 です。
モーションパスにキーフレームを追加する方法と、アニメーション化するページアイテムに適用される変形
を各キーフレームで変更する方法を、次のスクリプトに示します (完全なスクリプトについては、
TransformAnimation を参照してください)。
Rem Given a page containing ovals "myOvalA," "myOvalB," and "myOvalC"...
Rem The motion path is constructed relative to the center of the object, and key frames
Rem are based on the duration of the animation divided by the number of frames
Rem per second (usually 24). The following array sets key frames at the start,
Rem midpoint, and end of a path.
myMotionPath = Array(Array(0, Array(Array(0, 0), Array(0, 0), Array(0, 0))), Array(23,
Array(Array(234, 0), Array(234, 0), Array(234, 0))), Array(47, Array(Array(468, 0), Array(468, 0),
Array(468, 0))))
myOvalA.AnimationSettings.Duration = 2
myOvalA.AnimationSettings.MotionPath = myMotionPath
Rem The transformation changes at each key frame.
Rem scaleXArray in the form Array(Array(keyframe, scale_percentage),
Rem Array(keyframe, scalePercentage), ...)
myOvalA.AnimationSettings.ScaleXArray = Array(Array(0, 100), Array(23, 200),
Array(47, 100))
Rem scaleYArray in the form Array(Array(keyframe, scale_percentage),
Rem Array(keyframe, scalePercentage), ...)
myOvalA.AnimationSettings.ScaleYArray = Array(Array(0, 100), Array(23, 200),
Array(47, 100))
Rem opacityArray in the form Array(Array(keyframe, opacity), Array(keyframe, opacity),...)
myOvalA.AnimationSettings.OpacityArray = Array(Array(0, 100), Array(23, 20),
Array(47, 100))
myOvalA.AnimationSettings.PlaysLoop = True
myOvalB.AnimationSettings.Duration = 2
myOvalB.AnimationSettings.MotionPath = myMotionPath
myOvalB.AnimationSettings.ScaleXArray = Array(Array(0, 200), Array(23, 300),
第 11 章 ダイナミックドキュメントの作成
ページ効果の追加
178
Array(47, 50))
myOvalB.AnimationSettings.ScaleYArray = Array(Array(0, 200), Array(23, 300),
Array(47, 50))
myOvalB.AnimationSettings.OpacityArray = Array(Array(0, 10), Array(23, 80),
Array(47, 60))
myOvalB.AnimationSettings.PlaysLoop = True
myOvalC.AnimationSettings.Duration = 2
myOvalC.AnimationSettings.MotionPath = myMotionPath
myOvalC.AnimationSettings.ScaleXArray = Array(Array(0, 50), Array(23, 200),
Array(47, 400))
myOvalC.AnimationSettings.ScaleYArray = Array(Array(0, 50), Array(23, 200),
Array(47, 400))
myOvalC.AnimationSettings.OpacityArray = Array(Array(0, 100), Array(23, 40),
Array(47, 80))
myOvalC.AnimationSettings.PlaysLoop = True
ページ効果の追加
ページ効果は、書き出し後のダイナミックドキュメントのページを変更した場合に現れる特殊効果です。
ページ効果の追加は、スクリプトを使用して簡単に行えます。次のスクリプトにその例を示します(完全な
スクリプトについては、PageTransitions を参照してください)。
Rem Given a document "myDocument" containing at least two spreads...
For myCounter = 1 To myDocument.Spreads.Count
myDocument.Spreads.Item(myCounter).PageTransitionType =
idPageTransitionTypeOptions.idPageTurnTransition
Rem This page transition option does not support the pageTransitionDirection
Rem or pageTransitionDuration properties.
Rem If you chose idPageTransitionTypeOptions.idWipeTransition (for example),
Rem you would be able to set those options, as shown in the next two lines:
Rem myDocument.spreads.item(myCounter).pageTransitionDirection =
Rem idPageTransitionDirectionOptions.idLeftToRight
Rem myDocument.spreads.item(myCounter).pageTransitionDuration =
Rem idPageTransitionDurationOptions.idMedium
Next
Rem Export the document to SWF, and you'll see the page transitions.
12
XML
章の更新ステータス
CS6
変更なし
XML(Extensible Markup Language)は、World Wide Web Consortium(www.w3.org)で作成と管理が行われて
いる、テキストベースのマークアップシステムです。XML では、HTML(Hypertext Markup Language)と同じ
ように、不等号記号で囲まれたマークアップタグ(<article> や <para> など)が使用されます。HTML では、
使用できるタグが事前に定義されていますが、XML では独自のタグを作成して、ドキュメントの構造をより
詳細に記述することができます。
高い柔軟性を備えている XML は、データの保存形式として広く利用されています。InDesign には、XML デー
タをページレイアウトに読み込むための様々な機能が用意されていますが、それらはスクリプトを使用して
制御できます。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成して実行する方法を理解しているものとして説明を行います。また、XML、DTD、XSLT に関する基礎知識を
持っていることを前提としています。
概要
XML はフォーマットを行うためのものではなく、ドキュメントの構造を記述するためのものです。したがっ
て、ページレイアウト作業で XML を活用するには、やや複雑な手順が必要になります。InDesign は、XML に
完全かつ柔軟に対応できますが、次のような制約があります。

InDesign ドキュメントに読み込んだ XML 要素は、XML 構造に対応する InDesign 要素に変換されます。
InDesign によって表現された XML 要素は、元の XML 要素とは異なります。

1 つの XML 要素は、レイアウト上で 1 つのみ使用できます。レイアウト上の XML 要素の情報を複製した
い場合は、XML 要素そのものを複製する必要があります。

XML 要素のレイアウト上での出現順序は、XML 構造での出現順序とほぼ同じになります。

XML 要素に関連付けられているストーリー内のテキストは、その要素のデータになります。
InDesign での XML スクリプティングの推奨事項
XML ファイルの処理は、InDesign の外部で(InDesign のレイアウトに XML ファイルを読み込む前に)そのほ
とんどを行うのが一般的です。InDesign の外部では、XML エディターや XML パーサーなどの様々な便利な
ツールが利用できます。
大規模な XML データ構造に含まれている要素を再配置したり複製したりする場合は、XSLT を使用して XML
を変換することを推奨します。これは、XML ファイルを読み込むときに実行できます。
InDesign ドキュメントで既にフォーマットされている XML データを操作する場合は、XML ルールを使用する
と便利です。XML ルールを使用すると、効率よくドキュメント内の XML 構造を検索して、目的の XML 要素を
処理できます。
XML ルールについて詳しくは、第 13 章「XML ルール」を参照してください。
179
第 12 章 XML
XML 要素のスクリプティング
180
XML 要素のスクリプティング
ここでは、XML 環境設定や XML 読み込み環境設定の指定、XML の読み込み、XML 要素の作成、XML 属性の追
加を行う方法について説明します。ここでは、XML コンテンツ自体を操作するスクリプトについて説明しま
す。XML 要素にフォーマットを適用するスクリプトについては、185 ページの「レイアウトへの XML 要素の
追加」を参照してください。
XML 環境設定の指定
XML ビュー環境設定オブジェクトを使用して、InDesign の構造パネルの外観を制御できます。次のスクリプ
トにその例を示します(チュートリアルスクリプトの XMLViewPreferences より)。
Set myXMLViewPreferences = myDocument.XMLViewPreferences
myXMLViewPreferences.ShowAttributes = True
myXMLViewPreferences.ShowStructure = True
myXMLViewPreferences.ShowTaggedFrames = True
myXMLViewPreferences.ShowTagMarkers = True
myXMLViewPreferences.ShowTextSnippets = True
また、XML 環境設定オブジェクトを使用して、XML タグ付きプリセット環境設定(表やストーリーのデフォ
ルトのタグ名やユーザーインターフェイスカラー)を指定することもできます。次のスクリプトにその例を
示します(チュートリアルスクリプトの XMLPreferences より)
。
Set myXMLPreferences = myDocument.XMLPreferences
myXMLPreferences.DefaultCellTagColor = idUIColors.idBlue
myXMLPreferences.DefaultCellTagName = "cell"
myXMLPreferences.DefaultImageTagColor = idUIColors.idBrickRed
myXMLPreferences.DefaultImageTagName = "image"
myXMLPreferences.DefaultStoryTagColor = idUIColors.idCharcoal
myXMLPreferences.DefaultStoryTagName = "text"
myXMLPreferences.DefaultTableTagColor = idUIColors.idCuteTeal
myXMLPreferences.DefaultTableTagName = "table"
XML 読み込み環境設定の指定
XML ファイルを読み込む前に、XML 読み込み環境設定を指定することができます。この環境設定を使用すれ
ば、XSLT 変換を適用したり、XML ファイル内の空白文字の処理方法を制御したり、繰り返すテキスト要素を
作成したりすることができます。XML 読み込み環境設定オブジェクトの設定方法を、次のスクリプトに示し
ます(チュートリアルスクリプトの XMLImportPreferences より)
。
Set myXMLImportPreferences = myDocument.XMLImportPreferences
myXMLImportPreferences.AllowTransform = False
myXMLImportPreferences.CreateLinkToXML = False
myXMLImportPreferences.IgnoreUnmatchedIncoming = True
myXMLImportPreferences.IgnoreWhitespace = True
myXMLImportPreferences.ImportCALSTables = True
myXMLImportPreferences.ImportStyle = idXMLImportStyles.idMergeImport
myXMLImportPreferences.ImportTextIntoTables = False
myXMLImportPreferences.ImportToSelected = False
myXMLImportPreferences.RemoveUnmatchedExisting = False
myXMLImportPreferences.RepeatTextElements = True
Rem The following properties are only used when the
Rem AllowTransform property is set to True.
Rem myXMLImportPreferences.TransformFilename = "c:¥myTransform.xsl"
Rem If you have defined parameters in your XSL file, then you can pass
Rem parameters to the file during the XML import process. For each parameter,
Rem enter an array containing two strings. The first string is the name of the
Rem parameter, the second is the value of the parameter.Rem
myXMLImportPreferences.TransformParameters = Array(Array("format", "1"))
第 12 章 XML
XML 要素のスクリプティング
181
XML の読み込み
XML 読み込み環境設定を指定したら、XML ファイルを読み込みます。次のスクリプトにその例を示します
(チュートリアルスクリプトの ImportXML より)。
myDocument.ImportXML "c:¥xml_test.xml"
XML ファイルの内容を特定の XML 要素に読み込む必要がある場合は、ドキュメントではなく XML 要素の
importXML メソッドを使用します。次のスクリプトにその例を示します(チュートリアルスクリプトの
ImportXMLIntoElement より)。
myXMLElement.importXML "c:¥xml_test.xml"
または、XMLImportPreferences オブジェクトの ImportToSelected プロパティを true に設定し、XML 要素を
選択した状態で XML ファイルを読み込む方法もあります。次のスクリプトにその例を示します(チュートリ
アルスクリプトの ImportXMLIntoSelectedElement より)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
myDocument.ImportXML "c:¥test.xml"
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myLastXMLElement = myRootXMLElement.XMLElements.Item(-1)
Rem Select the XML element
myDocument.Select myLastXMLElement, idSelectionOptions.idReplaceWith
myDocument.XMLImportPreferences.ImportToSelected = True
myDocument.ImportXML "c:¥test.xml"
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
myRootXMLElement.PlaceXML myTextFrame
XML タグの作成
XML タグとは、ドキュメント内で使用する XML 要素の名前のことです。XML を読み込むと、XML ファイル内
の要素名が、ドキュメントの XML タグのリストに追加されます。また、XML タグを直接作成することもでき
ます。次のスクリプトにその例を示します(チュートリアルスクリプトの MakeXMLTags より)
。
Rem
Set
Rem
Set
Rem
Set
You can create an XML tag without specifying a color for the tag.
myXMLTagA = myDocument.XMLTags.Add("XML_tag_A")
You can define the highlight color of the XML tag using the UIColors enumeration...
myXMLTagB = myDocument.XMLTags.Add("XML_tag_B", UIColors.Gray)
...or you can provide an RGB array to set the color of the tag.
myXMLTagC = myDocument.XMLTags.Add("XML_tag_C", Array(0, 92, 128))
XML タグのロード
XML ファイルの XML コンテンツを読み込まずに、XML タグだけを読み込むことができます。この機能は、
XML データを読み込む前にタグとスタイルのマッピングを行いたい場合に便利です。次のスクリプトにその
例を示します(チュートリアルスクリプトの LoadXMLTags より)
。
myDocument.LoadXMLTags("c:¥test.xml")
XML タグの保存
ファイルから XML タグをロードするのとは逆に、XML タグをファイルに保存することもできます。これを行
うと、タグだけが XML ファイルに保存されます。ドキュメントデータは保存されません。この処理は、XML
を書き出すより高速で、生成されるファイルも小さくなります。XML タグを保存する方法を、次のサンプル
スクリプトに示します(完全なスクリプトについては、SaveXMLTags を参照してください)。
myDocument.SaveXMLTags("c:¥xml_tags.xml", "Tag set created October 5, 2006")
第 12 章 XML
XML 要素のスクリプティング
182
XML 要素の作成
通常、XML 要素は XML ファイルを読み込んで作成しますが、InDesign スクリプティングを使用して XML 要素
を作成することもできます。次のスクリプトにその例を示します(チュートリアルスクリプトの
CreateXMLElement より)。
Set myXMLTagA = myDocument.XMLTags.Add("XML_tag_A")
Set myXMLElementA = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTagA)
myXMLElementA.Contents = "This is an XML element containing text."
XML 要素の移動
move メソッドを使用して、XML 構造内の XML 要素を移動できます。次のスクリプトにその例を示します
(チュートリアルスクリプトの MoveXMLElement より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Set myXMLTagA = myDocument.XMLTags.Add("myXMLTagA")
Set myXMLTagB = myDocument.XMLTags.Add("myXMLTagB")
Set myXMLElementA = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTagA)
myXMLElementA.Contents = "This is XML element A."
Set myXMLElementB = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTagB)
myXMLElementB.Contents = "This is XML element B."
myXMLElementA.Move idLocationOptions.idAfter, myXMLElementB
XML 要素の削除
XML 要素を削除すると、レイアウトと XML 構造の両方から XML 要素が削除されます。次のスクリプトにその
例を示します(チュートリアルスクリプトの DeleteXMLElement より)
。
myRootXMLElement.XMLElements.Item(1).Delete
XML 要素の複製
XML 要素を複製すると、新しい XML 要素が、XML 構造内の元の XML 要素の直後に追加されます。次のスク
リプトにその例を示します(チュートリアルスクリプトの DuplicateXMLElement より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Set myXMLTagA = myDocument.XMLTags.Add("myXMLTagA")
Set myXMLTagB = myDocument.XMLTags.Add("myXMLTagB")
Set myXMLElementA = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTagA)
myXMLElementA.Contents = "This is XML element A."
Set myXMLElementB = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTagB)
myXMLElementB.Contents = "This is XML element B."
myXMLElementA.Duplicate
XML 構造からのアイテムの削除
XML 要素とページアイテムやテキストとの関連付けを削除するには、untag メソッドを使用します。次のス
クリプトにその例を示します。このメソッドを使用すると、XML 要素との関連付けは削除されますが、オブ
ジェクトそのものは削除されません。XML 要素が削除されたコンテンツは、親の XML 要素に関連付けられま
す。XML 要素がルート XML 要素の場合、その XML 要素に関連付けられているレイアウトオブジェクト(テキ
ストまたはページアイテム)は、ドキュメントに保持されます (完全なスクリプトについては、
UntagElement を参照してください)。
Set myXMLElement = myDocument.XMLElements.item(1).xmlElements.item(1)
myXMLElement.Untag
第 12 章 XML
XML 要素のスクリプティング
183
XML コメントの作成
XML コメントは、XML データ構造に注釈を作成する場合に使用します。XML コメントを追加する方法を、次
のスクリプトに示します(チュートリアルスクリプトの MakeXMLComment より)。
Set myRootXMLElement = myDocument.XMLElements.item(1)
Set myXMLElementB = myRootXMLElement.xmlElements.item(2)
myXMLElementB.XMLComments.Add "This is an XML comment."
XML 処理命令の作成
処理命令(PI:Processing Instruction)とは、XML ドキュメントを読み込むアプリケーションに対する命令が
含まれている XML 要素のことです。XML 処理命令は、InDesign では無視されますが、他のアプリケーション
で使用するために InDesign の XML 構造に挿入することができます。XML ドキュメントには複数の処理命令を
含めることができます。
XML 処理命令は、ターゲットと値の 2 つの要素によって構成されます。次に例を示します。
<?xml-stylesheet type="text/css" href="generic.css"?>
XML 処理命令を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
MakeProcessingInstruction を参照してください)。
Set myRootXMLElement = myDocument.XMLElements.item(1)
Set myXMLProcessingInstruction = myRootXMLElement.XMLInstructions.Add("xml-stylesheet
type=¥"text/css¥" ", "href=¥"generic.css¥"")
XML 属性の操作
XML 属性とは、XML 要素に関連付けられている「メタデータ」のことです。XML 要素に XML 属性を追加する
方法を、次のスクリプトに示します(チュートリアルスクリプトの MakeXMLAttribute より)。XML 要素には任
意の数の XML 属性を追加できますが、各属性の名前はその要素内で固有のものであることが必要です(例え
ば、
「id」という名前の属性を 2 つ使用することはできません)。
Set myDocument = myInDesign.Documents.Item(1)
Set myRootXMLElement = myDocument.XMLElements.item(1)
Set myXMLElementB = myRootXMLElement.xmlElements.item(2)
myXMLElementB.XMLAttributes.Add "example_attribute", "This is an XML attribute. It will not appear
in the layout!"
スクリプトを使用して属性を直接作成する以外に、XML 要素を変換して属性を作成することもできます。こ
れを行うと、XML 要素のテキスト内容が XML 属性の値として使用され、XML 要素の親に追加されます。XML
要素の名前が属性の名前になるので、同じ名前を持つ属性が XML 要素の親に既に存在している場合は、作成
に失敗します。XML 要素にページアイテムが含まれている場合、それらのページアイテムはレイアウトから
削除されます。
XML 属性を XML 要素に変換する際には、新しい XML 要素を追加する場所を指定できます。新しい XML 要素
は、XML 属性の親の先頭または末尾に追加できます。デフォルトでは、親要素の先頭に追加されます。
新しい XML 要素に XML マークアップタグを指定することもできます。このパラメーターを省略すると、その
XML 属性が含まれている XML 要素と同じ XML タグを使用して新しい XML 要素が作成されます。
XML 要素を XML 属性に変換する方法を、次のスクリプトに示します(完全なスクリプトについては、
ConvertElementToAttribute を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myRootXMLElement = myDocument.XMLElements.item(1)
myRootXMLElement.XMLElements.Item(-1).ConvertToAttribute
第 12 章 XML
XML 要素のスクリプティング
184
XML 属性を XML 要素に変換することもできます。次のスクリプトにその例を示します(チュートリアルスク
リプトの ConvertAttributeToElement より)。
Set myRootXMLElement = myDocument.XMLElements.item(1)
Set myXMLElementB = myRootXMLElement.xmlElements.item(1)
Rem The "at" parameter can be either idLocationOptions.idAtEnd or
Rem idLocationOptions.idAtBeginning, but cannot
Rem be idLocationOptions.idAfter or idLocationOptions.idBefore.
myXMLElementB.XMLAttributes.item(1).convertToElement idLocationOptions.idAtEnd,
myDocument.XMLTags.item("xml_element"
XML ストーリーの操作
レイアウト要素(ストーリーまたはページアイテム)に関連付けられていない XML 要素を読み込むと、その
要素は XML ストーリーに格納されます。テキストフレーム内のテキストと同じように、配置されていない
XML 要素内のテキストを操作することができます。次のスクリプトにその例を示します(完全なスクリプト
については、XMLStory を参照してください)。
Set myXMLStory = myDocument.XmlStories.Item(1)
Rem Though the text has not yet been placed in the layout,
Rem all text properties are available.
myXMLStory.Paragraphs.Item(1).PointSize = 72
Rem Place the XML element in the layout to see the result.
myDocument.XMLElements.Item(1).XMLElements.Item(1).PlaceXML
myDocument.Pages.Item(1).TextFrames.Item(1)
XML の書き出し
InDesign ドキュメントから XML を書き出す方法としては、ドキュメント内の XML 構造全体を書き出す方法
と、1 つの XML 要素(とその要素に含まれているすべての子 XML 要素)を書き出す方法があります。次のス
クリプトにその例を示します(完全なスクリプトについては、ExportXML を参照してください)。
Rem Export the entire XML structure in the document.
myDocument.Export idExportFormat.idXML, "c:¥completeDocumentXML.xml"
Rem Export a specific XML element and its child XML elements.
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(-1)
myXMLElement.Export idExportFormat.idXML, "c:¥partialDocumentXML.xml"
また、XMLExportPreferences オブジェクトの ExportFromSelected プロパティを使用して、ユーザーイン
ターフェイスで選択されている XML 要素を書き出すこともできます。次のスクリプトにその例を示します
(完全なスクリプトについては、ExportSelectedXMLElement を参照してください)。
myDocument.Select myDocument.XMLElements.Item(1).XMLElements.Item(2)
myDocument.XMLExportPreferences.ExportFromSelected = True
Rem Export the entire XML structure in the document.
myDocument.Export idExportFormat.idXML, "c:¥selectedXMLElement.xml"
myDocument.XMLExportPreferences.ExportFromSelected = False
第 12 章 XML
レイアウトへの XML 要素の追加
185
レイアウトへの XML 要素の追加
これまでの節では、XML データを InDesign ドキュメントに読み込んで、ドキュメント内の XML 構造を操作す
る方法について説明しました。この節では、XML 情報をページレイアウトに読み込んでフォーマットを行う
方法について説明します。
XML 要素とページアイテムやテキストとの関連付け
ページアイテムやテキストに既存の XML 要素を関連付けるには、PlaceXML メソッドを使用します。このメ
ソッドを使用すると、ページアイテムの内容が XML 要素の内容に置き換わります。次のスクリプトにその例
を示します(チュートリアルスクリプトの PlaceXML より)
。
myDocument.XMLElements.item(1).placeXML myDocument.pages.item(1).textFrames.item(1)
既存のページアイテムやテキストオブジェクトに既存の XML 要素を関連付けるには、markup メソッドを使用
します。このメソッドを使用すると、ページアイテムやテキストの内容と XML 要素の内容(存在する場合)
が結合されます。markup メソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについ
ては、Markup を参照してください)。
myDocument.XMLElements.item(1).XMLElements.item(0).markup
myDocument.pages.item(1).textFrames.item(1)
ページアイテムへの XML の配置
XML 要素をページアイテムに関連付ける別の方法として、PlaceIntoFrame メソッドを使用する方法がありま
す。このメソッドでは、XML を配置するときにフレームを作成できます。次のスクリプトにその例を示しま
す(完全なスクリプトについては、PlaceIntoFrame を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add()
myDocument.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myDocument.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
myDocument.ViewPreferences.RulerOrigin = idRulerOrigin.idPageOrigin
Rem PlaceIntoFrame has two parameters:
Rem On: The page, spread, or master spread on which to create the frame
Rem GeometricBounds: The bounds of the new frame (in page coordinates).
myDocument.XMLElements.Item(1).XMLElements.Item(1).PlaceIntoFrame myDocument.Pages.Item(1),
Array(72, 72, 288, 288)
XML 要素をインラインページアイテム(アンカーオブジェクト)に関連付けるには、PlaceIntoCopy メソッ
ドを使用します。次のスクリプトにその例を示します(チュートリアルスクリプトの PlaceIntoCopy より)
。
Set myPage = myDocument.Pages.Item(1)
Set myXMLElement = myDocument.XMLElements.Item(1)
myXMLElement.PlaceIntoCopy myPage, Array(288, 72), myPage.TextFrames.Item(1), True
既存のページアイテム(または既存のページアイテムのコピー)を XML 要素に関連付けて、XML 構造内のそ
の要素がある場所にページアイテムを挿入するには、PlaceIntoInlineCopy メソッドを使用します。次のス
クリプトにその例を示します(チュートリアルスクリプトの PlaceIntoInlineCopy より)
。
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
myTextFrame.InsertionPoints.Item(-1).Contents = vbCr & vbCr
myDocument.XMLElements.Item(1).PlaceXML myTextFrame
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTag)
myXMLElement.Contents = "This is the second XML element."
myXMLElement.PlaceIntoInlineCopy myTextFrame, False
第 12 章 XML
レイアウトへの XML 要素の追加
186
XML 要素を新規インラインフレームに関連付けるには、PlaceIntoInlineFrame メソッドを使用します。次の
スクリプトにその例を示します(チュートリアルスクリプトの PlaceIntoInlineFrame より)。
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(3)
Rem Specify width and height as you create the inline frame.
myXMLElement.PlaceIntoInlineFrame Array(72, 24)
XML テキスト要素の内部や周囲へのテキストの挿入
XML データを InDesign レイアウトに配置する際に、空白文字(改行やタブ文字など)や静的テキスト(「名
前」や「住所」などのラベル)を XML 要素のテキストに追加したいことがあります。XML 要素の内部や周囲
にテキストを追加する方法を、次のサンプルスクリプトに示します(完全なスクリプトについては、
InsertTextAsContent を参照してください)。
Rem Shows how to add text before, after, and at the beginning/end
Rem of XML elements.
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Add
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myXMLTag = myDocument.XMLTags.Add("myXMLElement")
Set myXMLElementA = myRootXMLElement.XMLElements.Add(myXMLTag)
myXMLElementA.Contents = "This is a paragraph in an XML story."
Set myXMLElementB = myRootXMLElement.XMLElements.Add(myXMLTag)
myXMLElementB.Contents = "This is another paragraph in an XML story."
Set myXMLElementC = myRootXMLElement.XMLElements.Add(myXMLTag)
myXMLElementC.Contents = "This is the third paragraph in an example XML story."
Set myXMLElementD = myRootXMLElement.XMLElements.Add(myXMLTag)
myXMLElementD.Contents = "This is the last paragraph in the XML story."
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(1)
Rem By inserting the return character after the XML element, the character
Rem becomes part of the content of the parent XML element, not of the element itself.
myXMLElement.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(2)
myXMLElement.InsertTextAsContent "Static text: ", idXMLElementPosition.idBeforeElement
myXMLElement.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Rem To add text inside the element, set the location option to beginning or end.
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(3)
myXMLElement.InsertTextAsContent "Text at the start of the element: ",
idXMLElementPosition.idElementStart
myXMLElement.InsertTextAsContent " Text at the end of the element.",
idXMLElementPosition.idElementEnd
myXMLElement.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Rem Add static text outside the element.
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(4)
myXMLElement.InsertTextAsContent "Text before the element: ",
idXMLElementPosition.idBeforeElement
myXMLElement.InsertTextAsContent " Text after the element.", idXMLElementPosition.idAfterElement
Rem To insert text inside the text of an element, work with the text objects contained by the
element.
myXMLElement.Words.Item(2).InsertionPoints.Item(1).Contents = "(the third word of) "
Set myStory = myDocument.Stories.Item(1)
myRootXMLElement.PlaceXML (myStory)
第 12 章 XML
レイアウトへの XML 要素の追加
187
既存レイアウトのマークアップ
XML 以外のファイルに基づいて XML を作成したいことがあります(例えば、既存のページレイアウトを XML
に変換したい場合)。そのような場合は、既存のページレイアウトの内容をマークアップして、XML 構造に追
加します。その後、この構造を書き出して、InDesign 外部の XML ツールで処理します。
スタイルへのタグのマッピング
XML テキスト要素にフォーマットを適用する最も簡単な方法の 1 つが、XMLImportMaps を使用してタグをス
タイルにマッピングする方法です。この方法では、特定の XML タグを段落スタイルや文字スタイルに関連付
けることができます。ドキュメントの MapXMLTagsToStyles メソッドを使用すると、テキストにスタイルが適
用されます。次のスクリプトにその例を示します(チュートリアルスクリプトの MapTagsToStyles より)
。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
Rem Create a tag to style mapping.
myDocument.XMLImportMaps.Add myDocument.XMLTags.Item("heading_1"),
myDocument.ParagraphStyles.Item("heading 1")
myDocument.XMLImportMaps.Add myDocument.XMLTags.Item("heading_2"),
myDocument.ParagraphStyles.Item("heading 2")
myDocument.XMLImportMaps.Add myDocument.XMLTags.Item("para_1"),
myDocument.ParagraphStyles.Item("para 1")
myDocument.XMLImportMaps.Add myDocument.XMLTags.Item("body_text"),
myDocument.ParagraphStyles.Item("body text")
Rem Apply the tag to style mapping.
myDocument.MapXMLTagsToStyles
Set myTextFrame = myDocument.TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
Rem Associate the root XML element with the text frame
Rem so that you can see the effect of the tag to style mapping.
myDocument.XMLElements.Item(1).PlaceXML myDocument.Pages.Item(1).TextFrames.Item(1)
タグへのスタイルのマッピング
XML 要素が関連付けられていないフォーマットされたテキストを XML 構造に移動したい場合は、スタイルを
タグにマッピングします。これによって、段落スタイルや文字スタイルを XML タグに関連付けることができ
ます。これを行うには、XMLExportMap オブジェクトを使用して、XML タグとスタイルの間にリンクを作成し、
MapStylesToXMLTags メソッドを使用して該当する XML 要素を作成します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの MapStylesToTags より)。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
Rem Create a tag to style mapping.
myDocument.XMLExportMaps.Add myDocument.ParagraphStyles.Item("heading 1"),
myDocument.XMLTags.Item("heading_1")
myDocument.XMLExportMaps.Add myDocument.ParagraphStyles.Item("heading 2"),
myDocument.XMLTags.Item("heading_2")
myDocument.XMLExportMaps.Add myDocument.ParagraphStyles.Item("para 1"),
myDocument.XMLTags.Item("para_1")
myDocument.XMLExportMaps.Add myDocument.ParagraphStyles.Item("body text"),
myDocument.XMLTags.Item("body_text")
Rem Apply the style to tag mapping.
myDocument.MapStylesToXMLTags
別の方法としては、単純に、ドキュメント内のすべての段落スタイルや文字スタイルに対して新しい XML タ
グを作成して、スタイルをタグにマッピングする方法があります。次のスクリプトにその例を示します
(チュートリアルスクリプトの MapAllStylesToTags より)
。
第 12 章 XML
レイアウトへの XML 要素の追加
188
Set
Set
Rem
Rem
For
myInDesign = CreateObject("InDesign.Application")
myDocument = myInDesign.Documents.Item(1)
Create tags that match the style names in the document,
creating an XMLExportMap for each tag/style pair.
myCounter = 1 To myDocument.ParagraphStyles.Count
Set myParagraphStyle = myDocument.ParagraphStyles.Item(myCounter)
myParagraphStyleName = myParagraphStyle.Name
myXMLTagName = Replace(myParagraphStyleName, " ", "_")
myXMLTagName = Replace(myXMLTagName, "[", "")
myXMLTagName = Replace(myXMLTagName, "]", "")
Set myXMLTag = myDocument.XMLTags.Add(myXMLTagName)
myDocument.XMLExportMaps.Add myParagraphStyle, myXMLTag
Next
Rem Apply the tag to style mapping.
myDocument.MapStylesToXMLTags
グラフィックのマークアップ
グラフィックに XML 要素を関連付ける方法を、次のスクリプトに示します(完全なスクリプトについては、
MarkingUpGraphics を参照してください)。
Set
Set
Rem
Set
myXMLTag = myDocument.XMLTags.Add("graphic")
myGraphic = myDocument.Pages.Item(1).Place("c:¥test.tif")
Associate the graphic with a new XML element as you create the element.
myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTag, myGraphic)
XML 要素へのスタイルの適用
タグとスタイルをマッピングしたり、XML 要素が関連付けられているテキストやページアイテムにスタイル
を適用したりする以外に、XML 要素にスタイルを直接適用することもできます。ApplyParagraphStyle、
ApplyCharacterStyle、ApplyObjectStyle の 3 つのメソッドを使用する方法を、次のスクリプトに示します
(完全なスクリプトについては、ApplyStylesToXMLElements を参照してください)。
Rem Create a series of XML tags.
Set myHeading1XMLTag = myDocument.XMLTags.Add("heading_1")
Set myHeading2XMLTag = myDocument.XMLTags.Add("heading_2")
Set myPara1XMLTag = myDocument.XMLTags.Add("para_1")
Set myBodyTextXMLTag = myDocument.XMLTags.Add("body_text")
Rem Create a series of paragraph styles.
Set myHeading1Style = myDocument.ParagraphStyles.Add
myHeading1Style.Name = "heading 1"
myHeading1Style.PointSize = 24
Set myHeading2Style = myDocument.ParagraphStyles.Add
myHeading2Style.Name = "heading 2"
myHeading2Style.PointSize = 14
myHeading2Style.SpaceBefore = 12
Set myPara1Style = myDocument.ParagraphStyles.Add
myPara1Style.Name = "para 1"
myPara1Style.PointSize = 12
myPara1Style.FirstLineIndent = 0
Set myBodyTextStyle = myDocument.ParagraphStyles.Add
myBodyTextStyle.Name = "body text"
myBodyTextStyle.PointSize = 12
myBodyTextStyle.FirstLineIndent = 24
Set myCharacterStyle = myDocument.CharacterStyles.Add
myCharacterStyle.Name = "Emphasis"
myCharacterStyle.FontStyle = "Italic"
Set myTextFrameStyle = myDocument.ObjectStyles.Add
myTextFrameStyle.Name = "Text Frame Style"
myTextFrameStyle.CornerEffect = idCornerEffects.idRoundedCorner
myTextFrameStyle.StrokeColor = myDocument.Colors.Item("Black")
myTextFrameStyle.StrokeWeight = 2
第 12 章 XML
レイアウトへの XML 要素の追加
189
Rem Add XML elements.
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myXMLElementA = myRootXMLElement.XMLElements.Add(myHeading1XMLTag)
myXMLElementA.Contents = "Heading 1"
myXMLElementA.ApplyParagraphStyle myHeading1Style, True
myXMLElementA.InsertTextAsContent vbCr, idLocationOptions.idAfter
Set myXMLElementB = myRootXMLElement.XMLElements.Add(myPara1XMLTag)
myXMLElementB.Contents = "This is the first paragraph in the article."
myXMLElementB.ApplyParagraphStyle myPara1Style, True
myXMLElementB.InsertTextAsContent vbCr, idLocationOptions.idAfter
Set myXMLElementC = myRootXMLElement.XMLElements.Add(myBodyTextXMLTag)
myXMLElementC.Contents = "This is the second paragraph in the article."
myXMLElementC.ApplyParagraphStyle myBodyTextStyle, True
myXMLElementC.InsertTextAsContent vbCr, idLocationOptions.idAfter
Set myXMLElementD = myRootXMLElement.XMLElements.Add(myHeading2XMLTag)
myXMLElementD.Contents = "Heading 2"
myXMLElementD.ApplyParagraphStyle myHeading2Style, True
myXMLElementD.InsertTextAsContent vbCr, idLocationOptions.idAfter
Set myXMLElementE = myRootXMLElement.XMLElements.Add(myPara1XMLTag)
myXMLElementE.Contents = "This is the first paragraph following the subhead."
myXMLElementE.ApplyParagraphStyle myPara1Style, True
myXMLElementE.InsertTextAsContent vbCr, idLocationOptions.idAfter
Set myXMLElementF = myRootXMLElement.XMLElements.Add(myBodyTextXMLTag)
myXMLElementF.Contents = "This is the second paragraph following the subhead."
myXMLElementF.ApplyParagraphStyle myBodyTextStyle, True
myXMLElementF.InsertTextAsContent vbCr, idLocationOptions.idAfter
Set myXMLElementG = myXMLElemetF.XMLElements.Add(myBodyTextXMLTag)
myXMLElementG.Contents = "Note:"
Set myXMLElementG = myXMLElementG.Move(idLocationOptions.idAtBeginning, myXMLElementF)
myXMLElementG.InsertTextAsContent " ", idLocationOptions.idAfter
myXMLElementG.ApplyCharacterStyle myCharacterStyle, True
Set myTextFrame = myDocument.TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
Rem Associate the root XML element with the text frame.
myRootXMLElement.PlaceXML myDocument.Pages.Item(1).TextFrames.Item(1)
myRootXMLElement.ApplyObjectStyle myTextFrameStyle, True
XML 表の操作
HTML 標準の表タグでデータがマークアップされている場合、InDesign はその XML データを自動的に表セル
に読み込みます。デフォルトの表マークアップを使用できないか、使用を避けたい場合は、
ConvertElementToTable メソッドを使用して XML 要素を表に変換できます。
このメソッドを使用するには、表に変換する XML 要素が特定の構造になっている必要があります。表の各行
が特定の XML 要素に対応しており、その要素の中に、行内の各セルに対応する一連の XML 要素が含まれてい
る必要があります。このメソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについ
ては、ConvertXMLElementToTable を参照してください)。テーブル行を表すために使用されている XML 要素
は、このプロセスによって変換されます。
第 12 章 XML
レイアウトへの XML 要素の追加
190
Rem Create a series of XML tags.
Set myRowTag = myDocument.XMLTags.Add("row")
Set myCellTag = myDocument.XMLTags.Add("cell")
Set myTableTag = myDocument.XMLTags.Add("table")
Rem Add XML elements.
Set myRootXMLElement = myDocument.XMLElements.Item(1)
With myRootXMLElement
Set myTableXMLElement = .XMLElements.Add(myTableTag)
With myTableXMLElement
For myRowCounter = 1 To 6
With .XMLElements.Add(myRowTag)
.Contents = "Row " + CStr(myRowCounter)
For myCellCounter = 1 To 4
With .XMLElements.Add(myCellTag)
.Contents = "Cell " + CStr(myCellCounter)
End With
Next
End With
Next
End With
End With
Set myTable = myTableXMLElement.ConvertElementToTable(myRowTag, myCellTag)
Set myTextFrame = myDocument.TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
myDocument.XMLElements.Item(1).XMLElements.Item(1).PlaceXML myTextFrame
XML 要素で構成されている表では、XML 要素に関連付けられている表やセルにスタイルを適用するのではな
く、XML 要素に表スタイルやセルスタイルを直接適用することができます。これを行うには、
ApplyTableStyle メソッドや ApplyCellStyle メソッドを使用します。次のスクリプトにその例を示します
(チュートリアルスクリプトの ApplyTableStyles より)。
Rem Create a series of XML tags.
Set myRowTag = myDocument.XMLTags.Add("row")
Set myCellTag = myDocument.XMLTags.Add("cell")
Set myTableTag = myDocument.XMLTags.Add("table")
Rem Create a table style and a cell style.
Set myTableStyle = myDocument.TableStyles.Add
myTableStyle.StartColumnFillColor = myDocument.Colors.Item("Black")
myTableStyle.StartColumnFillTint = 25
Set myCellStyle = myDocument.CellStyles.Add
myCellStyle.FillColor = myDocument.Colors.Item("Black")
myCellStyle.FillTint = 45
Rem Add XML elements.
Set myRootXMLElement = myDocument.XMLElements.Item(1)
With myRootXMLElement
Set myTableXMLElement = .XMLElements.Add(myTableTag)
With myTableXMLElement
For myRowCounter = 1 To 6
With .XMLElements.Add(myRowTag)
.Contents = "Row " + CStr(myRowCounter)
For myCellCounter = 1 To 4
With .XMLElements.Add(myCellTag)
.Contents = "Cell " + CStr(myCellCounter)
End With
Next
End With
第 12 章 XML
レイアウトへの XML 要素の追加
191
Next
End With
End With
Set myTable = myTableXMLElement.ConvertElementToTable(myRowTag, myCellTag)
Set myTableXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(1)
myTableXMLElement.ApplyTableStyle myTableStyle
myTableXMLElement.XMLElements.Item(1).ApplyCellStyle myCellStyle
myTableXMLElement.XMLElements.Item(6).ApplyCellStyle myCellStyle
myTableXMLElement.XMLElements.Item(11).ApplyCellStyle myCellStyle
myTableXMLElement.XMLElements.Item(16).ApplyCellStyle myCellStyle
myTableXMLElement.XMLElements.Item(17).ApplyCellStyle myCellStyle
myTableXMLElement.XMLElements.Item(22).ApplyCellStyle myCellStyle
myDocument.XMLElements.Item(1).PlaceIntoFrame myDocument.Pages.Item(1), myGetBounds(myDocument,
myDocument.Pages.Item(1))
myTable.AlternatingFills = idAlternatingFillsTypes.idAlternatingColumns
13
XML ルール
章の更新ステータス
CS6
変更なし
InDesign の XML ルール機能は、ドキュメントに含まれている XML コンテンツをスクリプトで処理するための
強力なツールです。XML ルールを使用すれば、XML 要素を処理するスクリプトを簡単に記述できるようにな
るとともに、XML 要素の検索、変更、フォーマットを効率よく行えるようになります。
XML ルールは、オープン、配置、クローズなどのアプリケーションイベントによって実行することができま
す。一般的には、ドキュメントに XML を読み込んだ後に実行します (イベントへのスクリプトの割り当てに
ついて詳しくは、第 8 章「イベント」を参照してください)。
この章では、XML ルールの構造と処理について簡単に説明した後で、次の方法について説明します。

XML ルールの定義

XML ルールの適用

XML ルールを使用した XML 要素の検索

XML ルールを使用した XML データのフォーマット

XML ルールに基づいたページアイテムの作成

XML ルールを使用したデータの再構築

XML ルールプロセッサーの使用
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成して実行する方法を理解しているものとして説明を行います。また、XML に関する基礎知識を持っており、
第 12 章「XML」を読み終えていることを前提としています。
概要
InDesign の XML ルール機能は、次の 3 つの部分から構成されています。

XML ルールプロセッサー(単一のスクリプトオブジェクト)ー XPath を使用して、XML 構造の中から
XML 要素を検索し、適切な XML ルールを適用します。次のことは重要です。1 つのスクリプトには、複
数の XML ルールプロセッサーオブジェクトを含めることができます。それぞれの XML ルールプロセッ
サーオブジェクトには、それぞれ 1 つの XML ルールセットが関連付けられます。

グルーコード ー XML ルールを記述するときや、XML ルールプロセッサーとやり取りを行うときに便利な
一連の関数(Adobe 提供)。

XML ルール ー スクリプトに追加する XML アクション。XML ルールはスクリプトコードで記述します。1
つのルールは、XPath ベースの 1 つの条件と、その条件が満たされたときに適用する 1 つの関数に結び付
いています。「apply」関数では、InDesign スクリプティングで定義可能な処理であれば、どのような処
理でも実行できます。例えば、XML 構造の変更、フォーマットの適用、ページ、ページアイテム、ド
キュメントの新規作成などが行えます。
1 つのスクリプトでは、いくつでもルールを定義できます。ルールは、InDesign ドキュメントの XML 構造全
体に適用することもできますし、XML 構造の中の一部の要素に適用することもできます。XML ルールプロ
192
第 13 章 XML ルール
概要
193
セッサーによって XML ルールが実行されると、ドキュメント内の一致する XML 要素やその他のオブジェクト
に変更が加えられます。
XML ルールは、XSLT に似た機能と考えることができます。XSLT では、XPath を使用して XML 構造内の XML 要
素を検索し、何らかの変換を行いますが、XML ルールでは、XPath を使用して InDesign の内部で XML 要素を
検索し、何らかのアクションを行います。XSLT のテンプレートでは、InDesign の外部にある XML パーサーを
使用して XML データに変換を適用しますが、InDesign のルールプロセッサーでは、XML ルールを使用して
InDesign の内部で XML データに変換を適用します。
XML ルールを使用する利点
以前のリリースの InDesign では、XPath を使用して InDesign ファイルの XML 構造をナビゲートすることはで
きませんでした。XML 構造を処理するには、再帰スクリプト関数を作成して、各要素を繰り返し調べていく
必要がありました。この処理は難しく、時間がかかりました。
XML ルールを使用すれば、構造内の XML 要素を簡単に検索できます。XML 要素の検索には、XPath と
InDesign の XML ルールプロセッサーが使用されます。XML ルールプロセッサーは、ドキュメント内の XML 要
素の繰り返し作業をスクリプトよりも高速に処理できます。
XML ルールのプログラミングモデル
XML ルールは、次の 3 つの要素で構成されます。
1.
名前(文字列)
2.
XPath 文(文字列)
3.
apply 関数
XPath 文では、XML 構造内の場所を定義します。XML ルールプロセッサーによって、これに一致する要素が
検索され、ルールで定義されている apply 関数が実行されます。
XML ルールのサンプルを次に示します。
Class RuleName
Public Property Get name
name = "RuleNameAsString"
End Property
Public Property Get xpath
xpath = "ValidXPathSpecifier"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
Rem Do something here.
Rem Return true to stop further processing of the XML element.
apply = False
End Function
End Class
この例では、ルールの名前は RuleNameAsString であり、RuleName に関連付けられます。XPath 式は
ValidXPathSpecifier です。実際に使用できる様々な XML ルールの例については、この章の後の節を参照し
てください。
注意 : XML ルールでは、XPath 1.0 の制限されたサブセットがサポートされています。197 ページの「XPath の
制限事項」を参照してください。
第 13 章 XML ルール
概要
194
XML ルールセット
XML ルールセットは、XML ルールプロセッサーで適用する 1 つ以上の XML ルールの配列です。それぞれの
ルールは、配列に格納されている順番に適用されます。XML ルールセットのサンプルを次に示します。
myRuleSet = Array(new SortByName, new AddStaticText, new LayoutElements, new FormatElements)
この例では、myRuleSet という配列に列挙されているルールが、スクリプトの別の場所に定義されています。
XML ルールセットを利用した、実際に使用できる様々なスクリプトについては、この章の後述を参照してく
ださい。
「グルー」コード
InDesign のスクリプトモデルに組み込まれている XML ルールプロセッサーオブジェクトに加えて、XML ルー
ルの作成に役立つ一連の関数が用意されています。glue code.vbs というファイルに、次の関数が定義されて
います。

__processRuleSet(root, ruleSet) — 一連の XML ルールを実行するには、__processRuleSet 関数を呼び
出して、XML 要素や XML ルールセットを指定する必要があります。この XML 要素では、ルールの処理を
開始する XML 構造内のポイントを定義します。

__processChildren(ruleProcessor) — 一致する XML 要素の子要素に対して一致する XML ルールを適用
するように、XML ルールプロセッサーに指示します。これを使用すれば、子 XML 要素が処理された後に、
親 XML 要素に適用したルールでコードを実行することができます。デフォルトでは、XML ルールプロ
セッサーによって XML 要素の子にルールが適用されると、制御はそのルールに戻されません。
__processChildren 関数を使用すれば、子 XML 要素が処理された後に、ルールの apply 関数に制御を戻
すことができます。

__skipChildren(ruleProcessor) — 現在の XML 要素の下位要素を XML ルールで処理しないようにプロ
セッサーに指示します。これは、現在の XML 要素を移動または削除する場合や、XML 構造の不要な部分
をスキップしてパフォーマンスを向上させたい場合などに役立ちます。
XML 構造内の反復処理
XML ルールプロセッサーは、ドキュメントの XML 階層に現れる順番で XML 要素を反復します。XML 構造を順
方向に通過していき、構造内のそれぞれの XML 要素を 2 回訪れます(XML ファイル内でネストしているタグ
の通常の順番と同じ、親、子、親の順番)。XML ルールプロセッサーは、すべての XML 要素に対して、一致す
るすべての XML ルールを、現在の XML ルールセットに列挙されている順番で適用しようとします。
__processRuleSet 関数は、
「深さ優先」の順番で XML 要素にルールを適用します。つまり、XML 要素とその
子要素は、XML 構造に現れる順番で処理されます。XML ルールプロセッサーは、XML 構造の 1 つの「枝」に
含まれているすべての XML 要素を訪れてから、次の「枝」に移動します。
XML ルールプロセッサーは、ある XML 要素に XML ルールを適用すると、その XML 要素の下位要素に適用で
きるルールがあるかどうかを調べます。__skipChildren または __processChildren 関数を XML ルールで使用
したり、他のルールの動作を変更したりすれば、この動作を変えることができます。
これらの関数の動作を確認するには、DepthFirstProcessingOrder.xml ファイルを新規ドキュメントに読み
込んで、DepthFirstProcessingOrder.jsx スクリプトを実行します。InDesign でテキストフレームが作成さ
れ、サンプル XML ファイルに含まれている各要素の属性名が、各ルールの訪問順にリストされます。このス
クリプトと AddAttribute チュートリアルスクリプトを組み合わせれば、作成した XML ドキュメントでの XML
検索の問題点を見つけることができます(XML 構造に合わせて AddAttribute スクリプトを編集する必要があ
ります)
。
第 13 章 XML ルール
概要
195
次の図に、通常の反復処理を示します(構造内のすべての XML 要素に一致するルールが 1 つある場合)。
Root
1
B
2
9
BA
BB
BC
3
4
5
8
BAA
BAB
BAC
6
7
BACA
BACB
次の図に、__processChildren を使用した場合の反復処理を示します(構造内のすべての XML 要素に一致す
るルールが 1 つある場合)。
Root
9
B
8
6
BA
7
BB
BC
5
4
BAA
3
BAB
BAC
2
1
BACA
BACB
次のルールセットを使用した場合の反復処理を、スクリプトの後の図に示します。ルールセットには、すべ
ての要素に一致する 2 つのルールが含まれており、1 つのルールで __processChildren が使用されています。
すべての要素は 2 回処理されます (完全なスクリプトについては、ProcessChildren を参照してください)。
第 13 章 XML ルール
概要
196
Class NormalRule
Public Property Get name
name = "NormalRule"
End Property
Public Property Get xpath
xpath = "//XMLElement"
End Property
Public Function apply(myXMLElement, myRuleProcessor)
With myXMLElement
myStory.InsertionPoints.Item(-1).Contents =
.XMLAttributes.Item(1).Value & vbCr
End With
apply = false
End Function
End Class
Class ProcessChildrenRule
Public Property Get name
name = "ProcessChildrenRule"
End Property
Public Property Get xpath
xpath = "//XMLElement"
End Property
Public Function apply(myXMLElement, myRuleProcessor)
glueCode_processChildren(myRuleProcessor)
With myXMLElement
myXMLElement.XMLattributes.Item(1).Value
myStory.InsertionPoints.Item(-1).Contents =
.XMLAttributes.Item(1).Value & vbCr
End With
apply = false
End Function
End Class
Root
1
19
B
2
18
14
16
BA
BB
3
13
5
BAA
15
17
7
BAB
4
BC
BAC
6
8
12
10
BACA
BACB
9
11
反復処理時の構造の変更
XML ルールプロセッサーが一致する XML 要素に XML ルールを適用したときに、このルールによってドキュメ
ントの XML 構造が変更されることがあります。XML ルールプロセッサーの現在のパスに含まれている XML 要
素が変更された場合は、他のルールの適用処理との間で競合が発生する可能性があります。XML ルールで
XML 構造を変更する場合は、XML ルールプロセッサーでエラーが発生しないように、次の制限を守ってくだ
さい。
第 13 章 XML ルール
概要
197

上位にある XML 要素の削除 — 一致した XML 要素の上位にある XML 要素を削除したい場合は、その上位
にある XML 要素に一致および処理を行うルールを別途作成します。

親 XML 要素の挿入 — 一致した XML 要素に上位の XML 要素を追加したい場合は、現在の XML 要素を処理
した後に追加します。上位の XML 要素を追加しても、XML ルールプロセッサーで現在実行されている
ルールの反復処理では処理されません(追加した要素は現在の要素の「上」にあるからです)。

現在の XML 要素の削除 — 一致した XML 要素に含まれている子 XML 要素がすべて処理されるまで、その
要素の削除や移動は行えません。このような変更を行いたい場合は、__skipChildren 関数を使用した上
で変更を行います。

処理は再実行されない — 処理済みのノードを変更しても、XML ルールが再実行されることはありませ
ん。
複数のルールが一致する場合の処理
複数のルールが 1 つの XML 要素に一致する場合は、XML ルールプロセッサーによって、一致するルールの一
部またはすべてが適用されます。いずれかのルールの apply 関数が true を返すまで、ルールセットに列挙さ
れている順に XML ルールが適用されます。つまり、戻り値の true は、要素の処理が完了したことを表しま
す。あるルールで true が返されると、その XML 要素に一致する他の XML ルールがあっても無視されます。
XML ルールの apply 関数で false を返せば、次に一致するルールが適用されるようになります。
apply 関数で false を返すときは、XML ルールで定義された XPath プロパティ以外の条件(スクリプトの他
の変数の状態など)に基づいて、XML ルールの一致動作を制御することができます。
XPath の制限事項
InDesign の XML ルールでは、XPath 1.0 仕様の制限されたサブセットがサポートされています。その代表的な
ものを次に示します。

名前(ルートからのパス)による要素の検索(/doc/title など)。

ワイルドカードやノード一致を使用したパスの検索(/doc/*/subtree/node() など)。

指定の属性が指定の値である要素の検索(/doc/para[@font='Courier'] など)。

指定の属性が指定の値でない要素の検索(/doc/para[@font !='Courier'] など)。

数字のインデックス(ただし last() は除く)を使用した子要素の検索(/doc/para[3] など)
。

現在の要素(self)または子孫要素(descendant)の検索(//para など)。

終端としてのコメント(comment())の検索(/doc/comment() など)
。

ターゲットなどによる PI の検索(/doc/processing-instruction('foo') など)。

複数の述語(predicate)の検索(/doc/para[@font='Courier'][@size=5][2] など)。

following-sibling 軸に沿った検索(/doc/note/following-sibling::* など)。
この実装では 1 パスの性質があるので、特に次の XPath 式は使用できません。

..、ancestor::、preceding-sibling:: などの、上位の要素や preceding-sibling 軸は使用できません。

述語でのパス指定は行えません(foo[bar/c] など)

last() 関数は使用できません

text() 関数の使用やテキストの比較は行えません。ただし、InDesign スクリプティングを使用して、目
的の XML ルールに一致する XML 要素のテキストコンテンツを調べることは可能です。
第 13 章 XML ルール
概要

述語でのブール演算の組み合わせは行えません(foo[@bar=font or @c=size] など)
。

述語での比較は行えません(foo[@bar < font or @c > 3] など)。

相対パスは使用できません(doc/chapter など)。
198
エラー処理
XML ルールは InDesign スクリプティングモデルの一部分なので、ルールを使用したスクリプトの基本的な性
質は、通常のスクリプトと同じです。したがって、エラー処理メカニズムも同じものを使用できます。
InDesign にエラーが発生した場合の動作は、XML ルールスクリプトも通常のスクリプトも同じです。InDesign
のエラーは、スクリプト言語に用意されている任意のエラー捕捉メカニズム(try...catch ブロックなど)
を使用して捕捉できます。
InDesign には、XML ルールの処理に固有のエラーがいくつか用意されています。サポートされていない XPath
指定がルールに使用されていると、XML ルールプロセッサーの初期化時に InDesign エラーが発生することが
。また、モデルの変更によって XML ルールプロセッ
あります(197 ページの「XPath の制限事項」を参照)
サーが無効な状態になった場合にも InDesign エラーが発生することがあります。XML ルールの処理で XML 構
造を変更すると、XML ルールプロセッサーが無効になる場合があります。XML 構造に対するこのような変更
は、XML ルールプロセッサーを使用したスクリプト、同時に実行されている別のスクリプト、ユーザーイン
ターフェイスで実行されたユーザーアクションなどによって行われる可能性があります。
XML ルールプロセッサーを無効にするような変更が XML 構造に加えられた場合は、XML ルールプロセッサー
の反復処理が再開されるとエラーが発生します。エラーメッセージには、エラーの原因となった XML 構造の
変更が表示されます。
XML ルールの制御フロー
XML ルールを含むスクリプトを実行すると、XML ルールを含むスクリプト関数から各 XML ルールに制御が渡
され、さらに各ルールからグルーコードで定義されている関数に制御が渡されます。これらの関数から XML
ルールプロセッサーに制御が渡され、プロセッサーが構造内の XML 要素を反復処理します。その結果やエ
ラーは、関数によって処理されるか、スクリプトエラーが発生するまで、このチェーンを逆方向に渡されて
いきます。次の図に、XML ルールスクリプトの制御フローの概要を示します。
XML 䊦䊷䊦
䉴䉪䊥䊒䊃
XML 䊦䊷䊦
XML 䊦䊷䊦
䊒䊨䉶䉾䉰䊷
䉫䊦䊷䉮䊷䊄
XM
Lr
ule
s
XPath condition
XPath 䈱᧦ઙ
XPath 䈱⹏ଔ
__processRuleSet
XML element
t
XML elemen
apply()
__processChildren
__skipChildren
t
XML elemen
XML ᭴ㅧౝ䈱
෻ᓳಣℂ
第 13 章 XML ルール
XML ルールの例
199
XML ルールの例
XML ルールでは、XPath 文を使用して目的の XML 要素を指定します。したがって、XML ルールとドキュメン
トの XML 構造の間には緊密な関係があります。この節では、実際に使用できる XML ルールスクリプトをいく
つか示しますが、そのためには、スクリプトの実行対象となる XML 構造も同時に示す必要があります。この
章の以降の各節では、サンプル XML データファイルに基づいた XML ルールの例を示します。この例では、架
空の IC メーカーの製品リストを使用します。XML データファイルの各レコードの構造は、次のとおりです。
<device>
<name></name>
<type></type>
<part_number></part_number>
<supply_voltage>
<minimum></minimum>
<maximum></maximum>
</supply_voltage>
<package>
<type></type>
<pins></pins>
</package>
<price></price>
<description></description>
</device>
最初は簡単なスクリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
サンプルドキュメントのセットアップ
この章の各スクリプトを実行する前に、ドキュメントに XMLRulesExampleData.xml データファイルを読み込
みます。XML を読み込む場合は、XML 読み込みオプションダイアログボックスの「空白のみの要素を読み込
まない」オプションをオンにします。ファイルを保存し、ファイル/復帰を選択してから、この節の各サン
プルスクリプトを実行します。または、次のスクリプトを実行してから、各サンプル XML ルールスクリプト
を実行します(XMLRulesExampleSetup.jsx というスクリプトファイルを参照してください)。
//XMLRuleExampleSetup.jsx
//
main();
function main(){
var myDocument = app.documents.add();
myDocument.xmlImportPreferences.allowTransform = false;
myDocument.xmlImportPreferences.ignoreWhitespace = true;
var myScriptPath = myGetScriptPath();
var myFilePath = myScriptPath.path + "/XMLRulesExampleData.xml"
myDocument.importXML(File(myFilePath));
var myBounds = myGetBounds(myDocument, myDocument.pages.item(0));
myDocument.xmlElements.item(0).placeIntoFrame(myDocument.pages.item(0), myBounds);
function myGetBounds(myDocument, myPage){
var myWidth = myDocument.documentPreferences.pageWidth;
var myHeight = myDocument.documentPreferences.pageHeight;
第 13 章 XML ルール
XML ルールの例
200
var myX1 = myPage.marginPreferences.left;
var myY1 = myPage.marginPreferences.top;
var myX2 = myWidth - myPage.marginPreferences.right;
var myY2 = myHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
function myGetScriptPath() {
try {
return app.activeScript;
}
catch(myError){
return File(myError.fileName);
}
}
}
最初の XML ルール
まず、非常に単純な XML ルールを作成します。このルールでは、ドキュメントの各 XML 要素の後に改行文字
を追加します。XML ルールセットには 1 つのルールが含まれています。完全なスクリプトについては、
AddReturns を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
Set myAddReturns = new AddReturns
myRuleSet = Array(myAddReturns)
Rem The third parameter of __processRuleSet is a
Rem prefix mapping table; we'll leave it empty.
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
Rem XML rule "AddReturns"
Class AddReturns
Public Property Get name
name = "AddReturns"
End Property
Public Property Get xpath
xpath = "//*"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
Rem Add a return character at the end of the XML element.
.InsertTextAsContent vbcr, idXMLElementPosition.idElementEnd
End With
apply = False
End Function
End Class
Function Include(myScriptFilePath)
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myScriptFile = myFileSystemObject.OpenTextFile(myScriptFilePath)
myScriptContents = myScriptFile.ReadAll
ExecuteGlobal myScriptContents
End Function
第 13 章 XML ルール
XML ルールの例
201
空白文字と静的テキストの追加
次の XML ルールスクリプトは、空白文字と静的テキストを追加するという点では前のスクリプトと似ていま
すが、要素名に基づいて XML 要素の扱いを変えている点で少し複雑なものになっています。完全なスクリプ
トについては、AddReturnsAndStaticText を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new ProcessDevice,new ProcessName,new ProcessType,_
new ProcessPartNumber,new ProcessSupplyVoltage,new ProcessPackageType,_
new ProcessPackageOne,new ProcessPackages,new ProcessPrice)
Rem The third parameter of __processRuleSet is a
Rem prefix mapping table; we'll leave it empty.
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
Class ProcessDevice
Public Property Get name
name = "ProcessDevice"
End Property
Public Property Get xpath
xpath = "/devices/device"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
End With
apply = False
End Function
End Class
Class ProcessName
Public Property Get name
name = "ProcessName"
End Property
Public Property Get xpath
xpath = "/devices/device/name"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
Rem Add static text at the beginning of the element.
.InsertTextAsContent "Device Name:", idXMLElementPosition.idBeforeElement
Rem Add a return character at the end of the element.
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
End With
apply = False
End Function
End Class
Class ProcessType
Public Property Get name
name = "ProcessType"
End Property
Public Property Get xpath
xpath = "/devices/device/type"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
Rem Add static text at the beginning of the element.
.InsertTextAsContent "Circuit Type:", idXMLElementPosition.idBeforeElement
Rem Add a return character at the end of the element.
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
End With
apply = False
End Function
第 13 章 XML ルール
End Class
Class ProcessPartNumber
Public Property Get name
name = "ProcessPartNumber"
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
Rem Add static text at the beginning of the element.
.InsertTextAsContent "Part Number:", idXMLElementPosition.idBeforeElement
Rem Add a return character at the end of the element.
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
End With
apply = False
End Function
End Class
Rem Adds static text around the "minimum" and "maximum"
Rem XML elements of the "supply_voltage" XML element.
Class ProcessSupplyVoltage
Public Property Get name
name = "ProcessSupplyVoltage"
End Property
Public Property Get xpath
xpath = "/devices/device/supply_voltage"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent "Supply Voltage: From ",
idXMLElementPosition.idBeforeElement
With myXMLElement.XMLElements.Item(1)
.InsertTextAsContent " to ", idXMLElementPosition.idAfterElement
End with
With myXMLElement.XMLElements.Item(-1)
Rem Add static text to the end of the voltage range.
.InsertTextAsContent " volts", idXMLElementPosition.idAfterElement
End with
Rem Add a return at the end of the XML element.
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
End With
apply = True
End Function
End Class
Rem Insert a dash between the "type" and "pins" elements.
Class ProcessPackageType
Public Property Get name
name = "ProcessPackageType"
End Property
Public Property Get xpath
xpath = "/devices/device/package/type"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent "-", idXMLElementPosition.idAfterElement
End With
apply = true
End Function
End Class
Rem Process the first "package" element.
Class ProcessPackageOne
Public Property Get name
name = "ProcessPackageOne"
XML ルールの例
202
第 13 章 XML ルール
XML ルールの例
203
End Property
Public Property Get xpath
xpath = "/devices/device/package[1]"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent "Package: ", idXMLElementPosition.idBeforeElement
End With
apply = true
End Function
End Class
Rem Process the remaining "package" elements.
Class ProcessPackages
Public Property Get name
name = "ProcessPackages"
End Property
Public Property Get xpath
xpath = "/devices/device/package"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent", ", idXMLElementPosition.idBeforeElement
End With
apply = True
End Function
End Class
Class ProcessPrice
Public Property Get name
name = "ProcessPrice"
End Property
Public Property Get xpath
xpath = "/devices/device/price"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
Rem Add a return at the start of the XML element.
.InsertTextAsContent vbCr & "Price: $",
idXMLElementPosition.idBeforeElement
Rem .InsertTextAsContent "Price: $", idXMLElementPosition.idBeforeElement
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
End With
apply = False
End Function
End Class
Function Include(myScriptFilePath)
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myScriptFile = myFileSystemObject.OpenTextFile(myScriptFilePath)
myScriptContents = myScriptFile.ReadAll
ExecuteGlobal myScriptContents
End Function
注意 : このスクリプト(の ProcessPackages という XML ルール)では、繰り返される要素の間にカンマを追
加しています。同じレベルに類似の要素が並んでいる場合は、forward-axis 一致を使用して同じことを実
行できます。次のような XML 構造があるとします。
<xmlElement><item>1</item><item>2</item><item>3</item><item>4</item>
</xmlElement>
それぞれの item という XML 要素の間にカンマを追加してレイアウトするには、次のような XML ルール
を使用します(チュートリアルスクリプトの ListProcessing より)。
第 13 章 XML ルール
XML ルールの例
204
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new ListItems)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
Rem Match all following sibling XML elements
Rem of the first "item" XML element.
Class ListItems
Public Property Get name
name = "ListItems"
End Property
Public Property Get xpath
xpath = "/xmlElement/item[1]/following-sibling::*"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent vbcr, idXMLElementPosition.idBeforeElement
End With
apply = False
End Function
End Class
XML ルールを使用した XML 構造の変更
InDesign の XML の実装においては、XML 要素の順番が重要になるので、XML ルールを使用して構造内の要素
の順番を変更したい場合が考えられます。一般に、XML ドキュメントの構造を大幅に変更する場合は、
InDesign に XML を読み込む前か読み込むときに、XSLT ファイルを使用してドキュメントを変換するのが最も
よい方法です。
move メソッドを使用してこれを行う方法を、次の XML ルールスクリプトに示します。XML プロセッサーが無
効にならないように、グルーコードで __skipChildren 関数を使用している点に注意してください。完全なス
クリプトについては、MoveXMLElement を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new MoveElement)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class MoveElement
Public Property Get name
name = "MoveElement"
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
第 13 章 XML ルール
XML ルールの例
205
Rem Moves the part_number XML element to the start of
Rem the device XML element (the parent).
Public Function apply (myXMLElement, myRuleProcessor)
Rem Because this rule makes changes to the XML structure,
Rem you must use _skipChildren to avoid invalidating
Rem the XML element references.
glueCode_skipChildren(myRuleProcessor)
With myXMLElement
Set myParent = .Parent
Set myNameElement = myParent.XMLElements.Item(1)
.Move idLocationOptions.idBefore, myNameElement
End With
apply = false
End Function
End Class
XML ルールを使用した XML 要素の複製
第 12 章「XML」で説明したように、XML 要素とレイアウト内の対応する表現との間には、1 対 1 の関係があ
ります。ある XML 要素の内容をレイアウト内で複数表示したい場合は、その要素を複製する必要があります。
XML ルールを使用して要素を複製する方法を、次のスクリプトに示します。完全なスクリプトについては、
DuplicateXMLElement を参照してください。このルールでも、__skipChildren を使用して無効な XML オブ
ジェクト参照を回避しています。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new DuplicateElement)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class DuplicateElement
Public Property Get name
name = "DuplicateElement"
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
Rem Moves the part_number XML element to the start of
Rem the device XML element (the parent).
Public Function apply (myXMLElement, myRuleProcessor)
Rem Because this rule makes changes to the XML structure,
Rem you must use _skipChildren to avoid invalidating
Rem the XML element references.
glueCode_skipChildren(myRuleProcessor)
With myXMLElement
.Duplicate
End With
apply = false
End Function
End Class
第 13 章 XML ルール
XML ルールの例
206
XML ルールと XML 属性
次の XML ルールでは、「name」要素の内容に基づいて XML 要素に属性を追加しています。XML ルールで、テ
キストコンテンツに基づいて要素を検索する必要がある場合は、XML 要素の内容を、親の XML 要素の XML 属
性にコピーまたは移動すると便利です。XML ルールでサポートされている XPath のサブセットでは、要素の
テキストを検索することはできませんが、属性値に基づいて要素を検索することは可能です。完全なスクリ
プトについては、AddAttribute を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new AddAttribute)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class AddAttribute
Public Property Get name
name = "AddAttribute"
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
Rem Adds the content of the XML element to an attribute
Rem of the parent of the XML element. This can make finding
Rem the element by its content much easier and faster.
Public Function apply (myXMLElement, myRuleProcessor)
With myXMLElement
Set myParent = .Parent
myString = myXMLElement.Texts.Item(1).Contents
Set myXMLAttribute = .Parent.XMLAttributes.Add("part_number", myString)
End With
apply = false
End Function
End Class
前述の XML ルールでは、ある XML 要素のデータを、親の XML 要素の XML 属性にコピーしました。では、XML
要素のデータを属性に移動して、その XML 要素を削除したい場合はどうすればよいでしょうか。その場合は、
convertToAttribute メソッドを使用します。次のスクリプトにその例を示します(チュートリアルスクリプ
トの ConvertToAttribute より)
。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new ConvertToAttribute)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class ConvertToAttribute
Public Property Get name
name = "ConvertToAttribute"
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
第 13 章 XML ルール
XML ルールの例
207
Rem Converts an XML element to an attribute
Rem of the parent of the XML element.
Public Function apply (myXMLElement, myRuleProcessor)
glueCode_skipChildren(myRuleProcessor)
With myXMLElement
.ConvertToAttribute
End With
apply = true
End Function
End Class
XML 属性のデータを XML 要素に移動するには、第 12 章「XML」の説明にあるように、convertToElement メ
ソッドを使用します。
複数の一致ルールの適用
ある XML ルールの apply 関数で true を返すと、それ以降の XML ルールは XML 要素に適用されなくなります。
apply 関数で false を返すと、他のルールが必要に応じて XML 要素に適用されます。次のスクリプトは、false
を返す XML ルール apply 関数の例を示しています。このスクリプトには、ドキュメント内のすべての XML 要
素に一致する 2 つのルールが含まれています。最初のルールは特定のカラーを適用して false を返しますが、2
番目のルールは(myCounter という変数の状態に基づいて)1 つおきに XML 要素に別のカラーを適用する点
が異なります。完全なスクリプトについては、ReturningFalse を参照してください。
myCounter = 0
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
Rem Define two colors.
Set myColorA = myAddColor(myDocument, "ColorA",
idColorModel.idProcess, Array(0, 100, 80, 0))
Set myColorB = myAddColor(myDocument, "ColorB",
idColorModel.idProcess, Array(100, 0, 80, 0))
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new ReturnFalse, new ReturnTrue)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Rem Adds a color to the text of every element in the structure.
Class ReturnFalse
Public Property Get name
name = "ReturnFalse"
End Property
Public Property Get xpath
xpath = "//*"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myColorA = myInDesign.Documents.Item(1).Colors.Item("ColorA")
With myXMLElement
.Texts.Item(1).FillColor = myColorA
End With
Rem Leaves the XML element available to further processing.
apply = false
End Function
End Class
Rem Adds a color to the text of every other element in the structure.
Class ReturnTrue
Public Property Get name
name = "ReturnTrue"
End Property
Public Property Get xpath
xpath = "//*"
第 13 章 XML ルール
XML ルールの例
208
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myColorB = myInDesign.Documents.Item(1).Colors.Item("ColorB")
With myXMLElement
Rem Test based on the global variable "myCounter"
If myCounter Mod 2 = 0 Then
.Texts.Item(1).FillColor = myColorB
End If
myCounter = myCounter + 1
End With
Rem Do not process the element with any further matching rules.
apply = true
End Function
End Class
Function Include(myScriptFilePath)
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myScriptFile = myFileSystemObject.OpenTextFile(myScriptFilePath)
myScriptContents = myScriptFile.ReadAll
ExecuteGlobal myScriptContents
End Function
Function myAddColor(myDocument, myColorName, myColorModel, myColorValue)
On Error Resume Next
Set myColor = myDocument.colors.Item(myColorName)
If Err.Number <> 0 Then
Set myColor = myDocument.colors.Add
myColor.Name = myColorName
Err.Clear
End If
On Error GoTo 0
myColor.model = myColorModel
myColor.colorValue = myColorValue
Set myAddColor = myColor
End Function
XML 要素の検索
既に説明したように、XML ルールでサポートされている XPath のサブセットでは、XML 要素のテキストコン
テンツを検索することはできません。この制約を回避するには、属性を使用して目的の XML 要素を検索する
か、一致する XML 要素のテキストを検索します。属性を使用して XML 要素を検索する方法を、次のスクリプ
トに示します。このスクリプトでは、検索した要素のテキストにカラーを適用していますが、実際のスクリ
プトではより意味のある処理を行うことになります。完全なスクリプトについては、
FindXMLElementByAttribute を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
Rem Define two colors.
Set myColorA = myAddColor(myDocument, "ColorA", idColorModel.idProcess,
Array(0, 100, 80, 0))
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new AddAttribute)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
Rem Now that the attributes have been added, find and format
Rem the XML element whose attribute content matches a specific string.
myRuleSet = Array(new FindAttribute)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class AddAttribute
Public Property Get name
name = "AddAttribute"
第 13 章 XML ルール
XML ルールの例
209
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
Rem Adds the content of the XML element to an attribute
Rem of the parent of the XML element. This can make finding
Rem the element by its content much easier and faster.
Public Function apply (myXMLElement, myRuleProcessor)
With myXMLElement
Set myParent = .Parent
myString = myXMLElement.Texts.Item(1).Contents
Set myXMLAttribute = .Parent.XMLAttributes.Add("part_number", myString)
End With
apply = false
End Function
End Class
Class FindAttribute
Public Property Get name
name = "FindAttribute"
End Property
Public Property Get xpath
xpath = "/devices/device[@part_number = 'DS001']"
End Property
Rem Applies a color to the text of an XML element
Rem (to show that we found it).
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myColorB = myInDesign.Documents.Item(1).Colors.Item("ColorB")
With myXMLElement
.Texts.Item(1).FillColor = myColorA
End With
apply = false
End Function
End Class
findText メソッドを使用して、XML コンテンツを検索およびフォーマットする方法を、次のスクリプトに示
します(完全なスクリプトについては、FindXMLElementByFindText を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
Rem Define two colors.
Set myColorA = myAddColor(myDocument, "ColorA", idColorModel.idProcess,
Array(0, 100, 80, 0))
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new FindByFindText)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class FindByFindText
Public Property Get name
name = "FindByFindText"
End Property
Public Property Get xpath
xpath = "/devices/device/description"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
With myXMLElement
myResetFindText myInDesign
If .Texts.Item(1).contents <> "" Then
Rem Set the find options.
myInDesign.FindChangeTextOptions.CaseSensitive = False
myInDesign.FindChangeTextOptions.IncludeFootnotes = False
第 13 章 XML ルール
XML ルールの例
210
myInDesign.FindChangeTextOptions.IncludeHiddenLayers = False
myInDesign.FindChangeTextOptions.IncludeLockedLayersForFind =
False
myInDesign.FindChangeTextOptions.IncludeLockedStoriesForFind =
False
myInDesign.FindChangeTextOptions.IncludeMasterPages = False
myInDesign.FindChangeTextOptions.WholeWord = False
Rem Search for the word "triangle" in the content of the element.
myInDesign.FindTextPreferences.FindWhat = "triangle"
Set myFoundItems = .FindText
If myFoundItems.Count > 0 Then
Set myColorA = myInDesign.Documents.Item(1).Colors.Item("ColorA")
.Texts.Item(1).FillColor = myColorA
End If
myResetFindText myInDesign
End If
End With
apply = false
End Function
End Class
Function myResetFindText(myInDesign)
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
End Function
findGrep メソッドを使用して、XML コンテンツを検索およびフォーマットする方法を、次のスクリプトに示
します(完全なスクリプトについては、FindXMLElementByFindGrep を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
Rem Define two colors.
Set myColorA = myAddColor(myDocument, "ColorA", idColorModel.idProcess,
Array(0, 100, 80, 0))
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
myRuleSet = Array(new FindByFindGrep)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class FindByFindGrep
Public Property Get name
name = "FindByFindGrep"
End Property
Public Property Get xpath
xpath = "/devices/device/description"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
With myXMLElement
myResetFindGrep myInDesign
If .Texts.Item(1).contents <> "" Then
Rem Search for the regular expression:
Rem "(?i)pulse.*?triangle|triangle.*?pulse"
Rem in the content of the element.
myInDesign.FindGrepPreferences.FindWhat =
"(?i)pulse.*?triangle|triangle.*?pulse"
第 13 章 XML ルール
XML ルールの例
211
Set myFoundItems = .FindGrep
Set myColorA = myInDesign.Documents.Item(1).Colors.Item("ColorA")
If myFoundItems.Count > 0 Then
.Texts.Item(1).FillColor = myColorA
End If
myResetFindGrep myInDesign
End If
End With
apply = false
End Function
End Class
Function myResetFindGrep(myInDesign)
myInDesign.FindTextPreferences = idNothingEnum.idNothing
myInDesign.ChangeTextPreferences = idNothingEnum.idNothing
End Function
XML ルールを使用した XML 要素の抽出
XSLT は、XML ファイルからデータのサブセットを抽出する場合によく使用されます。同じことを、XML ルー
ルを使用して行うことができます。一連のサンプル XML 要素を複製して、XML 要素階層の別の場所に移動す
る方法を、次のサンプルスクリプトに示します。複製した XML 要素は、XML ルールに一致しない XML 構造の
場所に追加する必要があることに注意してください。そうしなかった場合は、無限ループに陥る恐れがあり
ます。完全なスクリプトについては、ExtractSubset を参照してください。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
Set myDocument = myInDesign.Documents.Item(1)
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
Set myXMLTag = myMakeXMLTag(myDocument, "VCOs")
Set myContainerElement =
myDocument.XMLElements.Item(1).XMLElements.Add(myXMLTag)
myRuleSet = Array(new ExtractVCO)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class ExtractVCO
Public Property Get name
name = "ExtractVCO"
End Property
Public Property Get xpath
xpath = "/devices/device/type"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
With myXMLElement
If .Texts.Item(1).Contents = "VCO" Then
Set myDestination = myXMLElement.Parent.Parent.XMLElements.Item(-1)
Set myNewElement = .Parent.Duplicate
myNewElement.Move idLocationOptions.idAtEnd, myDestination
End If
End With
apply = false
End Function
End Class
第 13 章 XML ルール
XML ルールの例
212
XML ルールを使用したフォーマットの適用
これまでの XML ルールの例では、XML 要素の検索、XML 要素の並べ替え、XML 要素へのテキストの追加を行
う基本的な方法を示しました。XML ルールはスクリプトの一部であるので、テキストフォーマットの適用か
らページアイテム、ページ、ドキュメントの新規作成まで、ほとんどすべてのアクションを実行できます。
次の XML ルールの例では、XML ルールを使用して XML 要素にフォーマットを適用する方法と、XML ルール
の一致に基づいて新規ページアイテムを作成する方法を示します。
次のスクリプトでは、XML のサンプルデータに静的テキストを追加し、フォーマットを適用しています(完
全なスクリプトについては、XMLRulesApplyFormatting を参照してください)。
Set myInDesign = CreateObject("InDesign.Application")
If myInDesign.Documents.Count > 0 Then
myFilePath = myInDesign.FilePath
myFilePath = myFilePath & "¥Scripts¥Xml rules¥glue code.vbs"
Rem Use the Include function to load the glue code file.
Include myFilePath
Set myDocument = myInDesign.Documents.Item(1)
Rem Document setup
With myDocument.ViewPreferences
.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
.VerticalMeasurementUnits = idMeasurementUnits.idPoints
End With
Rem Create a color.
Set myColor = myAddColor(myDocument, "Red", idColorModel.idProcess,
Array(0, 100, 100, 0))
Rem Create a series of paragraph styles.
Set myParagraphStyle = myMakeParagraphStyle(myDocument, "DeviceName")
myParagraphStyle.PointSize =24
myParagraphStyle.Leading = 24
myParagraphStyle.FillColor = myColor
myParagraphStyle.SpaceBefore = 24
Set myParagraphStyle = myMakeParagraphStyle(myDocument, "DeviceType")
myParagraphStyle.PointSize =12
myParagraphStyle.Leading = 12
myParagraphStyle.FontStyle = "Bold"
Set myParagraphStyle = myMakeParagraphStyle(myDocument, "PartNumber")
myParagraphStyle.PointSize =12
myParagraphStyle.Leading = 12
myParagraphStyle.FontStyle = "Bold"
Set myParagraphStyle = myMakeParagraphStyle(myDocument, "Voltage")
myParagraphStyle.PointSize =10
myParagraphStyle.Leading = 12
myParagraphStyle.FontStyle = "Bold"
Set myParagraphStyle = myMakeParagraphStyle(myDocument, "DevicePackage")
myParagraphStyle.PointSize =10
myParagraphStyle.Leading = 12
Set myParagraphStyle = myMakeParagraphStyle(myDocument, "Price")
myParagraphStyle.PointSize =10
myParagraphStyle.Leading = 12
myParagraphStyle.FontStyle = "Bold"
myRuleSet = Array(new ProcessDevice, new ProcessName, new ProcessType, new ProcessPartNumber,
new ProcessSupplyVoltage, new ProcessPrice, new ProcessPackageType, new ProcessPackageOne, new
ProcessPackages)
glueCode_ProcessRuleSet myInDesign, myDocument.XMLElements.Item(1), myRuleSet, Array()
End If
Class ProcessDevice
Public Property Get name
name = "ProcessDevice"
End Property
Public Property Get xpath
xpath = "/devices/device"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
第 13 章 XML ルール
With myXMLElement
.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
End With
apply = false
End Function
End Class
Class ProcessName
Public Property Get name
name = "ProcessName"
End Property
Public Property Get xpath
xpath = "/devices/device/name"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
.ApplyParagraphStyle myDocument.ParagraphStyles.Item("DeviceName")
End With
apply = true
End Function
End Class
Class ProcessType
Public Property Get name
name = "ProcessType"
End Property
Public Property Get xpath
xpath = "/devices/device/type"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
.InsertTextAsContent "Circuit Type: ",
idXMLElementPosition.idBeforeElement
.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
.ApplyParagraphStyle myDocument.ParagraphStyles.Item("DeviceType")
End With
apply = true
End Function
End Class
Class ProcessPartNumber
Public Property Get name
name = "ProcessPartNumber"
End Property
Public Property Get xpath
xpath = "/devices/device/part_number"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
XML ルールの例
213
第 13 章 XML ルール
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
.InsertTextAsContent "Part Number: ",
idXMLElementPosition.idBeforeElement
.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
.ApplyParagraphStyle myDocument.ParagraphStyles.Item("PartNumber")
End With
apply = true
End Function
End Class
Class ProcessSupplyVoltage
Public Property Get name
name = "ProcessPartNumber"
End Property
Public Property Get xpath
xpath = "/devices/device/supply_voltage"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
.InsertTextAsContent "Supply Voltage From: ",
idXMLElementPosition.idBeforeElement
With .XMLElements.Item(1)
.InsertTextAsContent " to ", idXMLElementPosition.idAfterElement
End With
With .XMLElements.Item(-1)
.InsertTextAsContent " volts",
idXMLElementPosition.idAfterElement
End With
.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
.ApplyParagraphStyle myDocument.ParagraphStyles.Item("Voltage")
End With
apply = true
End Function
End Class
Class ProcessPackageType
Public Property Get name
name = "ProcessPackageType"
End Property
Public Property Get xpath
xpath = "/devices/device/package/type"
End Property
Public Function apply (myXMLElement, myRulesProcessor)
With myXMLElement
.InsertTextAsContent "-", idXMLElementPosition.idAfterElement
End With
apply = true
End Function
End Class
Rem Process the first "package" element.
Class ProcessPackageOne
Public Property Get name
name = "ProcessPackageOne"
End Property
Public Property Get xpath
xpath = "/devices/device/package[1]"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
XML ルールの例
214
第 13 章 XML ルール
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
.InsertTextAsContent "Package: ",
idXMLElementPosition.idBeforeElement
Rem Because we have already added a return to the
Rem end of this element as part of the ProcessPrice
Rem rule, we can savly apply a paragrpah style.
.ApplyParagraphStyle
myDocument.ParagraphStyles.Item("DevicePackage")
End With
apply = true
End Function
End Class
Rem Process the remaining "package" elements.
Class ProcessPackages
Public Property Get name
name = "ProcessPackages"
End Property
Public Property Get xpath
xpath = "/devices/device/package"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
With myXMLElement
.InsertTextAsContent", ", idXMLElementPosition.idBeforeElement
End With
apply = True
End Function
End Class
Class ProcessPrice
Public Property Get name
name = "ProcessPrice"
End Property
Public Property Get xpath
xpath = "/devices/device/price"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
Rem Add a return at the start of the XML element.
.InsertTextAsContent vbCr & "Price: $",
idXMLElementPosition.idBeforeElement
.InsertTextAsContent vbcr, idXMLElementPosition.idAfterElement
.ApplyParagraphStyle myDocument.ParagraphStyles.Item("Price")
End With
apply = False
End Function
End Class
XML ルールの例
215
第 13 章 XML ルール
XML ルールの例
216
XML ルールを使用したページアイテムの作成
次のスクリプトでは、新しいページアイテムを作成し、そのページアイテムに XML 要素の内容を挿入し、静
的テキストを追加して、フォーマットを適用しています。ここでは、スクリプト内の該当する XML ルールの
部分のみを示します。詳しくは、完全なスクリプト(XMLRulesLayout)を参照してください。
最初のルールでは、それぞれの「device」という XML 要素に新規テキストフレームを作成します。
Class ProcessDevice
Public Property Get name
name = "ProcessDevice"
End Property
Public Property Get xpath
xpath = "/devices/device"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
If myDocument.Pages.Item(1).TextFrames.Count > 0 Then
Set myPage = myDocument.Pages.Add
myBounds = myGetBounds(myDocument, myPage)
Set myTextFrame = .PlaceIntoFrame(myPage, myBounds)
myTextFrame.TextFramePreferences.FirstBaselineOffset =
idFirstBaseline.idLeadingOffset
Else
Set myPage = myDocument.Pages.Item(1)
myBounds = myGetBounds(myDocument, myPage)
Set myTextFrame = .PlaceIntoFrame(myPage, myBounds)
myTextFrame.TextFramePreferences.FirstBaselineOffset =
idFirstBaseline.idLeadingOffset
End If
End With
apply = false
End Function
End Class
“ProcessType” ルールで、「type」という XML 要素を、ページ上の新規フレームに移動します。
Class ProcessType
Public Property Get name
name = "ProcessType"
End Property
Public Property Get xpath
xpath = "/devices/device/type"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myDocument = myInDesign.Documents.Item(1)
With myXMLElement
Set myPage = myDocument.Pages.Item(-1)
myBounds = myGetBounds(myDocument, myPage)
myX1 = myBounds(1)
myY1 = myBounds(0)
myBounds = Array(myY1-24, myX1, myY1, myX1 + 48)
Set myTextFrame = .PlaceIntoFrame(myPage, myBounds)
myTextFrame.TextFramePreferences.InsetSpacing = Array(6, 6, 6, 6)
myTextFrame.FillColor = myDocument.Swatches.Item("Red")
.ApplyParagraphStyle myDocument.ParagraphStyles.Item("DeviceType")
End With
apply = true
End Function
End Class
第 13 章 XML ルール
XML ルールを使用した表の作成
217
XML ルールを使用した表の作成
ConvertElementToTable メソッドを使用すれば、XML 要素を表に変換することができます。ただし、このメ
ソッドで表に変換できるのは、すべての XML 要素が特定の XML タグ(行タグと、セルタグまたは列タグ)で
構成されている場合のみです。多くの場合、表に変換したい XML データはそのような構造になっていません。
列に使用したい XML 要素は、「price」や「part number」などの異質な XML タグである場合が多いです。
この制限に対応するには、表の列として追加したい XML 要素を、コンテナ XML 要素を使用して「ラップ」し
ます。次のスクリプトにその例を示します(XMLRulesTable を参照してください)。この例では、XML ルール
を使用して各行の XML 要素を作成しています。
Class ProcessDevice
Public Property Get name
name = "ProcessDevice"
End Property
Public Property Get xpath
xpath = "//device[@type = 'VCO']"
End Property
Rem Create a new row for every device whose type is "VCO"
Public Function apply (myXMLElement, myRuleProcessor)
Set myInDesign = CreateObject("InDesign.Application")
Set myRowTag = myInDesign.Documents.Item(1).XmlTags.Item("Row")
Set myNewRowElement = myContainerElement.XMLElements.Add(myRowTag)
apply = false
End Function
End Class
次のルールでは、行 XML 要素内のコンテナ要素にその内容を移動してフォーマットしています。
Class ProcessPrice
Public Property Get name
name = "ProcessPrice"
End Property
Public Property Get xpath
xpath = "//device[@type = 'VCO']/price"
End Property
Public Function apply (myXMLElement, myRuleProcessor)
glueCode_skipChildren(myRuleProcessor)
With myXMLElement
Set myInDesign = CreateObject("InDesign.Application")
Set myCellTag = myInDesign.Documents.Item(1).XmlTags.Item("Column")
Set myLastElement = myContainerElement.XMLElements.Item(-1)
Set myNewElement = myLastElement.XMLElements.add(myCellTag)
Set myPriceElement = .Move(idLocationOptions.idAtBeginning,
myNewElement)
myPriceElement.InsertTextAsContent "$",
idXMLElementPosition.idBeforeElement
End With
apply = true
End Function
End Class
指定された XML 要素をすべて「ラップ」したら、コンテナ要素を表に変換します。
Set myTable = myContainerElement.ConvertElementToTable(myRowTag, myCellTag)
第 13 章 XML ルール
XML ルールプロセッサーオブジェクトのスクリプティング
218
XML ルールプロセッサーオブジェクトのスクリプティング
glue code.vbs で一連のユーティリティ関数が既に提供されていますが、XML ルールプロセッサーオブジェ
クトをスクリプトで直接操作することもできます。これは、XML ルールのサポート関数を開発したり、XML
ルールプロセッサーを別の方法で使用したりする場合に必要になります。
スクリプトを使用して、XML ルールのコンテキストの外部で XML 要素を操作した場合、XPath を使用して要
素を探すことはできません。しかし、一致する XML 要素を単純に返す XML ルールを作成して、XML ルールプ
ロセッサーでルールを適用することが可能です。次のスクリプトにその例を示します (このスクリプトで
も、以前の節のサンプルスクリプトと同じ XML データファイルを使用します)。完全なスクリプトについて
は、XMLRulesProcessor を参照してください。
myXPath = Array("/devices/device")
myXMLMatches = mySimulateXPath(myXPath)
Rem At this point, myXMLMatches contains all of the XML elements
Rem that matched the XPath expression provided in myXPath.
Rem In a real script, you could now process the elements.
Rem For this example, however, we'll simply display a message.
If IsEmpty(myXMLMatches(0)) = False Then
MsgBox "Found " & CStr(UBound(myXMLMatches)+1) & " matching elements."
Else
MsgBox "Did not find any matching XML elements."
End if
Function mySimulateXPath(myXPath)
ReDim myMatchingElements(0)
Set myInDesign = CreateObject("InDesign.Application")
Set myRuleProcessor = myInDesign.XMLRuleProcessors.Add(myXPath)
Set myDocument = myInDesign.Documents.Item(1)
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myMatchData = myRuleProcessor.StartProcessingRuleSet(myRootXMLElement)
Do While TypeName(myMatchData) <> "Nothing"
Set myXMLElement = myMatchData.Element
If IsEmpty(myMatchingElements(0)) = False Then
ReDim Preserve myMatchingElements(UBound(myMatchingElements) + 1)
End If
Set myMatchingElements(UBound(myMatchingElements)) = myXMLElement
Set myMatchData = myRuleProcessor.FindNextMatch
Loop
mySimulateXPath = myMatchingElements
End Function
14
変更のトラック
章の更新ステータス
CS6
変更なし
原稿作成や編集作業の進行中に、ドキュメントの変更のトラック、表示/非表示、適用、取り消しを実行で
きます。すべての変更は記録されていて画面で確認できるので、ドキュメントの見直しが簡単に行えます。
このチュートリアルでは、変更のトラックに関する一般的な操作をスクリプトで実行する方法について説明
します。
ここでは、読者が『Adobe InDesign スクリプティングチュートリアル』を既に読んでおり、スクリプトを作
成、インストール、実行する方法を理解しているものとして説明を行います。また、InDesign でテキストを
操作する方法や、組版に関する基本的な用語を理解しているものとしています。
変更のトラック
ここでは、スクリプトを使用して、トラックされた変更に移動したり、変更を適用および取り消しする方法
について説明します。
既存のストーリーに含まれているテキストの追加や削除、移動が行われると、その変更がゲラビューおよび
ストーリービューに示されます。
トラックされた変更への移動
トラックされた変更の記録がストーリーに含まれている場合、ユーザーはトラックされた変更に順次移動す
ることができます。トラックされた変更に移動する方法を、次のスクリプトに示します(完全なスクリプト
については、GetTrackchange を参照してください)。
次のスクリプトでは、nextItem メソッドを使用して、挿入点の後の変更に移動します。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
//Story.trackChanges
If true, track changes is turned on.
If(myStory.TrackChanges=true ) Then
Set myChange = myStory.Changes.Item(1)
If(myStory.Changes.Count>1) Then
Set myChange0 = myStory.Changes.NextItem(myChange)
End If
End If
次のスクリプトでは、previousItem メソッドを使用して、挿入点の前の変更に移動します。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
If(myStory.TrackChanges=true ) Then
Set myChange = myStory.Changes.LastItem()
If(myStory.Changes.Count>1) Then
Set myChange0 = myStory.Changes.PreviousItem(myChange)
End If
End If
219
第 14 章 変更のトラック
変更のトラック
220
トラックされた変更の適用と取り消し
ストーリーに対する変更が行われた場合、変更のトラック機能を使用してすべての変更を見直したり、ス
トーリーにすべての変更を組み込むかどうかを決定できます。ユーザーは、すべてのユーザーが行った変更
(テキストの追加や削除、移動)を適用および取り消しすることができます。
次のスクリプトでは、変更を適用します(完全なスクリプトについては、AcceptChange を参照してくださ
い)
。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myChange = myStory.Changes.Item(1)
myChange.Accept
次のスクリプトでは、変更を取り消します(完全なスクリプトについては、RejectChange を参照してくださ
い)
。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myChange = myStory.Changes.Item(1)
myChange.Reject
トラックされた変更に関する情報
変更の情報には日付や時間などが含まれています。次のスクリプトでは、トラックされた変更の情報を表示
します(完全なスクリプトについては、GetChangeInfo を参照してください)。
Set myDocument = myInDesign.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myChange = myStory.Changes.Item(1)
With myChange
Rem idChangeTypes.idDeletedText (Read Only) Deleted text.
Rem idChangeTypes.idInsertedText (Read Only) Insert text.
Rem idChangeTypes.idMovedText (Read Only) Moved text.
myTypes = .ChangeType
Rem Characters A collection of Characters.
Set myCharacters = .Characters
Rem Character = myCharacters.Item(1);
myDate = .Date
Rem InsertionPoints A collection of insertion points.
Rem insertpoint = myInsertionPoints.Item(1);
Set myInsertionPoints = .InsertionPoints
Rem Lines (Read Only) A collection of lines.
Set myLines = .Lines
Rem Paragraphs (Read Only) A collection of paragraphs.
Set myParagraphs =.Paragraphs
Rem InsertionPoints A collection of insertion points.
Rem myInsertpoint = myInsertionPoints.Item(0);
Set myStoryOffset = .StoryOffset
Rem TtextColumns (Read Only) A collection of text columns.
Set myTextColumns = .TextColumns
Rem TextStyleRanges (Read Only) A collection of text style ranges.
Set myTextStyleRanges = .TextStyleRanges
Rem TextVariableInstances (Read Only) A collection of text variable instances.
Set myTextVariableInstances = .TextVariableInstances
Rem Texts (Read Only) A collection of text objects.
Set myTexts = .Texts
Rem The user who made the change. Note: Valid only when track changes is true.
myUserName = .UserName
Rem Words A collection of words
Set myWords = .Words
End With
第 14 章 変更のトラック
変更のトラックの環境設定
221
変更のトラックの環境設定
変更のトラックの環境設定とは、変更のトラックに関するユーザー設定です。例えば、トラックされる変更
の種類(テキストの追加や削除、移動)を定義できます。トラックされた変更の種類別の外観を指定したり、
マージンの色付きの変更バーで変更を識別したりできます。これらの環境設定を設定して取得する方法を、
次のスクリプトに示します(完全なスクリプトについては、GetChangePreference を参照してください)。
Set myTrackChangesPreference = myInDesign.TrackChangesPreferences
With myTrackChangesPreference
Rem AddedBackgroundColorChoice As idChangeBackgroundColorChoices, The background color option for
added text.
Rem idChangeBackgroundColorChoices, Background color options for changed text.
Rem idChangeBackgroundUsesChangePrefColor The background color for changed text is the same as
the track changes preferences background color. For information, see background color for added
text, background color for deleted text, or background color for moved text.
Rem idChangeBackgroundUsesGalleyBackgroundColor The background color for changed text is the
same as the galley background color.
Rem idChangeBackgroundUsesUserColor The background color for changed text is the same as the
color assigned to the current user.
myAddedBackgroundColorChoice = .AddedBackgroundColorChoice
.AddedBackgroundColorChoice =
idChangeBackgroundColorChoices.idChangeBackgroundUsesChangePrefColor
Rem idChangeTextColorChoices,Changed text color options.
Rem Property AddedTextColorChoice As idChangeTextColorChoices, The color option for added text.
Rem idChangeUsesChangePrefColor,The text color for changed text is the same as the text color
defined in track changes preferences. For information, see text color for added text, text color
for deleted text, or text color for moved text.
Rem idChangeUsesGalleyTextColor,The text color for changed text is the same as the galley text
color.
myAddedTextColorChoice = .AddedTextColorChoice
.AddedTextColorChoice = idChangeTextColorChoices.idChangeUsesChangePrefColor
Rem BackgroundColorForAddedText,The background color for added text, specified as an InCopy UI
color. Note: Valid only when added background color choice is change background uses change pref
color. Type: Array of 3 Doubles (0 - 255) or idInCopyUIColors enumerator
myBackgroundColorForAddedText = .BackgroundColorForAddedText
.BackgroundColorForAddedText = idUIColors.idGray
Rem BackgroundColorForDeletedText, The background color for deleted text, specified as an InCopy
UI color. Note: Valid only when deleted background color choice is change background uses change
pref color
myBackgroundColorForDeletedText = .BackgroundColorForDeletedText
.BackgroundColorForDeletedText = idUIColors.idRed
Rem BackgroundColorForMovedText,The background color for moved text. Note: Valid only when moved
background color choice is change background uses change pref color
myBackgroundColorForMovedText = .BackgroundColorForMovedText
.BackgroundColorForMovedText = idUIColors.idPink
Rem ChangeBarColor, The change bar color, specified as an InCopy UI color.
myChangeBarColor = .ChangeBarColor
.ChangeBarColor = idUIColors.idCharcoal
Rem DeletedBackgroundColorChoice,The background color option for deleted text.
Rem idChangeBackgroundUsesChangePrefColor The background color for changed text is the same as
the track changes preferences background color. For information, see background color for added
text, background color for deleted text, or background color for moved text.
Rem idChangeBackgroundUsesGalleyBackgroundColor The background color for changed text is the
same as the galley background color.
Rem idChangeBackgroundUsesUserColor The background color for changed text is the same as the
color assigned to the current user.
myDeletedBackgroundColorChoice = .DeletedBackgroundColorChoice
.DeletedBackgroundColorChoice =
idChangeBackgroundColorChoices.idChangeBackgroundUsesUserColor
Rem DeletedTextColorChoice, The color option for deleted text.
Rem idChangeUsesChangePrefColor,The text color for changed text is the same as the text color
defined in track changes preferences. For information, see text color for added text, text color
第 14 章 変更のトラック
変更のトラックの環境設定
222
for deleted text, or text color for moved text.
Rem idChangeUsesGalleyTextColor,The text color for changed text is the same as the galley text
color.
myDeletedTextColorChoice = .DeletedTextColorChoice
.DeletedTextColorChoice = idChangeTextColorChoices.idChangeUsesChangePrefColor
Rem LocationForChangeBar,The change bar location.
Rem idChangebarLocations,Change bar location options.
Rem idLeftAlign, Change bars are in the left margin.
Rem idRightAlign, Change bars are in the right margin
myLocationForChangeBar = .LocationForChangeBar
.LocationForChangeBar = idChangebarLocations.idLeftAlign
Rem MarkingForAddedText, The marking that identifies added text.
Rem idChangeMarkings, Marking options for changed text.
Rem idOutline,
Outlines changed text.
Rem idNone, Does not mark changed text.
Rem idStrikethrough, Uses a strikethrough to mark changed text.
Rem idUnderlineSingle, Underlines changed text.
myMarkingForAddedText = .MarkingForAddedText
.MarkingForAddedText = idChangeMarkings.idStrikethrough
Rem MarkingForDeletedText, The marking that identifies deleted text.
Rem idChangeMarkings, Marking options for changed text.
Rem idOutline,
Outlines changed text.
Rem idNone, Does not mark changed text.
Rem idStrikethrough, Uses a strikethrough to mark changed text.
Rem idUnderlineSingle, Underlines changed text.
myMarkingForDeletedText = .MarkingForDeletedText
.MarkingForDeletedText = idChangeMarkings.idUnderlineSingle
Rem MarkingForMovedText, The marking that identifies moved text.
Rem idChangeMarkings, Marking options for changed text.
Rem idOutline,
Outlines changed text.
Rem idNone, Does not mark changed text.
Rem idStrikethrough, Uses a strikethrough to mark changed text.
Rem idUnderlineSingle, Underlines changed text.
myMarkingForMovedText = .MarkingForMovedText
.MarkingForMovedText = idChangeMarkings.idOutline
Rem MovedBackgroundColorChoice,The background color option for moved text.
Rem idChangeBackgroundUsesChangePrefColor The background color for changed text is the same as
the track changes preferences background color. For information, see background color for added
text, background color for deleted text, or background color for moved text.
Rem idChangeBackgroundUsesGalleyBackgroundColor The background color for changed text is the
same as the galley background color.
Rem idChangeBackgroundUsesUserColor The background color for changed text is the same as the
color assigned to the current user.
myMovedBackgroundColorChoice = .MovedBackgroundColorChoice
.MovedBackgroundColorChoice =
idChangeBackgroundColorChoices.idChangeBackgroundUsesChangePrefColor
Rem MovedTextColorChoice, The color option for moved text.
Rem idChangeUsesChangePrefColor,The text color for changed text is the same as the text color
defined in track changes preferences. For information, see text color for added text, text color
for deleted text, or text color for moved text.
Rem idChangeUsesGalleyTextColor,The text color for changed text is the same as the galley text
color.
myMovedTextColorChoice = .MovedTextColorChoice
.MovedTextColorChoice = idChangeTextColorChoices.idChangeUsesChangePrefColor
Rem if true, displays added text.
myShowAddedText = .ShowAddedText
.ShowAddedText = true
Rem If true, displays change bars.
myShowChangeBars = .ShowChangeBars
.ShowChangeBars = true
Rem ShowDeletedText, If true, displays deleted text.
myShowDeletedText = .ShowDeletedText
.ShowDeletedText = true
Rem ShowMovedText,If true, displays moved text.
第 14 章 変更のトラック
変更のトラックの環境設定
223
myShowMovedText = .ShowMovedText
.ShowMovedText = true
Rem SpellCheckDeletedText, If true, includes deleted text when using the Spell Check command.
mySpellCheckDeletedText = .SpellCheckDeletedText
.SpellCheckDeletedText = true
Rem TextColorForAddedText, The color for added text, specified as an InCopy UI color. Note: Valid
only when added text color choice is change uses change pref color.
myTextColorForAddedText = .TextColorForAddedText
.TextColorForAddedText = idUIColors.idBlue
Rem TextColorForDeletedText,The color for deleted text.
myTextColorForDeletedText = .TextColorForDeletedText
.TextColorForDeletedText = idUIColors.idYellow
Rem TextColorForMovedText,The color for moved text.
myTextColorForMovedText = .TextColorForMovedText
.TextColorForMovedText = idUIColors.idGreen
End With
Fly UP