Adobe CS6 InCopy desktop publishing software Scripting Guide
Reklam
Reklam
ADOBE
®
INCOPY
®
CS6
ADOBE INCOPY CS6
スクリプティングガイド:
VBSCRIPT
2012 Adobe Systems Incorporated. All rights reserved.
Adobe® InCopy® 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, InCopy, InDesign, Illustrator, and Photoshop are registered trademarks or trademarks of Adobe
Systems Incorporated in the United States and/or other countries. Microsoft and Windows are registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. Apple and Mac OS are trademarks 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.
目次
3
目次
4
目次
5
アサインされたストーリーのプロパティに対する繰り返し処理 . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
目次
6
1
概要
章の更新ステータス
CS6
変更なし
このマニュアルでは、次の作業を行う方法について説明します。
Adobe® InCopy® のスクリプティング環境の操作
高度なスクリプティング機能の使用
InCopy ドキュメントのテキストや書式の操作(テキストの検索と変更など)
ダイアログボックスなどのユーザーインターフェイスアイテムの作成
メニューのカスタマイズや追加と、メニューアクションの作成
ユーザーインターフェイスのイベントに対する応答
XML の操作(XML 要素の作成、XML の読み込み、レイアウトへの XML 要素の追加など)
このマニュアルに掲載されているスクリプトの使用方法
このマニュアルに掲載されているスクリプトのほとんどは、完全なスクリプトではありません。 このマニュ
アルの説明内容に関連するスクリプトから特定部分のみを抜粋した、断片的なスクリプトです。 このマニュ
アルに掲載されているスクリプトの行をコピーして、スクリプトエディタに貼り付けることができますが、
スクリプトを実行するには、さらに編集が必要になります。 また、このマニュアルからコピーしたスクリプ
さい。このような文字が含まれていると、スクリプトを正常に実行できません。
このマニュアルに掲載されているすべてのスクリプトの Zip アーカイブは、InCopy のスクリプティングホー
ムページ( http://www.adobe.com/jp/products/incopy/scripting/index.html
)で入手できます。
ウンロードして展開したら、該当するスクリプト言語に対応するフォルダーを InCopy フォルダー内の Scripts
フォルダーの下にある Scripts Panel フォルダーに移動します。 これで、InCopy のスクリプトパネルからスクリ
プトを実行できます。
スクリプトの構造について
サンプルスクリプトはすべて、main、mySetup、mySnippet、myTeardown(関数)などの共通のテンプレー
トを使用して記述されています。 この記述方式は、自動化テストとパブリケーションを簡略化するためのも
のです。通常はスクリプトをこのように構築する必要はありません。 スクリプト作成者の関心を引くと思わ
れるスクリプトの断片は、mySnippet 関数内に記述されています。
詳細情報
InCopy スクリプティングに関するユーザーフォーラム( http://www.adobeforums.com
)でも、InCopy スクリ
プティングに関する情報が入手できます。 このフォーラムでは、質問をしたり、質問に答えたり、新たに作
成したスクリプトを別のユーザーと共有したりできます。 このフォーラムでは、多数のサンプルスクリプト
が提供されています。
7
第 1 章 概要
InCopy について 8
InCopy について
InCopy は、Adobe InDesign® との統合利用を目的に開発された共同作業用のテキスト編集アプリケーションで
す。 InCopy では、変更をトラックしたり、編集上の注釈を追加したり、原稿用のスペースに合わせて原稿を
はめ込んだりすることができます。 InCopy と InDesign は同じテキスト組版エンジンを使用しているので、レ
イアウトに原稿をはめ込んだときの組版結果はまったく同じになります。
や新聞、企業出版物を共同で制作し、テキストの編集とレイアウトの編集を並行して進めることができます。
対象となるユーザーは、編集者、ライター、校正者、原稿の編集者、原稿の加工業者です。
InCopy は、多くのパネルやパレットを InDesign と共有していますが、独自のユーザーインターフェイス項目
も搭載しています。
InCopy ファイルと InDesign ファイルの関係
InCopy ファイルと InDesign ファイルの関係は重要です。これは、出版ワークフローにおける作業の分担は、
1 つの素材の大部分を両方のアプリケーションで開いて変更する場合に発生するためです。
InCopy からの一般的な書き出し方法は、2 種類あります。
(IDML ベースの)ICML ファイルを書き出すことができます。
(INX ベースの)INCX ファイルを書き出すことができます。
InDesign からの一般的な書き出し方法で、InCopy との連携を伴うものは、2 種類あります。
InCopy ファイルとして InDesign から書き出されたストーリーは、XML ファイルまたは XML ストリームで
す(この機能は、InDesign に読み込まれる InCopyExport と InCopyWorkflow のプラグインによって提供さ
である、ページの形状が一切含まれていない、XML ファイルまたは XML ストリーム内のデータは
InDesign や InCopy だけでなく検索エンジンやデータベースツールなどでも使用できるといった実用的な
特徴があります。
記事内の各グループ(見出し、署名欄、原稿、グラフィック、キャプションなど)を書き出すこともで
きます。 InDesign および InCopy では、各グループの作成をアサインファイルでサポートしています。ア
サインファイルは、その他のファイルをトラックする補助ファイルを追加することで、ファイル管理を
行います。 実際には、アサインとは、依頼作業(例えば、原稿の編集、レイアウト、原稿の作成など)
のために 1 人の人間に割り当てられる一連のファイルです。 アサインに含まれるすべてのストーリーは、
保持されます。 InDesign では、アサインに書き出すことによって、特定のストーリー一式を書き出すこと
ができます。 InCopy で、アサインに含まれているすべてのストーリーを同時に(1 つの単位として)開き
を参照してください。
ストーリー
InDesign ドキュメントは、書き出し時に、同じ数の InCopy ドキュメントにモジュール化することができま
クパネル、または InCopy のアサインパレットのアサインファイルで確認できます。
InCopy では、InDesign ドキュメントへのリンクが存在していて関連付けが行われていても、リンクは維持さ
ストーリーは、XML で構造化することができます。 つまり、XML データの中に XML データを含めることがで
いる外部の構造内に、ストーリーの未加工テキストを含めることができます。
第 1 章 概要
InCopy ファイルと InDesign ファイルの関係 9
XML で書き出すことができます。
ICML または INCX ファイルには、InCopy データとマークアップテキストの両方を含めることができます。
ファイルを XML データで書き出した場合は、InCopy 特有のデータが取り除かれ、スタイルの設定に関する情
報以外のマークアップ記述が残ります。
ページの形状
する必要があります。 InCopy では、必要な場合に InDesign ドキュメントを開いて、デザイン情報や書き出さ
れたストーリーへのリンクを抽出することができます。 InCopy 内でページの形状が必要になる場合、アサイ
ンファイルにページの形状を含めて提供することができます。
メタデータ
Adobe Extensible Metadata Platform(XMP)は、メタデータを作成、変換、管理するための実用的な方法を提
供しています。 InCopy ファイルでは、XMP がサポートされています。
XMP データを表示するために、InDesign ではファイル/ファイル情報のコマンドが用意されているように、
は、書き出し時に XMP データをそのまま残しておくことも、取り除くこともできます。
サードパーティーソフトウェア開発者によってストーリーに追加されたメタデータは、InDesign ドキュメン
トに組み込むときにそのまま保持されます。 追加されたメタデータは、InDesign 内で表示できるだけでなく
(リンクパネルのメニューにあるファイル情報ダイアログボックス)、InCopy 内でも表示できます。 さらに、
サードパーティーソフトウェア開発者は、メタデータをカスタムユーザーインターフェイスで表示する機能
を InDesign に追加することもできます。
サービスプロバイダーがメタデータの内容を InCopy ファイルに追加するための拡張のポイントがあります。
を参照してください。
ドキュメントモデル
トを使用することもできますが、デフォルトのドキュメントタイプにはなっていません。
InDesign と InCopy のいずれも、基本のドキュメントは常にデータベースです。ただし、InCopy では、このド
キュメントが不完全なドキュメントになることがあります。 InDesign では、通常、主なドキュメントは開い
ている InDesign ファイルですが、開いている INX または IDML ファイルになることもあります。通常、INX ま
たは IDML ファイルは、保存されていない InDesign ドキュメントのように見えます。
込まれている InCopy ストーリー(またはプレーンテキストや RTF テキスト)があります。 また、IDML や INX
ベースのアサインファイルもあります。これらのアサインファイルには、XML ファイルに保存されている
デルのプラグインセットに対応しており、時間とともに変更に合わせたバージョンアップが重ねられていま
により、ドキュメントをアプリケーション間で移動しても、ほとんど同様に表示することが可能になります。
ユーザーインターフェイスの違い
InDesign と InCopy は多くのパネルを共有していますが、InCopy は小型のセットで、画面の上、左、下の境界
に補助的なツールバーが表示されます。 また、InCopy の多くのパネルは、このツールバーにドッキングさせ
ることができます。ドッキングさせると、パネルは小型化されますが、常に表示されるようになります。
第 1 章 概要 設計とアーキテクチャ 10
また、InCopy には複数のビューによるカスタムウィンドウレイアウトが用意されており、メインウィンドウ
にゲラビュー、ストーリービュー、レイアウトビューの 3 つのタブがあります。 レイアウトビューは InDesign
ウィンドウのビューです。 ゲラビューとストーリービューは、単なるストーリーエディターのビューです。
ゲラビューでは正確な行末が適用され、ストーリービューでは適用されません。
設計とアーキテクチャ
ストーリーとファイルの関係
示しており、特に InDesign 以外でファイルの編集が必要な場合に適した選択です。
ICML 形式
各 InCopy ファイルやストリームは、XML 形式で記述されています。 この利点は、InCopy ファイルを簡単に解
析できることと、あらゆるテキストエディターで開けることです。
INCX 形式
が、INCX ベースのワークフローを引き続きサポートする場合に使用できます。
ドキュメントの操作
InCopy では、ドキュメントの操作(ファイルの操作)のデフォルト実装が提供されています(例えば、新
ファイルの操作は、1 つのプラグイン(InCopyFileActions)にソースコード形式で含まれています。 ソフト
ウェア開発者やシステムインテグレーターが、この部分を独自の実装内容に置き換え、それぞれのワークフ
ローシステムに合わせた相互処理にカスタマイズすることを想定しています。
XMP メタデータの使用
ユーザーは、ファイル/コンテンツファイル情報を選択して、メタデータを入力および編集できます。 この
メタデータは、InCopy ファイルに保存されます。 ソフトウェア開発者やシステムインテグレーターは、XMP
SDK を使用して、独自のメタデータを作成し保存できます。
2
はじめに
CS6
更新
CS5 に関する言及を削除または変更。
章の更新ステータス
インターフェイスに搭載されているツール、パネル、ダイアログボックスなど)と比べても、スクリプティ
ングほど時間と手間とコストを節約してくれるものはありません。
このマニュアルでは、すべての InCopy ユーザーを対象に説明を行います。 まず、スクリプトを初めて作成す
る方のために、スクリプトの基本事項について説明します。 次に、他のアプリケーション向けにスクリプト
を作成した経験がある方のために、InCopy スクリプティングの特徴について説明します。 さらに、スクリプ
トを InCopy にインストールして実行する方法や、InCopy スクリプティングで実現できることと実現できない
こと、スクリプトの作成に必要なソフトウェアについても説明します。
InCopy のユーザーインターフェイスで行える操作のほとんどは、スクリプトを使用して実行することができ
ます。 テキストの入力やフォーマット、テキストの検索や変更、注釈の追加、ドキュメントページの印刷や
書き出しなど、 ドキュメントやその内容に変更を加えるアクションは、すべてスクリプトで実行できます。 ま
た、ユーザーインターフェイスでは行えない高度な処理も実行できます。
スクリプトを使用すれば、メニューの作成、メニュー項目の追加、ダイアログボックスやパネルの作成と表
示、ユーザーインターフェイスで行われた選択への応答などが行えます。 また、テキストファイルの読み取
りや書き込み、XML データの解析、他のアプリケーションとの通信なども行えます。 スクリプトは、カーソ
ル位置でのタブストップの設定のような単純な処理から、非常に複雑な処理まで、様々な用途に活用できま
クフロー全体を自動化するスクリプトを作成できるようになります。
ワークスペースの設定やキーボードショートカットの定義など、スクリプトで実行できない操作がいくつか
ありますが、その多くはユーザーインターフェイスに関係する操作です。 また、InCopy ドキュメントに新し
い種類のオブジェクトを追加したり、InCopy の基本機能を新たに追加する(例えば、新しいテキストコンポ
ジションエンジンを追加する)こともできません。 このような拡張を行いたい場合は、InCopy ソフトウェア
開発キット(SDK)を使用して、C++ でコンパイル済みのプラグインを作成する必要があります。
InCopy は、主に Adobe InDesign® ドキュメントの製作工程の一部として使用されます。したがって、このマ
ニュアルでは、InCopy だけでなく InDesign についても触れています。 また、InDesign と InCopy のスクリプ
ティングは非常に似ています。 InDesign スクリプティングについて詳しくは、『Adobe InDesign スクリプティ
ングチュートリアル』および『Adobe InDesign スクリプティングガイド』を参照してください。
スクリプトのインストール
InCopy にスクリプトをインストールするには、InCopy アプリケーションフォルダー内の Scripts フォルダーに
ある Scripts Panel フォルダーに、スクリプトファイルを保存します。
または、ユーザー環境設定フォルダーの Scripts Panel フォルダーにスクリプトを保存します。 ユーザー環境設
定フォルダーは、次の場所にあります。
< ユーザー名 >
はユーザー名を表し、~(チルド)はシステムボリュー
ムを表します。
Windows® XP:
C:¥Documents and Settings¥< ユーザー名 >¥Application Data¥Adobe¥InCopy¥
Version 8.0-J¥ja_JP¥Scripts¥Scripts Panel
Windows® Vista:
C:¥ ユーザー ¥< ユーザー名 >¥App Data¥Roaming¥Adobe¥InCopy¥
Version 8.0-J¥ja_JP¥Scripts¥Scripts Panel
11
第 2 章 はじめに スクリプトの実行 12
このフォルダーに保存したスクリプトは、InCopy のスクリプトパネルに表示されます(このパネルを表示す
るには、ウィンドウ/スクリプトを選択します)。
Scripts Panel フォルダーには、スクリプトやスクリプトが保存されているフォルダーのエイリアスやショート
カットを保存することもできます。これらのエイリアスやショートカットも、スクリプトパネルに表示され
ます。
スクリプトの実行
スクリプトを実行するには、スクリプトパネルを表示し(ウィンドウ/スクリプトを選択し)、スクリプトパ
ネルに表示されているスクリプト名をダブルクリックします。 多くの場合、何らかのユーザーインターフェ
イス(ダイアログボックスやパネルなど)が表示され、必要に応じて警告が表示されます。
スクリプトパネルの使用
スクリプトパネルでは、コンパイル済みまたは未コンパイルの AppleScript(拡張子が
.spt
、
.as
、
.applescript
のファイル)
.js
または
.jsx
のファイル)
.vbs
の
ファイル)、実行可能ファイルを実行できます。
スクリプトパネルに表示されているスクリプトを編集するには、Option キー(Mac OS)または Alt キー
(Windows)を押しながらスクリプト名をダブルクリックします。 スクリプトのファイルタイプに対応するエ
ディターで、そのスクリプトファイルが開かれます。
スクリプトパネルに表示されているスクリプトの保存フォルダーを開くには、Command キー(Mac OS)ま
たは Ctrl キーと Shift キー(Windows)を押しながらスクリプト名をダブルクリックします。 または、スクリ
プトパネルのメニューから「Finder で表示」(Mac OS)または「エクスプローラーで表示」(Windows)を選
択します。 そのスクリプトが保存されているフォルダーが、Finder(Mac OS)またはエクスプローラー
(Windows)で表示されます。
スクリプトは一連のアクションとして実行されます。つまり、編集メニューから「取り消し」を選択して、
スクリプトで行った各変更を取り消すことができます。 スクリプトのトラブルシューティングを行う場合は、
これによって問題のアクションが見つけやすくなります。
スクリプトにキーボードショートカットを追加するには、編集/キーボードショートカットを選択し、セッ
トメニューから編集可能なショートカットセットを選択し、機能エリアメニューから「スクリプト」を選択
します。 スクリプトパネル内のスクリプトが一覧表示されます。 スクリプトを選択し、InCopy の通常の機能
と同じようにキーボードショートカットを割り当てます。
VBScript 言語の詳細
集に追加のソフトウェアが必要ないからです。VBScript は、任意のテキストエディター(メモ帳など)で編
集でき、InCopy のスクリプトパネルから実行できます。
前のバージョンの Visual Basic が適しています。Visual Basic .NET 以降のバージョンでは、InCopy スクリプティ
ングでよく使用される Variant データ型が利用できません。
Microsoft® Word、Microsoft Excel、Microsoft Visio、AutoCAD などの多くのアプリケーションには、Visual Basic
が、InCopy に VBA は搭載されていません。
Windows で VBScript や Visual Basic を使用して InCopy スクリプティングを行う場合は、管理者権限を持つユー
ザーアカウントで InCopy をインストールする必要があります。 インストール後は、すべてのユーザーが
第 2 章 はじめに このマニュアルに掲載されているスクリプトの使用方法 13
InCopy スクリプトを実行できます。Power User 権限または Administrator 権限を持つユーザーは、InCopy のス
クリプトパネルにスクリプトを追加できます。
このマニュアルに掲載されているスクリプトの使用方法
このマニュアルに記載されているスクリプトを使用するには、チュートリアルスクリプトファイルを開くか
(ファイル名は各スクリプトの前に記載されています)、この章に記載されているコードをコピーします。
スクリプトファイルは、
InCopyCS6ScriptingGuideScripts.zip
という Zip アーカイブに格納されています。
アーカイブを圧縮解除したら、目的のスクリプト言語(AppleScript、JavaScript または VBScript)で作成され
たスクリプトが保存されているフォルダーを、Scripts Panel フォルダーに移動します。 これらのスクリプト
ファイルを利用するほうが、スクリプトを直接入力したり、このマニュアルからスクリプトをコピーして貼
り付けるよりも簡単です。
スクリプトアーカイブを入手できない場合、この章に掲載されているスクリプトコードを入力することもで
1.
この Adobe PDF 形式のマニュアルからスクリプトをコピーして、テキストエディター(メモ帳など)ま
たは VBScript エディタ(VBSEdit など)に貼り付けます。
2.
Scripts Panel フォルダーに、プレーンテキストファイルとしてスクリプトを保存します(
を参照)。ファイル拡張子は .vbs を使用します。
3.
ウィンドウ/スクリプトを選択して、スクリプトパネルを表示します。
4.
スクリプトパネルでスクリプト名をダブルクリックして、スクリプトを実行します。
手入力でスクリプトを作成する方法は、この章に掲載されているスクリプトに対してのみ有効です。 他の章
に掲載されているスクリプトは、断片的なスクリプトです。完全なスクリプトではありません。 他の章のス
クリプトを実行するには、スクリプトアーカイブのスクリプトを使用する必要があります。
注意 : このマニュアルからスクリプトをコピーして貼り付ける場合は、レイアウトの都合で途中で改行され
ている文があるとエラーになる点に注意してください。 このようなエラーを発見するのは難しいことが多い
ので、Zip アーカイブのスクリプトを使用することをお勧めします。
最初の InCopy スクリプトの作成
では、InCopy スクリプトを実際に作成してみましょう。ここでは、新規ドキュメントを作成し、テキストフ
レームを追加し、そのテキストフレームにテキストを入力するスクリプトを作成します。 非常に簡単な作業
のように思えますが、このスクリプトでは次の処理を行います。
InCopy との通信を確立する。
新規ドキュメントを作成する。
ストーリーにテキストを追加する。
テキストエディター(メモ帳など)を起動し、次のスクリプトを入力します(または、
HelloWorld.vbs
とい
うチュートリアルスクリプトを開きます)。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
myStory.Contents = "Hello World!"
Scripts Panel フォルダーに、プレーンテキストファイルとしてスクリプトを保存します(
.vbs
を使用します。
リプトパネルでスクリプト名をダブルクリックします。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 14
スクリプトの動作の説明
ここでは、Hello World スクリプトの動作について、順を追って説明します。
1.
InCopy アプリケーションオブジェクトとの通信を確立します。
Set myInCopy = CreateObject("InCopy.Application")
2.
新規ドキュメントを作成して、その参照を取得します。
Set myDocument = myInCopy.Documents.Add
3.
ドキュメントの最初のストーリーへの参照を取得します(独立したドキュメントには必ずストーリーが
含まれています)。
Set myStory = myDocument.Stories.Item(1)
4.
コンテンツのプロパティに文字列を設定して、ストーリーにテキストを追加します。 myStory.Contents = "Hello World!"
スクリプティング用語と InCopy オブジェクトモデル
ここでは、次のスクリプトに進む前に、スクリプト言語に関する一般的な用語と、InCopy スクリプティング
に固有の用語について説明します。
スクリプティングの用語
まず、スクリプティングに関する一般的な用語や概念について説明します。
コメント
コメントを使用して、スクリプトに説明用のテキストを追加することができます。 コメントはスクリプトの
実行時には無視され、エラーが発生しないようになっています。 スクリプトの処理について、自分や他人の
ために注釈を残しておきたい場合は、コメントを使用すると便利です。 このマニュアルのチュートリアルス
クリプトでも、コメントを使用しています。
VBScript でコメントを入力するには、コメントの左に「
Rem
」 「remark」の意味です)または「
'
」と入力し
ます。 1 行全体をコメントにする場合は、行の先頭にコメントのマーカーを入力します。 次に例を示します。
Rem this is a comment
' and so is this
値
InCopy スクリプティングで使用される値の例としては、テキストの文字のポイントサイズ、注釈の内容、ド
キュメントのファイル名などがあります。 値とは、スクリプトで処理を行う際に使用するデータのことです。
値にどのような種類のデータが含まれるかは、値の型によって定義されます。 例えば、単語が格納されてい
る値の型は文字列で、段落の行送りの値の型は数値です。 通常、スクリプトで使用される値は数値かテキス
トです。 InCopy スクリプティングで最もよく使用される値の型を、次の表に示します。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 15
値の型
Boolean
Integer
Double
String
Array
説明
真(True)か偽(False)かを表す論
理値。
例
True
14
数と負の整数があります。
精度の高い数値。小数点が含まれる
ことがあります。
一連のテキスト文字。 文字列は引用
符で囲みます。
値のリスト(この値はどの型であっ
てもかまいません)。
13.9972
" これは文字列です "
Array("0p0", "0p0", "16p4", "20p6")
値の型の変換
字列への変換(テキストの中に挿入したり、ダイアログボックスに表示したりする場合に行います)と、文
字列から数値への変換(ポイントサイズやページ位置を設定する場合に行います)の 2 つです。
Rem To convert from a number to a string:
myNumber = 2
myString = cstr(myNumber)
Rem To convert from a string to an integer:
myString = "2"
myNumber = cInt(myString)
Rem If your string contains a decimal value, use "cDbl" rather than "cInt":
myNumber = cDbl(myString)
変数
変数は、値を格納する入れ物のようなものです。 「変数」という名前が表しているように、この入れ物に格
納する値は変更することができます。 変数には数値が格納されることもありますし、テキスト文字列や、
照するときにはこの名前を使用します。 変数に値を格納するには、その変数にデータを割り当てます。
InCopy のすべてのサンプルスクリプトやチュートリアルスクリプトでは、変数名はすべて my
で始まってい
ます。 このようにすることで、スクリプトで独自に作成した変数と、スクリプト言語の予約語を簡単に区別
できるようにしています。
変数への値の割り当て
変数に値や文字列を割り当てるのは簡単です。その方法を次の例に示します。 myNumber = 10
myString = "Hello, World!"
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
変数には、意味のある名前を付けるようにしてください。 firstPage
や corporateLogo
などは良い例です。 x
や c
などは悪い例です。
スクリプトの実行速度に悪影響を与えることはありません。
変数は、1 つの単語である必要があります。ただし、読みやすくするために途中で大文字を使用したり
( myFirstPage
、アンダースコアを使用したり( my_first_page
など)することができます。
初の文字に数字を使用することはできません。また、変数名に句読点や引用符を含めることもできません。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 16
配列変数
配列には、一連の値を格納することができます。 myArray = Array(1, 2, 3, 4)
Rem In Visual Basic.NET: myArray = New Double (1, 2, 3, 4)
配列に含まれている要素を参照するには、その要素のインデックスを参照します。VBScript では、配列の最
初の要素は要素 0 です。 myFirstArrayItem = myArray(0)
注意 : Visual Basic では、
OptionBase
文を使用して、配列の最初の要素を要素 1 に設定することができます。
このマニュアルの例では、配列の最初の要素は要素 1 ではなく、デフォルトのとおり要素 0 としています。
OptionBase
を 1 に設定している場合は、掲載されているサンプルスクリプトの配列参照の部分を、すべて適
切に変更する必要があります。
次の例のように、配列の中にさらに別の配列を含めることができます。 myArray = Array(Array(0,0), Array(72, 72))
Rem In Visual Basic.NET: myArray = New Array(New Double(0,0), NewDouble (0,0))
変数の値の型を調べる
オブジェクトの値の型に基づいて判断を行いたい場合があります。 例えば、選択されたテキストに対して処
理を実行するスクリプトでは、何も選択されていない場合には処理を停止する必要があります。
Rem Given a variable of unknown type, "myMysteryVariable"...
myType = TypeName(myMysteryVariable)
Rem myType will be a string corresponding to the variable type (e.g., "Rectangle")
演算子
演算子は、変数や値を使用して計算(加算、減算、乗算、除算)を実行し、値を返します。 例えば、
MyWidth/2
では、変数 myWidth
に格納されている値の半分の値が返されます。
また、演算子を使用して比較(等しい(
=
こともできます。 例えば、
、等しくない(
<>
)、より大きい(
>
、より小さい(
<
))を行う
MyWidth > myHeight
では、 myWidth
が myHeight
よりも大きい場合には true
(または 1)が、そうでない場合には false
(0)が返
されます。
VBScript では、アンパサンド(
&
)を使用して 2 つの文字列を連結(結合)させることができます。 例えば、
"Pride " & "and Prejudice"
とすると、次の文字列が返されます。
"Pride and Prejudice"
条件文
「もし選択されているテキストのサイズが 12 ポイントなら、そのポイントサイズを 10 ポイントに設定しなさ
(選択されているテキストのカラー、ドキュメントのページ数、日付など)を評価して、その結果に従って処
理を行うことができます。 条件文は、ほとんどの場合 if
で始まります。
第 2 章 はじめに
制御構造
スクリプティング用語と InCopy オブジェクトモデル 17
令をしていたことでしょう。 スクリプティングの用語では、このような命令のことを制御構造と呼びます。 制
御構造を使用すると、反復作業、つまりループ処理を行うことができます。 ループの考えは、それぞれルー
プ内で変化があったかなかったかに関わらず、特定の条件を満たすまで、ある動作を何度も何度も繰り返す
ことです。 for
で始まります。
関数
関数とは、スクリプトの中から参照することができるスクリプティングモジュールのことです。 関数に値
(または一連の値)を渡して、返される値を取得する、というのが一般的な使い方です。 関数は、何か特別な
コードで構成されているわけではありません。これらは、スクリプトの中で同じコードを何度も入力する手
間を省くためのものです。 関数は function
で始まります。
InDesign および InCopy オブジェクトモデルの理解
InCopy と InDesign ドキュメントの関係を考えるとき、おそらくプログラムと、そのコンポーネントの関係を
考えるでしょう。 同様に、段落はテキストフレームの中にあり、テキストフレームはページの中にあり、 ペー
ジはスプレッドの中にあり、いくつかのスプレッドが集まって 1 つのドキュメントを構成していることもご
存知だと思います。 ドキュメントにはカラー、スタイル、レイヤー、マスタースプレッドなども含まれてい
ます。 ドキュメントにオブジェクトを作成するユーザーは、それらの間に一定の序列があることを直感的に
理解しています。
InDesign や InCopy も、ドキュメントのコンテンツを同じような考え方で「認識」しています。ドキュメント
の中にはページが含まれており、ページの中にはページアイテム(テキストフレーム、長方形、楕円形など)
が含まれています。 テキストフレームの中には文字、単語、段落、アンカーフレームなどが含まれています。
グラフィックフレームの中には画像、EPS、PDF などが含まれています。グループの中には他のページアイテ
ムが含まれています。 これらはすべて、InDesign パブリケーションを構成するオブジェクトです。InDesign お
よび InCopy スクリプトでは、このオブジェクトに対して何らかの操作を行います。
パブリケーションの中にあるオブジェクトは、一定の序列に従って編成されています。 例えば、段落はス
トーリーの中にあり、ストーリーはドキュメントの中にあり、ドキュメントは InCopy アプリケーションオブ
ジェクトの中にあります。 オブジェクトモデルや階層という言葉は、このような構造のことを指しています。
目的のオブジェクトにアクセスするためには、このオブジェクトモデルを理解している必要があります。
InCopy の構造を理解することが、InCopy スクリプティングをマスターする秘訣であると言えます。
オブジェクトにはプロパティ(属性)があります。 例えば、テキストオブジェクトには、テキストの書式設
定に使用するフォント、ポイントサイズ、テキストに適用する行送りなどのプロパティがあります。
プロパティには値が設定されます。例えば、テキストのポイントサイズには、ポイント数を表す数値や、自
動行送りを表す「Auto」などの文字列が設定されます。 また、テキストの塗りカラーには、1 つのカラー、グ
ラデーション、混合インキ、スウォッチなどが設定されます。
プロパティには、読み書き可能なものと読み取り専用のものがあります。 読み書き可能なプロパティは、別
の値に変更することができますが、読み取り専用のプロパティは変更できません。
また、オブジェクトにはメソッドが用意されています。 これは、そのオブジェクトが実行できるアクション
を表しており、スクリプトの中で「動詞」として使用されます。 例えば、ドキュメントオブジェクトには、
印刷、書き出し、保存などを行うメソッドが用意されています。
メソッドはパラメーターを取ります。パラメーターは、メソッドの動作を定義するための値です。 例えば、 open メソッドは、開くファイルを定義するためのパラメーターを取ります。
解するための概念的なフレームワークなので、InCopy スクリプティングで利用できるオブジェクトを完全に
網羅したものではありません。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 18 application documents libraries books application preferences application defaults application events application menus application properties application methods a document document preferences document defaults document events document properties document methods document elements pages or spreads stories page text objects
この図に示されている各オブジェクトについて、次の表で説明します。 page items
用語
Application
Application defaults
Application events
Application menus
Application methods
Application preferences
Application properties
Books
Document
表しているもの
InCopy。
アプリケーションのデフォルト設定。カラー、段落スタイル、オブジェクトスタイルな
ど。 アプリケーションのデフォルト設定はすべての新規ドキュメントに影響を与えます。
ユーザーやスクリプトがアプリケーションを操作したときに発生します。 例えば、ドキュ
メントのオープン、クローズ、保存を行ったときや、メニュー項目を選択したときなどに
イベントが生成されます。 イベントに反応してスクリプトを実行させることができます。
InCopy のユーザーインターフェイスに表示されるメニュー、サブメニュー、コンテキスト
メニュー。 メニューの選択にスクリプトを関連付けたり、スクリプトからメニューアク
ションを実行したりできます。
アプリケーションが実行できるアクション。テキストの検索と変更、選択項目のコピー、
新規ドキュメントの作成、ライブラリのオープンなど。
テキストの環境設定、PDF 書き出しの環境設定、ドキュメントの環境設定など。 環境設定
オブジェクトの多くはドキュメントレベルにも存在しています。 ユーザーインターフェイ
スの場合と同じように、アプリケーションの環境設定は新規ドキュメントに適用されま
す。ドキュメントの環境設定は特定のドキュメントの設定を変更します。
アプリケーションのプロパティ。アプリケーションのフルパス、アプリケーションのロ
ケール、ユーザー名など。
開かれているブックのコレクション。
InCopy ドキュメント。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 19
用語
Document defaults
Document elements
Document events
Document methods
Document preferences
Document properties
Documents
Libraries
Page
Page item
表しているもの
ドキュメントのデフォルト設定。デフォルトのカラー、段落スタイル、デフォルトのテキ
スト書式など。
ドキュメントのストーリー、読み込んだグラフィック、ページなど。 ページやストーリー
もドキュメント要素ですが、これらは他のオブジェクトを格納するコンテナとして特に重
要な要素なので、この表の前にある図では独立して示されています。ドキュメント要素に
は、このほかにも、長方形、楕円形、グループ、XML 要素などの、読み込んだり作成した
りできるあらゆる種類のオブジェクトが含まれます。
ドキュメントレベルで発生するイベント。テキストの読み込みなど。 この表の
「Application events」を参照してください。
ドキュメントが実行できるアクション。ドキュメントのクローズ、印刷、書き出しなど。
ドキュメントの環境設定。ガイド、表示、ドキュメントの環境設定など。
ドキュメントのファイル名、ページ数、原点の位置など。
開かれているドキュメントのコレクション。
開かれているライブラリのコレクション。
InCopy ドキュメント内の 1 つのページ。
ページ上に作成または配置できる任意のオブジェクト。 ページアイテムには、テキストフ
レーム、長方形、グラフィックの線、グループなど多くの種類があります。
InCopy ドキュメント内のページまたはスプレッド。
Pages or spreads
Stories
Text objects
InCopy ドキュメント内のテキスト。
InCopy ストーリーには、文字、単語、線、段落、テキスト列などのテキストオブジェクト
が含まれます。
InCopy オブジェクトモデルの参照
クトとそのプロパティやメソッドに関する参照情報は、すべてモデルに格納されており、スクリプト編集ア
プリケーションで参照することができます。
InCopy オブジェクトモデルを表示するには、VBScript のエディターやデバッガー、Visual Basic の一部のバー
ジョン、Visual Basic for Applications が搭載されているアプリケーションのいずれかが必要です。
Visual Basic 6
Visual Basic 6 を使用してオブジェクトモデルを参照するには:
1.
Visual Basic のプロジェクトを新規作成し、プロジェクト/参照設定を選択します。
ボックスが表示されます。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 20
2.
利用可能な参照のリストから「Adobe InCopy CS6_J Type Library」オプションを選択して、「OK」をクリッ
クします。 このライブラリがリストにない場合は、「参照」ボタンをクリックし、「Resources for Visual
Basic.tlb」ファイルを探して選択します。
~¥Documents and Settings¥< ユーザー名 >¥
Application Data¥Adobe¥InCopy¥Version 8.0-J¥ja_JP¥Scripting Support¥8.0¥
の中にあります
(< ユーザー名 > はユーザー名を表し、~(チルド)はシステムボリュームを表します)。 必要に応じて
ファイルを検索してください。 ファイルが見つかったら「開く」をクリックして、プロジェクトに参照
を追加します。
3.
表示/オブジェクトブラウザーを選択します。 オブジェクトブラウザーダイアログボックスが表示され
ます。
4.
プロジェクト/ライブラリメニューに表示されている、開いているライブラリのリストの中から、
「InCopy」を選択します。 InCopy オブジェクトモデルを構成するオブジェクトが表示されます。
5.
オブジェクトクラスをクリックします。 そのオブジェクトのプロパティとメソッドが表示されます。 プロ
パティまたはメソッドの詳細を参照するには、その項目を選択します。オブジェクトブラウザーウィン
ドウの一番下に、その項目の定義が表示されます。
Visual Basic Express 2008 / Visual Basic.NET
Visual Basic Express 2008 / Visual Basic.NET を使用してオブジェクトモデルを参照するには:
1.
Visual Basic のプロジェクトを新規作成し、プロジェクト/参照の追加を選択します。
ログボックスが表示されます。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 21
2. 「COM」タブを選択します。
3.
利用可能な参照のリストから「Adobe InCopy CS6_J Type Library」を選択します。 選択済みコンポーネント
のリストに参照が追加されます。 このライブラリがリストにない場合は、「参照」ボタンをクリックし、
「Resources for Visual Basic.tlb」ファイルを探して選択します。 このファイルは、通常は
~¥Documents and
Settings¥< ユーザー名 >¥Application Data¥Adobe¥InCopy¥Version 8.0-J¥ja_JP¥Scripting Support¥8.0¥
の中にあります(< ユーザー名 > はユーザー名を表します)。 ファイルが見つかったら「開く」をクリッ
クして、プロジェクトに参照を追加します。
4. 「OK」をクリックします。
5.
表示/オブジェクトブラウザーを選択します。 「オブジェクトブラウザー」タブが表示されます。
6.
オブジェクトウィンドウで、開かれているライブラリのリストから「interop.incopy」を選択します。
InCopy オブジェクトモデルを構成するオブジェクトが表示されます。
7.
オブジェクトクラスをクリックします。 そのオブジェクトのプロパティとメソッドが表示されます。 プロ
パティまたはメソッドの詳細を参照するには、その項目を選択します。オブジェクトブラウザーウィン
ドウの一番下に、その項目の定義が表示されます。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 22
Visual Basic for Applications
Microsoft Excel から Visual Basic for Applications を使用してオブジェクトモデルを参照するには:
1.
Excel を起動します。
2.
ツール/マクロ/ Visual Basic Editor を選択します。 Visual Basic Editor のウィンドウが表示されます。
3.
ツール/参照設定を選択します。 参照設定ダイアログボックスが表示されます。
4.
利用可能な参照のリストから「Adobe InCopy CS6_J Type Library」を選択して、「OK」をクリックします。
選択済みコンポーネントのリストに参照が追加されます。 このライブラリがリストにない場合は、「参
照」ボタンをクリックし、「Resources for Visual Basic.tlb」ファイルを探して選択します。 このファイルは、
通常は
~¥Documents and Settings¥< ユーザー名 >¥Application Data¥Adobe¥InCopy¥Version 8.0-J¥ja_JP¥
Scripting Support¥8.0¥
の中にあります(< ユーザー名 > はユーザー名を表します) ファイルが見つ
かったら「開く」をクリックして、プロジェクトに参照を追加します。
5.
表示/オブジェクトブラウザーを選択します。 オブジェクトブラウザーウィンドウが表示されます。
6.
ライブラリのポップアップメニューから「InCopy」を選択します。 InCopy オブジェクトライブラリのオ
ブジェクトのリストが表示されます。
7.
オブジェクト名をクリックします。 そのオブジェクトのプロパティとメソッドが表示されます。 プロパ
ティまたはメソッドの詳細を参照するには、その項目を選択します。オブジェクトブラウザーウィンド
ウの一番下に、その項目の定義が表示されます。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 23
測定値と位置
InCopy では、どのアイテムやオブジェクトも、設定されている測定値に従ってページ上に配置されます。
InCopy の座標系の仕組みと、使用される測定単位について理解しておくと、スクリプトを書く際にその知識
が役に立ちます。
座標
他のページレイアウトプログラムやドロープログラムと同じように、InCopy でも、単純な 2 次元座標を使用
してページやスプレッド上のオブジェクトの位置を設定します。 座標は 2 つの値の組で表しますが、そのう
ちの水平成分を x と呼び、垂直成分を y と呼びます。 選択ツールでオブジェクトを選択すると、変形パネルや
コントロールパネルにこの座標が表示されます。 座標は、InCopy のユーザーインターフェイスと同様に、定
規の現在の原点からの相対位置で測定されます。
は、InCopy の座標では、垂直軸(y 軸)の原点より下が正の数であり、原点より上が負の数である、という
ことです。
測定単位
とができます。 数値を渡したときには、パブリケーションの現在の測定単位が使用されます。測定文字列
(後述の表を参照)を渡したときには、その文字列で指定した測定単位が使用されます。
れる測定値は、変形パネルに表示される測定値と表記の仕方が違うことがあります。 例えば、現在の測定単
位系がパイカである場合、端数のある値はパイカとポイントの形(変形パネルでの表記法)ではなく、小数
の形で返されます。 例えば、「1p6」は「1.5」と返されます。 このようにしている理由は、スクリプティング
システムで測定文字列を使用して算術演算を行おうとすると問題が生じるからです。 例えば、「13p4」に
「0p3.5」を足そうとするとスクリプトエラーが発生します。13.333 に .2916(どちらもパイカに換算した値)
を足す場合にはエラーは発生しません。
スクリプトで特定の測定値の加減乗除を行う場合には、スクリプトの始めの部分で測定単位を設定します。
そして、スクリプトの終わりの部分で、スクリプトを実行する前の測定単位に戻します。 または、多くのサ
ンプルスクリプトで行っているように、測定単位をオーバーライドすることができます。 これを行うには、
特別な文字が含まれた文字列を使用します。次に例を示します。
オーバーライド
c cm i(または in) mm p pt
意味
シセロ(必要に応じて c の後にディド値を追加できます)
センチメートル
インチ
ミリメートル
パイカ(必要に応じて p の後にポイント値を追加できます)
ポイント
例
1.4 c
.635 cm
.25 i
6.35 mm
1p6
18 pt
第 2 章 はじめに 「Hello World」への機能の追加 24
「Hello World」への機能の追加
次に、最初のスクリプトで作成した「Hello World」パブリケーションに変更を加える新しいスクリプトを作
アクティブなドキュメントを取得する。
最初のストーリー内のテキストのフォーマットを変更する。
注釈を追加する。
ImprovedHelloWorld チュートリアルスクリプトを開くか、または次の手順に従ってスクリプトを作成します。
1.
任意のテキストエディター(メモ帳など)を起動します。
2.
作成したドキュメントが開いていることを確認します。 ドキュメントを保存せずに閉じてしまった場合
は、
HelloWorld.vbs
スクリプトをもう一度実行すればドキュメントが新たに作成されます。
3.
次のコードを入力します。
Set myInCopy = CreateObject("InCopy.Application")
Rem Disable normal error handling (trying to get a non-
Rem existent font can cause errors).
On Error Resume Next
Rem Enter the name of a font on your system, if necessary.
Set myFont = myInCopy.Fonts.Item("Arial")
If Error.Number <> 0 Then
Error.Clear
End If
Rem Resume normal error handling.
On Error Goto 0
Rem Get the active document and assign the result to the variable "myDocument"
Set myDocument = myInCopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Rem Change the font, size, and paragraph alignment.
If TypeName(myFont) <> "Nothing" Then
myStory.AppliedFont = myFont
End If
myStory.PointSize = 48
myStory.Justification = idJustification.idCenterAlign
Rem Enter the note at the last insertion point of the story.
Set myInsertionPoint = myStory.InsertionPoints.Item(-1)
Set myNote = myInsertionPoint.Notes.Add
myNote.Texts.Item(1).Contents = "This is a Note."
4.
スクリプトパネル用のフォルダーに、プレーンテキストファイルとしてテキストを保存します(
.vbs
を使用します。
スクリプトパネルでスクリプト名をダブルクリックして、新しいスクリプトを実行します。
3
スクリプティング機能
CS6 編集
章の更新ステータス
および 3 つの副節を、更新、修正および明確化しました。
この章では、InCopy のスクリプティング環境に関連するスクリプティングテクニックを紹介します。 InCopy
のスクリプトモデルを構成するオブジェクトのほとんどは、アプリケーションのデフォルトやドキュメント
を操作するためのオブジェクトですが、 この章ではまず、スクリプトそのものを制御する方法について説明
します。
この章の内容は、次のとおりです。
ScriptPreferences
オブジェクトとそのプロパティ
実行中のスクリプトへの参照の取得
以前のバージョンのスクリプトオブジェクトモデルに基づいたスクリプトの実行
DoScript
メソッドを使用したスクリプトの実行
InCopy の起動時におけるスクリプトの自動実行
ここでは、読者が
を既に読んでおり、該当するスクリプト言語で InCopy のスクリプトを
作成、インストール、実行する方法を理解しているものとして説明を行います。
スクリプトの環境設定
ScriptPreferences
オブジェクトには、InCopy でのスクリプトの実行方法に関連するオブジェクトやプロパ
ティが用意されています。 次の表に、ScriptPreferences オブジェクトの各プロパティの詳細を示します。
プロパティ
EnableRedraw
ScriptsFolder
ScriptsList
説明
スクリプトパネルからスクリプトを実行している最中の画面の再描画をオン
またはオフにします。
Scripts フォルダーへのパス。
使用可能なスクリプトのリスト。 このプロパティは、次に示すような配列の
配列を返します。
[[fileName, filePath], ]
fileName
はスクリプトファイルの名前を表し、
filePath
はスクリプトへの
フルパスを表します。 この機能を使用すれば、目的のスクリプトがインス
トールされているどうかを確認できます。
25
第 3 章 スクリプティング機能 現在のスクリプトの取得 26
プロパティ
UserInteractionLevel
Version
説明
このプロパティは、ユーザーに表示する警告やダイアログボックスを制御し
ます。 idUserInteractionLevels.idNeverInteract
に設定
すると、警告やダイアログボックスは一切表示されなくなります。 idUserInteractionLevels.idInteractWithAlerts
に設定すると、警告は有
効になりますが、ダイアログボックスは無効になります。 idUserInteractionLevels.idInteractWithAll
に設定すると、警告とダイア
ログボックスは通常どおりに表示されます。 警告の表示をオフにする機能
は、スクリプトでドキュメントを開く場合に便利です。InCopy では、フォ
ントやリンク先のグラフィックファイルが見つからないと警告が表示されま
す。 idUserInteractionLevels.idNeverInteract
に設定し
てからドキュメントを開き、スクリプトを終了する直前にプロパティを元に
戻せば( idUserInteractionLevels.idInteractWithAll
告が表示されるのを避けられます。
を参照してください。 このプロパティは、アプリ
ケーションのバージョンと同じではないことに注意してください。
現在のスクリプトの取得
現在のスクリプトへの参照を取得するには、アプリケーションオブジェクトの
ActiveScript
プロパティを使
用します。 このプロパティは、現在のスクリプトが保存されている場所を基準にしてファイルやフォルダー
を検索する場合に役立ちます。次のスクリプトにその例を示します(チュートリアルスクリプトの
Set myInCopy = CreateObject("InCopy.Application")
myActiveScript = myInCopy.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
プロパティで返されるのは、スクリプトパレットから実行したスクリ
プトのみです。
スクリプトのバージョン対応
InCopy では、以前のバージョンの InCopy スクリプトオブジェクトモデルに基づいて作成されたスクリプトを
実行できます。 新しいバージョンの InCopy で古いスクリプトを実行する場合は、次の点に注意する必要があ
ります。
ターゲットの設定 - スクリプトを実行する InCopy のバージョン(現在のバージョン)をターゲットに設
言語によって異なります。
コンパイル - この段階では、スクリプトで使用されている名前が InCopy で認識できるスクリプト ID に
異なります。
インタープリターによる実行 - この段階では、スクリプト ID が InCopy の適切なハンドラーに関連付けら
れます。これにより InCopy は、以前のバージョンのスクリプトオブジェクトモデルに基づいて作成され
たスクリプトも正しく解釈できるようになります。 そのためには、スクリプトでアプリケーションのス
第 3 章 スクリプティング機能 スクリプトのバージョン対応 27
クリプト環境設定に古いオブジェクトモデルを明示的に設定するか(
に示すとおり)
フォルダー
Version 8.0 Scripts
Version 7.0 Scripts
Version 6.0 Scripts
Version 5.0 Scripts
Version 2.0 Scripts
スクリプトの InCopy バージョン
CS6
CS5 および CS5.5
CS4
CS3
CS2
ターゲットの設定
スクリプトを実行する InCopy のバージョン(現在のバージョン)が、スクリプトでターゲットとして明示的
または暗黙的に設定されている必要があります。 スクリプトパネルからスクリプトを実行すると暗黙的に
ターゲットが設定されます。
Visual Basic アプリケーションや VBScript で明示的にターゲットを設定するには、
CreateObject
メソッドを使
用します。
Rem Target InCopy CS6 Roman:
Set myApp = CreateObject("InCopy.Application.CS6")
Rem Target InCopy CS6 J:
Set myApp = CreateObject("InCopy.Application.CS6_J")
Rem Target the last version of InCopy that was launched:
Set myApp = CreateObject("InCopy.Application")
コンパイル
Visual Basic アプリケーションのコンパイルでは、以前のバージョンのタイプライブラリを参照してバージョ
ンの対応を行うことができます。 以前のバージョンのタイプライブラリを生成するには、Application オブ
ジェクトの PublishTerminology メソッドを使用します。 これによって、アプリケーションの環境設定フォル
ダー内の
Scripting Support
フォルダーにある、DOM のバージョンと同じ名前のフォルダーにタイプライブ
ラリが生成されます。 例えば、CS5 用語説明を
C:¥Documents and Settings¥< ユーザー名 >¥Application
Data¥Adobe¥InCopy¥Version 8.0-J¥ja_JP¥Scripting Support¥8.0
フォルダーに生成するには、次のようにし
ます。
Set myApp = CreateObject("InCopy.Application")
Rem Publish the InCopy CS5 type library (version 7.0 DOM)
myApp.PublishTerminology(7.0)
ジョンに基づいて、対応するタイプライブラリが自動的に生成されて参照されます。
インタープリターによる実行
インタープリターで使用するスクリプトオブジェクトモデルのバージョンを取得したり設定したりするには、
InCopy アプリケーションオブジェクトの
ScriptPreferences
オブジェクトを使用します。
アプリケーションの現在のバージョンに設定されており、変更されるまでそのバージョンが使用されます。
例えば、スクリプトオブジェクトモデルのバージョンを CS5 に変更するには、次のようにします。
Set myInCopy = CreateObject("InCopy.Application")
Rem Set to 7.0 DOM
myInCopy.ScriptPreferences.Version = 7.0
第 3 章 スクリプティング機能
DoScript メソッドの使用 28
DoScript メソッドの使用
DoScript
このメソッ
ドには、有効なスクリプトコードを表す文字列か、ディスク上のスクリプトファイルを指定できます。 指定
するスクリプトは、現在のスクリプトと同じ言語であっても、異なる言語であってもかまいません。 使用で
きる言語はプラットフォームによって異なります。Mac OS® の場合は AppleScript または JavaScript を実行で
きます。Windows® の場合は VBScript または JavaScript を実行できます。
DoScript
メソッドは、次の様々な場合に利用できます。
使用したい機能が、メインのスクリプト言語ではサポートされておらず、別の言語でサポートされてい
る場合。 例えば、VBScript にはファイルブラウザーやフォルダーブラウザーを表示する機能はありません
が、JavaScript にはこの機能が用意されています。 AppleScript では三角関数(サインやコサイン)の計算
に時間がかかる場合がありますが、JavaScript では高速に処理できます。 JavaScript では、Microsoft® Excel
スプレッドシートのセルの内容を照会することはできませんが、AppleScript や VBScript を使用すれば行
うことができます。 どの場合も、別の言語で断片的なスクリプトコードを作成して
DoScript
メソッドで
実行すれば、メインのスクリプト言語の制約を回避することができます。
スクリプトを動的に生成して実行する場合。 実行時にスクリプトの文字列を動的に生成して、
DoScript
メソッドで実行することができます。 この方法は、選択されている内容や作成するオブジェクトの属性
に基づいてダイアログボックスやパネルをカスタマイズしたい場合などに適しています。
オブジェクトにスクリプトを埋め込む場合。
DoScript
メソッドを使用すれば、オブジェクトの label
プ
ロパティに文字列として保存されているスクリプトを実行することができます。 このテクニックを利用
すると、特定のパラメーターに基づいてレイアウトプロパティを制御したり内容を更新したりするスク
リプトを、オブジェクト自体に埋め込むことができます。 また、XML 要素にも、属性またはコンテンツ
を
参照してください。
DoScript へのパラメーターの渡し方
DoScript
で実行するスクリプトにパラメーターを渡すには、次のようにします(チュートリアルスクリプト
の DoScriptParameters より)。
Set myInCopy = CreateObject("InCopy.Application")
myJavaScript = "alert(""First argument: "" + arguments[0] + ""¥rSecond argument: "" + arguments[1]);"
myInCopy.DoScript myJavaScript, idScriptLanguage.idJavascript, Array("Hello from DoScript", "Your message here.")
myVBScript = "msgbox arguments(1), vbOKOnly, ""First argument: "" & arguments(0)"
myInCopy.DoScript myVBScript, idScriptLanguage.idVisualBasic, Array("Hello from DoScript", "Your message here.")
DoScript からの戻り値
DoScript
で実行するスクリプトから値を返すには、アプリケーションの
ScriptArgs
オブジェクトを使用し
ます(この名前は、「script arguments」を縮めたものです)。 次のスクリプトにその例を示します(完全なス
クリプトについては、DoScriptReturnValue というチュートリアルスクリプトを参照してください)。
第 3 章 スクリプティング機能 起動時におけるスクリプトの自動実行 29
Set myInCopy = CreateObject("InCopy.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
myInCopy.DoScript myJavaScript, idScriptLanguage.idJavascript
myScriptArgumentA = myInCopy.ScriptArgs.GetValue("ScriptArgumentA")
myScriptArgumentB = myInCopy.ScriptArgs.GetValue("ScriptArgumentB")
MsgBox "ScriptArgumentA: " & myScriptArgumentA & vbCr & "ScriptArgumentB: " & myScriptArgumentB
myVBScript = "Set myInCopy = CreateObject(""InCopy.Application"")" & vbCr
myVBScript = myVBScript & "myInCopy.ScriptArgs.SetValue ""ScriptArgumentA"", ""This is the first script argument value.""" & vbCr
myVBScript = myVBScript & "myInCopy.ScriptArgs.SetValue ""ScriptArgumentB"", ""This is the second script argument value."""
myInCopy.DoScript myVBScript, idScriptLanguage.idVisualBasic
myScriptArgumentA = myInCopy.ScriptArgs.GetValue("ScriptArgumentA")
myScriptArgumentB = myInCopy.ScriptArgs.GetValue("ScriptArgumentB")
MsgBox "ScriptArgumentA: " & myScriptArgumentA & vbCr & "ScriptArgumentB: " & myScriptArgumentB
起動時におけるスクリプトの自動実行
InCopy の起動時にスクリプトを自動実行させるには、Scripts フォルダーの下にあるスタートアップ用のフォ
ルダーである Startup Scripts フォルダーにスクリプトファイルを保存します(詳しくは、
4
テキストと組版
章の更新ステータス
CS6
変更なし
テキストの入力、編集、フォーマットといった作業は、InCopy ドキュメントの製作工程の中でも、最も時間
のかかる作業の 1 つです。 したがって、テキストや書式に関する作業を自動化できれば、生産性の大幅な向
上が期待できます。
このチュートリアルでは、テキストや書式に関する一般的な操作をスクリプトで実行する方法について説明
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、InCopy でテキストを操作する方法や、組版に関する基本
的な用語を理解しているものとしています。
テキストの入力と読み込み
ここでは、InCopy ドキュメントにテキストを配置する方法について説明します。 InCopy のユーザーインター
フェイスを使用してテキストフレームにテキストを入力したり、テキストファイルを配置したりするのと同
じように、スクリプトを使用してテキストフレームを作成し、ストーリーにテキストを挿入し、テキスト
ファイルを配置することができます。
ストーリーとテキストフレーム
InCopy レイアウトの中にあるテキストは、すべてストーリーの中に含まれています。どのストーリーにも 1
つ以上のテキストフレームを含めることができます。 独立した InCopy ドキュメントには 1 つのストーリーが
含まれています。テキストフレームは、ストーリーのテキストを表示する必要がある場合にのみ追加されま
す。
.icml
ファイル)として InDesign から書き出されたストーリーにも当ては
まります。
InDesign ドキュメントから生成された InCopy ドキュメントには、複数のストーリーが含まれていることがあ
ります。また、InDesign レイアウトで作成されたテキストフレームが必ず含まれています。 InCopy では、
InDesign と異なり、スクリプトを使用して新しいテキストフレームを追加することはできません。
InCopy ドキュメントの中にあるテキストオブジェクトの関係について詳しくは、 38 ページの「テキストオブ
を参照してください。
ストーリーへのテキストの追加
ストーリーにテキストを追加するには、 contents
プロパティを使用します。
この方法を使用して、ストーリーの末尾にテキストを追加しています(完全なスクリプトについては、
30
第 4 章 テキストと組版 テキストの入力と読み込み 31
Set myDocument = myInCopy.Documents.Add
Rem Add text to the default story.
Set myStory = myDocument.Stories.Item(1)
myStory.Contents = "This is the first paragraph of example text."
Rem To add more text to the story, we'll use the last insertion point
Rem in the story. ("vbCr" is a return character in VBScript.)
Set myInsertionPoint = myStory.InsertionPoints.Item(-1)
myInsertionPoint.Contents = vbCr & "This is the second paragraph."
テキストの置換
次のスクリプトでは、適当なオブジェクトの内容を変更することで、1 つの単語をある語句に置換していま
す(完全なスクリプトについては、ReplaceWord を参照してください)。
Rem Enters text in the default story and then replaces
Rem a word in the story with a different phrase.
Set myDocument = myInCopy.Documents.Add
Rem Add text to the default story.
Set myStory = myDocument.Stories.Item(1)
myStory.Contents = "This is some example text."
Rem Replace the third word "some" with the phrase
Rem "a little bit of".
myStory.Words.Item(3).Contents = "a little bit of"
次のスクリプトでは、段落内のテキストを置換しています(完全なスクリプトについては、ReplaceText を参
照してください)。
Rem Enters text in the default story, and then replaces
Rem the text in the second paragraph.
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
myStory.Contents = "Paragraph 1." & vbCr & "Paragraph 2." & vbCr & "Paragraph 3." & vbCr
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 myStartCharacter = myStory.Paragraphs.Item(2).Characters.Item(1)
Set myEndCharacter = myStory.Paragraphs.Item(2).Characters.Item(-2)
Set myText = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
myText.Contents = "This text replaces the text in paragraph 2."
このスクリプトでは、
ItemByRange
メソッドを使用して、段落内のテキストへの参照(単一のテキストオブ
を削除してしまうと、段落に適用されている段落スタイルが変更される可能性があるからです。 ここでは、
ストーリーのテキストコレクションの
ItemByRange
メソッドを使用しています。パラメーターには 2 つの文
字(段落の先頭の文字と、末尾の文字(改行文字)の直前にある文字)を指定しています。 myTextFrame.ParentStory.Characters.ItemByRange
を使用する方法も考えられますが、その場合は
Character
ここでは、単一の
Text
オブジェクトを使用すること
で、1 つのアクションで置換を行っています。
特殊文字の挿入
多くの VBScript エディタでは Unicode がサポートされているので、InCopy に渡すテキスト文字列に Unicode
文字を簡単に入力できます。 また、Unicode 文字の字形の識別番号を指定する <nnnn> という InCopy ショート
カット(nnnn は、目的の文字の Unicode コード)を使用することもできます。 次のスクリプトでは、特殊文
字をいくつかの方法で入力しています(完全なスクリプトについては、SpecialCharacters を参照してくださ
い)。
第 4 章 テキストと組版 テキストの配置とテキスト読み込み環境設定の指定 32
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
Rem Entering special characters directly.
myStory.Contents = "Registered trademark: ®" & vbCr & "Copyright: ©" & vbCr & "Trademark: ™" & vbCr
Rem Entering special characters by their Unicode glyph ID value:
myStory.InsertionPoints.Item(-1).Contents = "Not equal to: <2260>" & vbCr
myStory.InsertionPoints.Item(-1).Contents = "Square root: <221A>" & vbCr
myStory.InsertionPoints.Item(-1).Contents = "Section symbol: <00B6>" & vbCr
Rem Entering InCopy special characters by their enumerations:
myStory.InsertionPoints.Item(-1).Contents = "Automatic page number marker:"
myStory.InsertionPoints.Item(-1).Contents = idSpecialCharacters.idAutoPageNumber
myStory.InsertionPoints.Item(-1).Contents = vbCr
myStory.InsertionPoints.Item(-1).Contents = "Section symbol:"
myStory.InsertionPoints.Item(-1).Contents = idSpecialCharacters.idSectionSymbol
myStory.InsertionPoints.Item(-1).Contents = vbCr
myStory.InsertionPoints.Item(-1).Contents = "En dash:"
myStory.InsertionPoints.Item(-1).Contents = idSpecialCharacters.idEnDash
myStory.InsertionPoints.Item(-1).Contents = vbCr
特定の文字の Unicode ID を調べたい場合は、InCopy の字形パレットを使用するのが最も簡単です(このパ
レットを表示するには、書式/字形を選択します)。パレット内で文字の上にカーソルを移動すると、その文
字の Unicode 値が表示されます。 Unicode について詳しくは、 http://www.unicode.org
を参照してください。
テキストの配置とテキスト読み込み環境設定の指定
テキスト文字列の入力だけでなく、ワードプロセッサーやテキストエディターで作成したテキストファイル
を配置することもできます。 新規ドキュメントのデフォルトストーリーにテキストファイルを配置する方法
を、次のスクリプトに示します(完全なスクリプトについては、PlaceTextFile を参照してください)。
Rem Places a text file in the default story of a new document.
Set myInCopy = CreateObject("InCopy.Application")
Rem Create an example document.
Set myDocument = myInCopy.Documents.Add
Rem Parameters for Page.place():
Rem File as File object,
Rem [ShowingOptions as Boolean = False]
Rem You'll have to fill in a valid file path on your system.
myDocument.Stories.Item(1).InsertionPoints.Item(1).Place "c:¥test.txt", False
配置するテキストファイルの種類に応じた読み込みオプションを指定するには、対応する読み込み環境設定
オブジェクトを使用します。 テキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全な
スクリプトについては、TextImportPreferences を参照してください)。 スクリプトのコメントに、各プロパ
ティに指定可能な値を示します。
Rem TextImportPreferences.vbs
Rem An InCopy CS6 VBScript
Rem
Set myInCopy = CreateObject("InCopy.Application")
Rem Sets the text import filter preferences.
With myInCopy.TextImportPreferences
Rem Options for characterSet:
Rem idTextImportCharacterSet.idAnsi
Rem idTextImportCharacterSet.idChineseBig5
Rem idTextImportCharacterSet.idGB18030
Rem idTextImportCharacterSet.idGB2312
Rem idTextImportCharacterSet.idKSC5601
Rem idTextImportCharacterSet.idMacintoshCE
Rem idTextImportCharacterSet.idMacintoshCyrillic
Rem idTextImportCharacterSet.idMacintoshGreek
Rem idTextImportCharacterSet.idMacintoshTurkish
Rem idTextImportCharacterSet.idRecommendShiftJIS83pv
Rem idTextImportCharacterSet.idShiftJIS90ms
第 4 章 テキストと組版 テキストの配置とテキスト読み込み環境設定の指定 33
Rem idTextImportCharacterSet.idshiftJIS90pv
Rem idTextImportCharacterSet.idUTF8
Rem idTextImportCharacterSet.idUTF16
Rem idTextImportCharacterSet.idWindowsBaltic
Rem idTextImportCharacterSet.idWindowsCE
Rem idTextImportCharacterSet.idWindowsCyrillic
Rem idTextImportCharacterSet.idWindowsEE
Rem icTextImportCharacterSet.idWindowsGreek
Rem idTextImportCharacterSet.idWindowsTurkish
.CharacterSet = idTextImportCharacterSet.idUTF16
.ConvertSpacesIntoTabs = True
.SpacesIntoTabsCount = 3
Rem The dictionary property can take any of the following
Rem language names (as strings):
Rem Bulgarian
Rem Catalan
Rem Croatian
Rem Czech
Rem Danish
Rem Dutch
Rem English: Canadian
Rem English: UK
Rem English: USA
Rem English: USA Legal
Rem English: USA Medical
Rem Estonian
Rem Finnish
Rem French
Rem French: Canadian
Rem German: Reformed
Rem German: Swiss
Rem German: Traditional
Rem Greek
Rem Hungarian
Rem Italian
Rem Latvian
Rem Lithuanian
Rem Neutral
Rem Norwegian: Bokmal
Rem Norwegian: Nynorsk
Rem Polish
Rem Portuguese
Rem Portuguese: Brazilian
Rem Romanian
Rem Russian
Rem Slovak
Rem Slovenian
Rem Spanish: Castilian
Rem Swedish
Rem Turkish
.Dictionary = "English: USA"
Rem platform options:
Rem idImportPlatform.idMacintosh
Rem idImportPlatform.idPC
.Platform = idImportPlatform.idPC
.StripReturnsBetweenLines = True
.StripReturnsBetweenParagraphs = True
.UseTypographersQuotes = True
End With
タグ付きテキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、TaggedTextImportPreferences を参照してください)。
第 4 章 テキストと組版 テキストの配置とテキスト読み込み環境設定の指定 34
Rem Sets the tagged text import filter preferences.
With myInCopy.TaggedTextImportPreferences
RemoveTextFormatting = False
Rem StyleConflict property can be:
Rem idStyleConflict.idPublicationDefinition
Rem idStyleConflict.idTagFileDefinition
.StyleConflict = idStyleConflict.idPublicationDefinition
.UseTypographersQuotes = True
End With
Word および RTF 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、WordRTFImportPreferences を参照してください)。
With myInCopy.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.idResolveClashUseExisting
Rem idResolveStyleClash.idResolveClashUseNew
.ResolveCharacterStyleClash =
idResolveStyleClash.idResolveClashUseExisting
.ResolveParagraphStyleClash =
idResolveStyleClash.idResolveClashUseExisting
.UseTypographersQuotes = True
End With
Excel 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについては、
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 35
With myInCopy.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
テキストの書き出しとテキスト書き出し環境設定の指定
書き出すには、テキストオブジェクトやストーリーオブジェクトを使用する必要があることに注意してくだ
さい。1 つの操作でドキュメント内のすべてのテキストを書き出すことはできません (完全なスクリプトに
ついては、ExportTextFile を参照してください)。
Set myDocument = InCopy.Documents.Add
Set myStory = myDocument.Stories.Item(0)
Rem Fill the story with placeholder text.
Set myTextFrame = myStory.TextContainers.Item(1)
myTextFrame.Contents = idTextFrameContents.idPlaceholderText
Rem Text export method parameters:
Rem Format as idExportFormat
Rem To As File
Rem [ShowingOptions As Boolean = False]
Rem Format parameter can be:
Rem idExportFormat.idInCopyCSDocument
Rem idExportFormat.idInCopyCSDocument
Rem idExportFormat.idPDFType
Rem idExportFormat.idRTF
Rem idExportFormat.idTaggedText
Rem idExportFormat.idTextType
Rem
Rem Export the story as text. You must fill in a valid file path on your system.
myStory.Export idExportFormat.idTextType, "C:¥test.txt"
指定したテキスト範囲を書き出す方法を、次の例に示します (ここでは、 myGetBounds
関数は省略していま
す。この関数については、ExportTextRange というチュートリアルスクリプトを参照してください)。
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 36
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
Rem Fill the story with placeholder text.
Set myTextFrame = myStory.TextContainers.Item(1)
myTextFrame.Contents = idTextFrameContents.idPlaceholderText
Set myStartCharacter = myStory.Paragraphs.Item(1).Characters.Item(1)
Set myEndCharacter = myStory.Paragraphs.Item(1).Characters.Item(-1)
Set myText = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
Rem Format as idExportFormat
Rem To As File
Rem [ShowingOptions As Boolean = False]
Rem
Rem Format parameter can be:
Rem idExportFormat.idInCopyCSDocument
Rem idExportFormat.idInCopyDocument
Rem idExportFormat.idPDFType
Rem idExportFormat.idRTF
Rem idExportFormat.idTaggedText
Rem idExportFormat.idTextType
Rem
Rem Export the text range. You must fill in a valid file path on your system.
myText.Export idExportFormat.idTextType, "C:¥test.txt"
書き出すテキストファイルの種類に応じた書き出しオプションを指定するには、対応する書き出し環境設定
オブジェクトを使用します。 テキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完
全なスクリプトについては、TextExportPreferences を参照してください)。
Rem Sets the text export filter preferences.
With myInCopy.TextExportPreferences
Rem Options for characterSet:
Rem idTextExportCharacterSet.idUTF8
Rem idTextExportCharacterSet.idUTF16
Rem idTextExportCharacterSet.idDefaultPlatform
.CharacterSet = idTextExportCharacterSet.idUTF16
Rem platform options:
Rem idImportPlatform.idMacintosh
Rem idImportPlatform.idPC
.Platform = idImportPlatform.idPC
End With
タグ付きテキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完全なスクリプトにつ
いては、TaggedTextExportPreferences を参照してください)。
Rem Sets the tagged text export filter preferences.
With myInCopy.TaggedTextExportPreferences
Rem Options for characterSet:
Rem idTagTextExportCharacterSet.idAnsi
Rem idTagTextExportCharacterSet.idASCII
Rem idTagTextExportCharacterSet.idGB18030
Rem idTagTextExportCharacterSet.idKSC5601
Rem idTagTextExportCharacterSet.idShiftJIS
Rem idTagTextExportCharacterSet.idUTF8
Rem idTagTextExportCharacterSet.idUTF16
.CharacterSet = idTagTextExportCharacterSet.idUTF16
Rem tagForm options:
Rem idTagTextForm.idAbbreviated
Rem idTagTextForm.idVerbose
.TagForm = idTagTextForm.idVerbose
End With
既存の書き出しフィルターを使用しないでテキストを書き出すこともできます。 VBScript には、テキストファ
イルをディスクに書き出す機能が用意されています。この機能を利用すれば、スクリプトでドキュメント内
のテキストをスキャンして、任意のテキストマークアップスキームを使用して任意の順序でテキストを書き
出すことができます。 HTML 形式で InCopy テキストを書き出す簡単な例を次に示します(完全なスクリプト
については、ExportHTML を参照してください)。
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 37
Function myExportHTML(myInCopy, myDocument)
Rem Use the myStyleToTagMapping dictionary to set up
Rem 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 myInCopy.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 of
Rem the paragraph with the appropriate tag.
myTag = myStyleToTagMapping.Item
(myParagraph.AppliedParagraphStyle.Name)
Rem If the tag comes back empty, map it to the basic
Rem paragraph tag.
If myTag = "" Then
myTag = "p"
End If
myStartTag = "<" & myTag & ">"
myEndTag = "</" & myTag & ">"
Rem If the paragraph is not the last paragraph
Rem in the story, 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 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
第 4 章 テキストと組版 テキストオブジェクト 38
(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 only one
table per paragraph, 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
Next
End If
End If
Rem Close the text file.
myTextFile.Close
End Function
テキストオブジェクト
次の図は、InCopy のテキストオブジェクトモデルを図式化したものです。 テキストオブジェクトにはレイア
ウトオブジェクト(テキストフレーム)とテキストストリームオブジェクト(ストーリー、挿入点、文字、
単語など)の 2 つの種類があります。 この図では、各オブジェクトの一般的な呼び名を記載しています。ス
クリプトを作成する際は、使用するスクリプト言語で定義されている対応する用語を使用してください。
第 4 章 テキストと組版 テキストオブジェクト 39 document story spread, page, layer
選択
insertion points characters words lines paragraphs text columns text style ranges texts notes text containers text frame insertion points characters words lines paragraphs text columns text style ranges texts notes
テキストストリームオブジェクトの parent
は、そのオブジェクトが含まれているストーリーです。
オブジェクトが含まれているテキストフレーム(またはテキストフレームのコレクション)への参照を取得
するには、
ParentTextFrames
プロパティを使用します。
テキストフレームの parent
は、通常、そのテキストフレームが含まれているページまたはスプレッドです。
グループ内にあるテキストフレームや、別のページアイテム内にペーストされたテキストフレームの parent
は、そのテキストフレームが含まれているページアイテムです。 アンカー付きフレームに変換されたテキス
トフレームの parent
は、そのアンカー付きフレームが含まれている文字です。
のの種類を判別する方法を、次のスクリプトに示します。 他の多くのサンプルスクリプトと異なり、このス
クリプトは実際には何も行いません。このスクリプトでは、選択をフィルタリングする方法のみが示されて
います (完全なスクリプトについては、TextSelection を参照してください)。
第 4 章 テキストと組版 テキストオブジェクト 40
Set myInCopy = CreateObject("InCopy.Application")
If myInCopy.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 myInCopy.Selection.Count = 1 Then
Select Case TypeName(myInCopy.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 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 を参照してください)。
Rem Create an example document.
Set myDocument = myInCopy.Documents.Add
Rem Create a series of paragraphs in the default story.
Set myStory = myDocument.Stories.Item(1)
myStory.Contents = "WordA" & vbcr & "WordB" & vbcr & "WordC" & vbcr & "WordD" & vbcr
Rem Move WordC before WordA.
myStory.Paragraphs.Item(3).Move idLocationOptions.idBefore, myStory.Paragraphs.Item(1)
Rem Move WordB after WordD (into the same paragraph).
myStory.Paragraphs.Item(3).Move idLocationOptions.idAfter, myStory.Paragraphs.Item(-1).Words.Item(1)
Rem Note that moving text removes it from its original location.
フォーマットされたテキストをドキュメント間で転送する場合にも、 move
して貼り付けるよりも、 move
メソッドや duplicate
メソッドを使用するほうが優れています。コピーして貼
り付けるためには、ドキュメントを表示して、コピーするテキストを選択しなければなりません。 move
や duplicate
を使用するほうが速くて確実です。 move
や duplicate
を使用して、ドキュメント間でテキストを
移動する方法を、次のスクリプトに示します(完全なスクリプトについては、MoveTextBetweenDocuments
を参照してください)。
Rem Moves formatted text from one document to another.
Rem Create an example document.
Set mySourceDocument = myInCopy.Documents.Add
Rem Add text to the default story.
Set mySourceStory = mySourceDocument.stories.item(1)
mySourceStory.Contents = "This is the source text." & vbCr & "This text is not the source text." & vbcr
mySourceStory.paragraphs.item(1).pointSize = 24
Rem Create a new document to move the text to.
Set myTargetDocument = myInCopy.Documents.Add
Rem Create a text frame in the target document.
Set myTargetStory = myTargetDocument.stories.item(1)
myTargetStory.contents = "This is the target text. Insert the source text after this paragraph." & vbcr
mySourceStory.paragraphs.item(1).duplicate idLocationOptions.idAfter, myTargetStory.insertionPoints.item(-1)
第 4 章 テキストと組版 テキストオブジェクト 41
フォーマットされていないテキストをテキストオブジェクト間でコピーする方法としては、コピーするテキ
ストオブジェクトの contents
プロパティを取得して、その文字列を別のテキストオブジェクトの contents
プロパティに設定する方法があります。 次のスクリプトにその例を示します(完全なスクリプトについては、
Rem Shows how to remove formatting from text as you
Rem move it to other locations in a document.
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
set myStory = myDocument.stories.item(1)
myStory.contents = "This is a formatted string." & vbcr & "Text pasted after this text will retain its formatting." & vbcr & vbcr & "Text moved to the following line will take on the formatting of the insertion point." & vbcr & "Italic: "
Rem Apply formatting to the first paragraph.
myStory.Paragraphs.Item(1).FontStyle = "Bold"
Rem Apply formatting to the last paragraph.
myStory.Paragraphs.Item(-1).FontStyle = "Italic"
Rem Copy from one frame to another using a simple copy.
myInCopy.Select myStory.Paragraphs.Item(1).Words.Item(1)
myInCopy.Copy
myInCopy.Select myStory.Paragraphs.Item(2).InsertionPoints.Item(-1)
myInCopy.Paste
Rem Copy the unformatted string from the first word to the end of the story
Rem by getting and setting the contents of text objects. Note that this doesn't
Rem really copy the text; it replicates the text string from one text location
Rem to another.
myStory.InsertionPoints.Item(-1).Contents = myStory.Paragraphs.Item(1).Words.Item(1).contents
テキストオブジェクトと反復処理
一連のテキストオブジェクトに対して繰り返して処理を行っている間に、テキストの移動、削除、追加を行
うと、テキスト参照に問題が発生することがあります。 このような問題が発生する例を、次のスクリプトに
示します(完全なスクリプトについては、TextIterationWrong を参照してください)。
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
myString = "Paragraph 1." & vbCr & "Delete this paragraph." & vbCr & "Paragraph 2." & vbCr &
"Paragraph 3." & vbCr & "Paragraph 4." & vbCr & "Paragraph 5." & vbCr & "Delete this paragraph." & vbCr & "Paragraph 6." & vbCr
myStory.Contents = myString
Rem The following for loop cause an error.
For 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
この例では、フォーマットされない段落がいくつか発生することになります。 その理由は次のとおりです。 こ
のスクリプトのループは、ストーリー内の最初の段落から最後の段落まで、段落に対して繰り返し処理を行
が削除されると、第 3 段落がその場所に移動します。 次にループカウンターが 3 になると、先ほどまで第 4 段
落であった段落が処理されます。第 3 段落であった段落はこの時点で第 2 段落になっているので、処理は行
われません。
この問題を回避するには、次のスクリプトのように、テキストオブジェクトを逆順で処理します(チュート
リアルスクリプトの TextIterationRight より)。
第 4 章 テキストと組版 テキストのフォーマット 42
Rem Shows how to iterate through text.
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
myString = "Paragraph 1." & vbCr & "Delete this paragraph." & vbCr & "Paragraph 2." & vbCr &
"Paragraph 3." & vbCr & "Paragraph 4." & vbCr & "Paragraph 5." & vbCr & "Delete this paragraph." & vbCr & "Paragraph 6." & vbCr
myStory.Contents = myString
Rem The following for loop will format all of the paragraphs by iterating
Rem backwards through the paragraphs in the story.
For myParagraphCounter = myStory.Paragraphs.Count To 1 Step -1
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
テキストのフォーマット
前の節では、ドキュメントにテキストを追加し、ストーリーやテキストオブジェクトを操作しました。 この
節では、テキストにフォーマットを適用します。 InCopy のすべてのフォーマット機能は、スクリプティング
で操作することができます。
テキストデフォルトの設定
テキストデフォルトは、アプリケーションとドキュメントの両方で設定できます。 アプリケーションのテキ
ストデフォルトは、新しく作成されるすべてのドキュメントのテキストデフォルトとして使用されます。 ド
キュメントのテキストデフォルトは、そのドキュメントで新しく作成されるすべてのテキストオブジェクト
のフォーマットとして使用されます (完全なスクリプトについては、TextDefaults を参照してください)。
Rem Sets the text defaults of a new document, which set the default formatting
Rem for all new text frames. Existing text frames are unaffected.
Set myInCopy = CreateObject("InCopy.Application")
myInCopy.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idPoints
myInCopy.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idPoints
Rem To set the application text formatting defaults, replace "myInCopy"
Rem with a reference to a document in the following lines.
With myInCopy.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 = myInCopy.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.
第 4 章 テキストと組版 テキストのフォーマット 43
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
Rem Assumes that application has a default character style named "myDropCap"
.DropCapStyle = myInCopy.CharacterStyles.Item("myDropCap")
End If
.FillColor = myInCopy.Colors.Item("Black")
.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
第 4 章 テキストと組版
.RightIndent = 0
.RuleAbove = False
If .RuleAbove = True Then
.RuleAboveColor = myInCopy.Colors.Item("Black")
.RuleAboveGapColor = myInCopy.Swatches.Item("None")
.RuleAboveGapOverprint = False
.RuleAboveGapTint = 100
.RuleAboveLeftIndent = 0
.RuleAboveLineWeight = 0.25
.RuleAboveOffset = 14
.RuleAboveOverprint = False
.RuleAboveRightIndent = 0
.RuleAboveTint = 100
.RuleAboveType = myInCopy.StrokeStyles.Item("Solid")
.RuleAboveWidth = idRuleWidth.idColumnWidth
End If
.RuleBelow = False
If .RuleBelow = True Then
.RuleBelowColor = myInCopy.Colors.Item("Black")
.RuleBelowGapColor = myInCopy.Swatches.Item("None")
.RuleBelowGapOverPrint = False
.RuleBelowGapTint = 100
.RuleBelowLeftIndent = 0
.RuleBelowLineWeight = 0.25
.RuleBelowOffset = 0
.RuleBelowOverPrint = False
.RuleBelowRightIndent = 0
.RuleBelowTint = 100
.RuleBelowType = myInCopy.StrokeStyles.Item("Solid")
.RuleBelowWidth = idRuleWidth.idColumnWidth
End If
.SingleWordJustification = idSingleWordJustification.idLeftAlign
.Skew = 0
.SpaceAfter = 0
.SpaceBefore = 0
.StartParagraph = idStartParagraph.idAnywhere
.StrikeThru = False
If .StrikeThru = True Then
.StrikeThroughColor = myInCopy.Colors.Item("Black")
.StrikeThroughGapColor = myInCopy.Swatches.Item("None")
.StrikeThroughGapOverprint = False
.StrikeThroughGapTint = 100
.StrikeThroughOffset = 3
.StrikeThroughOverprint = False
.StrikeThroughTint = 100
.StrikeThroughType = myInCopy.StrokeStyles.Item("Solid")
.StrikeThroughWeight = 0.25
End If
.StrokeColor = myInCopy.Swatches.Item("None")
.StrokeTint = 100
.StrokeWeight = 0
テキストのフォーマット 44
第 4 章 テキストと組版 テキストのフォーマット 45
.Tracking = 0
.Underline = False
If .Underline = True Then
.UnderlineColor = myInCopy.Colors.Item("Black")
.UnderlineGapColor = myInCopy.Swatches.Item("None")
.UnderlineGapOverprint = False
.UnderlineGapTint = 100
.UnderlineOffset = 3
.UnderlineOverprint = False
.UnderlineTint = 100
.UnderlineType = myInCopy.StrokeStyles.Item("Solid")
.UnderlineWeight = 0.25
End If
.VerticalScale = 100
End With
フォント
InCopy アプリケーションオブジェクトのフォントコレクションには、InCopy で利用できるすべてのフォント
が含まれています。 これとは対照的に、ドキュメントのフォントコレクションには、そのドキュメントで使
用されているフォントのみが含まれています。 ドキュメントのフォントコレクションには、環境に無いフォ
ント(ドキュメントで使用されているが InCopy では利用できないフォント)も含まれます。 アプリケーショ
ンフォントとドキュメントフォントの違いを調べる方法を、次のスクリプトに示します(完全なスクリプト
については、FontCollections を参照してください)。
Rem Shows the difference between the fonts collection of the application
Rem and the fonts collection of a document.
Set myInCopy = CreateObject("InCopy.Application")
Set myApplicationFonts = myInCopy.Fonts
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
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 myInCopy.Fonts.Count
myString = myString & myInCopy.Fonts.Item(myCounter) & vbCr
Next
myStory.Contents = myString
注意 : フォント名は通常、
familyName<tab>fontStyle
という形式で示されます。
familyName
はフォントファ
ミリー名、
<tab>
はタブ文字、
fontStyle
はフォントスタイル名です。
"Adobe Caslon Pro<tab>Semibold Italic"
フォントの適用
テキストのある範囲にローカルフォントを適用するには、 appliedFont
プロパティを使用します。次のスク
リプトにその例を示します(チュートリアルスクリプトの ApplyFont より)。
Rem Given a reference to InCopy "myInCopy," a font name "myFontName"
Rem and a text object "myText"...
myText.appliedFont = myInCopy.Fonts.Item(myFontName)
また、次のスクリプトのように、フォントファミリー名とフォントスタイルを指定してフォントを適用する
こともできます。 myText.AppliedFont = myInCopy.Fonts.Item("Adobe Caslon Pro")
myText.FontStyle = "Semibold Italic"
第 4 章 テキストと組版 テキストのフォーマット 46
テキストプロパティの変更
InCopy のテキストオブジェクトには、そのフォーマット属性に対応する多数のプロパティが用意されていま
いる段落とほぼ同じプロパティ)が用意されています。 SetTextProperties というチュートリアルスクリプトに
は、テキストオブジェクトのすべてのプロパティを設定する方法が示されています。 次のスクリプトにその
例を示します。
Rem Shows how to set all read/write properties of a text object.
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add()
Set myStory = myDocument.Stories.Item(1)
myStory.Contents = "x"
Set myTextObject = myStory.Characters.Item(1)
With myTextObject
.AlignToBaseline = False
.AppliedCharacterStyle = myDocument.CharacterStyles.Item("[None]")
myFontName = "Minion Pro" & vbTab & "Regular"
.AppliedFont = myInCopy.Fonts.Item(myFontName)
.AppliedLanguage = myInCopy.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
Rem More text properties in the tutorial script.
テキストカラーの変更
テキスト文字の塗りと線にカラーを適用できます。次のスクリプトにその例を示します(チュートリアルス
クリプトの TextColors より)。
Rem Given two colors "myColorA" and "myColorB"...
set myStory = myDocument.Stories.Item(1)
myStory.contents = "Text" & vbCr & "Color"
Set myText = myStory.Paragraphs.Item(1)
myText.PointSize = 72
myText.Justification = idJustification.idCenterAlign
Set myText = myStory.Paragraphs.Item(2)
myText.StrokeWeight = 3
myText.PointSize = 144
myText.Justification = idJustification.idCenterAlign
第 4 章 テキストと組版 テキストのフォーマット 47
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
スタイルの作成と適用
前述のいくつかの例でローカルフォーマットを適用する方法を示しましたが、ここでは、文字スタイルや段
落スタイルを使用してテキストをフォーマットする方法について説明します。 スタイルを使用すると、
フォーマットされたテキストとスタイルの間にリンクが作成されます。そのため、スタイルの再定義、特定
のスタイルでフォーマットされたテキストの収集、テキストの検索や変更などが簡単に行えます。 段落スタ
イルや文字スタイルは、テキストのフォーマット作業を効率化する上で重要な役割を果たします。段落と文
字スタイルはテキストにフォーマットを設定する場合に生産性の鍵となるものであり、テキストにフォー
マットを適用するどんなスクリプトにとっても中心的な存在になるはずです。
段落スタイルや文字スタイルを作成して適用する方法を、次のスクリプトに示します(完全なスクリプトに
ついては、CreateStyles を参照してください)。
Rem Shows how to create and apply a paragraph style and a character style.
Set myInCopy = CreateObject("InCopy.Application")
Rem Create an example document.
Set myDocument = myInCopy.Documents.Add
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 text frame on page 1.
Set myStory = myDocument.Stories.Item(1)
Rem Fill the text frame with placeholder text.
myStory.Contents = "Normal text. Text with a character style applied to it. More normal text."
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
Rem paragraph-style object, which you can now use to specify formatting.
myStory.Texts.Item(1).ApplyParagraphStyle myParagraphStyle, True
Set myStartCharacter = myStory.Characters.Item(14)
Set myEndCharacter = myStory.Characters.Item(55)
Set myText = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter)
myText.Item(1).ApplyCharacterStyle myCharacterStyle
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
End If
Err.Clear
On Error GoTo 0
myColor.Model = myColorModel
myColor.ColorValue = myColorValue
Set myAddColor = myColor
End Function
Function myAddStyle(myDocument, myStyleName, myStyleType)
第 4 章 テキストと組版 テキストのフォーマット 48
On Error Resume Next
Select Case myStyleType
Case 1:
Set myStyle = myDocument.CharacterStyles.Item(myStyleName)
If Err.Number <> 0 Then
Set myStyle = myDocument.CharacterStyles.Add
myStyle.Name = myStyleName
End If
Err.Clear
On Error GoTo 0
Case 2:
Set myStyle = myDocument.ParagraphStyles.Item(myStyleName)
If Err.Number <> 0 Then
Set myStyle = myDocument.ParagraphStyles.Add
myStyle.Name = myStyleName
End If
Err.Clear
On Error GoTo 0
Case 3:
Set myStyle = myDocument.ObjectStyles.Item(myStyleName)
If Err.Number <> 0 Then
Set myStyle = myDocument.ObjectStyles.Add
myStyle.Name = myStyleName
End If
Err.Clear
On Error GoTo 0
End Select
Set myAddStyle = myStyle
End Function
テキストオブジェクトの
AppliedParagraphStyle
プロパティを使用せずに
ApplyParagraphStyle
メソッドを
使用する利点は、 既存のフォーマットをオーバーライドできる点にあります。スタイルにプロパティを設定
しても、ローカルフォーマットは変更されずに保持されます。
新規ドキュメントの作成時に、スタイルが存在するかどうかを確認しているのは、 アプリケーションのデ
フォルトスタイルとして同じ名前のスタイルが存在している可能性があるからです。 その場合、同じ名前で
新しいスタイルを作成しようとするとエラーが発生します。
先頭文字スタイル(Nested Style)を使用すると、文字スタイルのフォーマットを特定のパターンに従って段
落に適用することができます。 先頭文字スタイルを含む段落スタイルの作成方法を、次のスクリプトに示し
ます(完全なスクリプトについては、NestedStyles を参照してください)。
Rem At this point, the variable myParagraphStyle contains a reference to a
Rem paragraoh-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
Set myStartCharacter = myStory.Characters.Item(1)
Set myEndCharacter = myStory.Characters.Item(-1)
Rem Use the ItemByRange method to apply the paragraph to all text in the
Rem story. Note the story object does not have the applyStyle method.)
Set myText = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
myText.ApplyParagraphStyle myParagraphStyle, True
スタイルの削除
ユーザーインターフェイスでスタイルを削除する際には、タグ付けされたスタイルでテキストのフォーマッ
ト方法を選択することができますが、 InCopy スクリプティングでもこれと同じことが行えます。次のスクリ
プトにその例を示します(チュートリアルスクリプトの RemoveStyle より)。
第 4 章 テキストと組版 テキストの検索と変更 49
Rem Delete the paragraph style myParagraphStyleA and replace with myParagraphStyleB.
myParagraphStyleA.Delete myDocument.ParagraphStyles.Item("myParagraphStyleB")
段落スタイルと文字スタイルの読み込み
他の InCopy ドキュメントから文字スタイルや段落スタイルを読み込むことができます。 次のスクリプトにそ
の例を示します(完全なスクリプトについては、ImportTextStyles を参照してください)。
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
Rem idImportFormat.idCharacterStylesFormat
idImportFormat.idTextStylesFormat
Rem From as string (file path)
Rem GlobalStrategy as idGlobalClashResolutionStrategy enumeration. Options are:
Rem
Rem
Rem idGlobalClashResolutionStrategy.idDoNotLoadTheStyle
idGlobalClashResolutionStrategy.idLoadAllWithOverwrite
idGlobalClashResolutionStrategy.idLoadAllWithRename
myNewDocument.ImportStyles idImportFormat.idTextStylesFormat, "c:¥styles.icml", idGlobalClashResolutionStrategy.idLoadAllWithOverwrite
テキストの検索と変更
検索/変更機能は、テキストを操作するための最も強力なツールの 1 つであり、 スクリプティングに完全に
対応しています。スクリプトを使用すれば、ユーザーインターフェイスでは利用できない様々なオプション
が指定できます。 InCopy では、次の 3 つの方法でテキストを検索できます。
テキストやテキストフォーマットを検索して、別のテキストやテキストフォーマットに変更できます。
この場合は、
FindTextPreferences
オブジェクトや
ChangeTextPreferences
オブジェクトを使用して、 findText
メソッドや changeText
メソッドのパラメーターを指定します。
正規表現を使用したテキスト検索(grep)を実行できます。 この場合は、
FindGrepPreferences
オブジェ
クトや
ChangeGrepPreferences
オブジェクトを使用して、 findGrep
メソッドや changeGrep
メソッドのパ
ラメーターを指定します。
指定された字形(とそのフォーマット)を検索して、別の字形やフォーマットに置換できます。 この場
合は、
FindGlyphPreferences
オブジェクトや
ChangeGlyphPreferences
オブジェクトを使用して、 findGlyph
メソッドや changeGlyph
メソッドのパラメーターを指定します。
どの検索/変更メソッドにも、
ReverseOrder
という 1 つのオプションパラメーターがあります。このパラ
メーターで、検索結果を返す順序を指定できます。 検索/変更操作の結果に基づいて、ストーリーのテキス
で説明したテキス
ト参照の問題に注意する必要があります。 この問題が発生する場合は、返されたテキストオブジェクトのコ
レクションを逆順で処理するようにループを設定するか、または、検索結果を逆順で返すように設定して、
そのコレクションを通常の順序で処理します。
検索/変更の環境設定
テキストを検索する前に、検索/変更の環境設定を消去することで、前回の設定を引き継がないようにする
ことができます。 また、必要に応じていくつかの検索/変更環境設定を指定して、対象となるテキスト、
フォーマット、正規表現、字形などを指定することができます。 検索/変更操作を行う一般的な手順を次に
示します。
1.
検索/変更の環境設定を消去します。 検索/変更操作の種類に応じて、次の 3 つのいずれかを行います。
第 4 章 テキストと組版 テキストの検索と変更 50
Rem Find/Change text preferences (where "myInCopy" is a
Rem reference to the InCopy application
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Find/Change grep preferences
myInCopy.FindGrepPreferences = idNothingEnum.idNothing
myInCopy.ChangeGrepPreferences = idNothingEnum.idNothing
Rem Find/Change glyph preferences
myInCopy.FindGlyphPreferences = idNothingEnum.idNothing
myInCopy.ChangeGlyphPreferences = idNothingEnum.idNothing
2.
検索/変更のパラメーターを設定します。
3.
検索/変更操作を実行します。
4.
検索/変更の環境設定を再び消去します。
テキストの検索と変更
指定したテキスト文字列を検索する方法を、次のスクリプトに示します。 このスクリプトではドキュメント
全体を検索していますが、ストーリー、テキストフレーム、段落、テキスト列などのテキストオブジェクト
を検索することもできます。 findText
メソッドとそのパラメーターは、すべてのテキストオブジェクトで共
通しています (完全なスクリプトについては、FindText を参照してください)。
Rem Clear the find/change preferences.
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Search the document for the string "Text".
myInCopy.FindTextPreferences.FindWhat = "text"
Rem Set the find options.
myInCopy.FindChangeTextOptions.CaseSensitive = False
myInCopy.FindChangeTextOptions.IncludeFootnotes = False
myInCopy.FindChangeTextOptions.IncludeHiddenLayers = False
myInCopy.FindChangeTextOptions.IncludeLockedLayersForFind = False
myInCopy.FindChangeTextOptions.IncludeLockedStoriesForFind = False
myInCopy.FindChangeTextOptions.IncludeMasterPages = False
myInCopy.FindChangeTextOptions.WholeWord = False
Set myFoundItems = myInCopy.Documents.Item(1).FindText()
MsgBox ("Found " & CStr(myFoundItems.Count) & " instances of the search string.")
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
指定したテキスト文字列を検索して別の文字列に置換する方法を、次のスクリプトに示します(完全なスク
リプトについては、ChangeText を参照してください)。
Rem Clear the find/change preferences.
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Search the document for the string "Text".
myInCopy.FindTextPreferences.FindWhat = "text"
Rem Set the find options.
myInCopy.FindChangeTextOptions.CaseSensitive = False
myInCopy.FindChangeTextOptions.IncludeFootnotes = False
myInCopy.FindChangeTextOptions.IncludeHiddenLayers = False
myInCopy.FindChangeTextOptions.IncludeLockedLayersForFind = False
myInCopy.FindChangeTextOptions.IncludeLockedStoriesForFind = False
myInCopy.FindChangeTextOptions.IncludeMasterPages = False
myInCopy.FindChangeTextOptions.WholeWord = False
Set myFoundItems = myInCopy.Documents.Item(1).FindText
MsgBox ("Found " & CStr(myFoundItems.Count) & " instances of the search string.")
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
第 4 章 テキストと組版 テキストの検索と変更 51
フォーマットの検索と変更
テキストフォーマットの検索や変更を行うには、 findTextPreferences
オブジェクトや changeTextPreferences
オブジェクトのその他のプロパティを設定します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの FindChangeFormatting より)。
Rem Clear the find/change preferences.
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Set the find options.
myInCopy.FindChangeTextOptions.CaseSensitive = False
myInCopy.FindChangeTextOptions.IncludeFootnotes = False
myInCopy.FindChangeTextOptions.IncludeHiddenLayers = False
myInCopy.FindChangeTextOptions.IncludeLockedLayersForFind = False
myInCopy.FindChangeTextOptions.IncludeLockedStoriesForFind = False
myInCopy.FindChangeTextOptions.IncludeMasterPages = False
myInCopy.FindChangeTextOptions.WholeWord = False
Rem Search the document for the 24 point text and change it to 10 point text.
myInCopy.FindTextPreferences.PointSize = 24
myInCopy.ChangeTextPreferences.PointSize = 10
Set myFoundItems = myInCopy.Documents.Item(1).ChangeText
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
テキスト文字列を検索してフォーマットを適用することもできます。次のスクリプトにその例を示します
(チュートリアルスクリプトの FindChangeStringFormatting より)。
Rem Clear the find/change preferences before the search.
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Set the general find/change options.
myInCopy.findChangeTextOptions.caseSensitive = false
myInCopy.findChangeTextOptions.includeFootnotes = false
myInCopy.findChangeTextOptions.includeHiddenLayers = false
myInCopy.findChangeTextOptions.includeLockedLayersForFind = false
myInCopy.findChangeTextOptions.includeLockedStoriesForFind = false
myInCopy.findChangeTextOptions.includeMasterPages = false
myInCopy.findChangeTextOptions.wholeWord = false
Rem The following line will only work if your default
Rem font has a font style named "Bold" if not, change
Rem the text to a font style used by your default font.
myInCopy.ChangeTextPreferences.FontStyle = "Bold"
Rem In this example, we'll use the InCopy search
Rem metacharacter "^9" to find any digit.
myInCopy.FindTextPreferences.FindWhat = "WIDGET^9^9^9^9"
set myFoundItems = myDocument.ChangeText
MsgBox ("Changed " & CStr(myFoundItems.Count) & " instances of the search string.")
Rem Clear the find/change preferences after the search.
myInCopy.FindTextPreferences = idNothingEnum.idNothing
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
grep の使用
InCopy の findGrep
メソッドや changeGrep
メソッドを使用すれば、正規表現を利用した検索/変更操作が行
トのフォーマットを changeGrepPreferences
オブジェクトのプロパティで指定したフォーマットに置換する
ことができます。 これらのメソッドや関係する環境設定オブジェクトの使用方法を、次のスクリプトに示し
ます(完全なスクリプトについては、FindGrep を参照してください)。
第 4 章 テキストと組版 テキストの検索と変更 52
Rem Clear the find/change preferences.
myInCopy.FindGrepPreferences = idNothingEnum.idNothing
myInCopy.ChangeGrepPreferences = idNothingEnum.idNothing
Rem Set the find options.
myInCopy.FindChangeGrepOptions.IncludeFootnotes = False
myInCopy.FindChangeGrepOptions.IncludeHiddenLayers = False
myInCopy.FindChangeGrepOptions.IncludeLockedLayersForFind = False
myInCopy.FindChangeGrepOptions.IncludeLockedStoriesForFind = False
myInCopy.FindChangeGrepOptions.IncludeMasterPages = False
Rem Regular expression for finding an email address.
myInCopy.FindGrepPreferences.FindWhat = "(?i)[A-Z]*?@[A-Z]*?[.]..."
Rem Apply the change to 24-point text only.
myInCopy.FindGrepPreferences.PointSize = 24
myInCopy.ChangeGrepPreferences.Underline = True
myInCopy.Documents.Item(1).ChangeGrep
Rem Clear the find/change preferences after the search.
myInCopy.FindGrepPreferences = idNothingEnum.idNothing
myInCopy.ChangeGrepPreferences = idNothingEnum.idNothing
注意 :
FindChangeTextOptions
オブジェクトで使用できる
WholeWord
と
CaseSensitive
の 2 つのプロパティ
は、 findChangeGrepOptions
ンを表現できるからです。 大文字と小文字を区別しない場合は
(?i)
を使用し、区別する場合は
(?-i)
を使用
します。
¥>
を使用し、単語の末尾に一致するには
¥<
を使用し、単語の境界に一致
するには
¥b
を使用します。 grep 検索/変更の利用例として、マークアップテキスト(タグでフォーマットが指定されているプレーンテ
キスト)を InCopy 形式のテキストに変換する処理があります。 簡単なテキストマークアップスキームとして
は、PageMaker の段落タグがあります(これは、PageMaker のタグ付きテキスト形式のファイルとは異なり
ます)。 このスキームでマークアップされたテキストファイルでは、次の例のように、段落スタイルの名前が
段落の先頭に示されます。
<heading1>This is a heading.
<body_text>This is body text.
grep 検索とテキスト検索/変更を組み合わせれば、テキストにフォーマットを適用して、マークアップタグ
を削除することができます。次のスクリプトにその例を示します(チュートリアルスクリプトの ReadPMTags
より)。
Function myReadPMTags(myInCopy, myStory)
Set myDocument = myStory.Parent
Rem Reset the findGrepPreferences to ensure that previous settings
Rem do not affect the search.
myInCopy.FindGrepPreferences = idNothingEnum.idNothing
myInCopy.ChangeGrepPreferences = idNothingEnum.idNothing
myInCopy.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.
For Each myFoundTag In myFoundTags
myString = myFoundTag
Rem Find the tag using findWhat.
myInCopy.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.
第 4 章 テキストと組版 テキストの検索と変更 53 myInCopy.ChangeTextPreferences.AppliedParagraphStyle = myStyle
myStory.ChangeText
Rem Reset the changeTextPreferences.
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Set the changeTo to an empty string.
myInCopy.ChangeTextPreferences.ChangeTo = ""
Rem Search to remove the tags.
myStory.ChangeText
Next
End If
Rem Reset the find/change preferences again.
myInCopy.ChangeTextPreferences = idNothingEnum.idNothing
Rem Reset the findGrepPreferences.
myInCopy.FindGrepPreferences = idNothingEnum.idNothing
End Function
Function myAddStyle(myDocument, myStyleName)
On Error Resume Next
Set myStyle = myDocument.ParagraphStyles.Item(myStyleName)
If Err.Number <> 0 Then
Set myStyle = myDocument.ParagraphStyles.Add
myStyle.Name = myStyleName
End If
Err.Clear
On Error GoTo 0
Set myAddStyle = myStyle
End Function
字形検索の使用
特定のフォントに含まれている個々の文字を検索/変更するには、
FindGlyph
メソッドや
ChangeGlyph
メ
ソッドを使用します。パラメーターは
FindGlyphPreferences
オブジェクトや
ChangeGlyphPreferences
オブ
ジェクトで設定します。 次のスクリプトでは、サンプルドキュメントの中で字形を検索し、変更しています
(完全なスクリプトについては、FindChangeGlyphs を参照してください)。
Rem Clear the find/change preferences.
myInCopy.FindGlyphPreferences = idNothingEnum.idNothing
myInCopy.ChangeGlyphPreferences = idNothingEnum.idNothing
Rem Set the find options.
myInCopy.FindChangeGrepOptions.IncludeFootnotes = False
myInCopy.FindChangeGrepOptions.IncludeHiddenLayers = False
myInCopy.FindChangeGrepOptions.IncludeLockedLayersForFind = False
myInCopy.FindChangeGrepOptions.IncludeLockedStoriesForFind = False
myInCopy.FindChangeGrepOptions.IncludeMasterPages = False
Rem You must provide a font that is used in the document for the
Rem AppliedFont property of the FindGlyphPreferences object.
myInCopy.FindGlyphPreferences.AppliedFont = myDocument.Fonts.Item("Minion ProRegular");
Rem Provide the glyph ID, not the glyph Unicode value.
myInCopy.FindGlyphPreferences.GlyphID = 500;
Rem The appliedFont of the changeGlyphPreferences object can be
Rem any font available to the application.
myInCopy.changeGlyphPreferences.AppliedFont = myInCopy.Fonts.Item("Times New RomanRegular");
myInCopy.Documents.Item(1).ChangeGlyph
Rem Clear the find/change preferences after the search.
myInCopy.FindGlyphPreferences = idNothingEnum.idNothing
myInCopy.ChangeGlyphPreferences = idNothingEnum.idNothing
第 4 章 テキストと組版
表
表 54
ConvertTextToTable
メソッドを使用して、既存のテキストから表を作成したり、ストーリー内の任意の挿入
点に空の表を作成することができます。 次のスクリプトでは、3 つの異なる方法で表を作成しています(完全
なスクリプトについては、MakeTable を参照してください)。
Set myStory = myDocument.Stories.Item(1)
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 myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
myString = "Table" & vbCr
myStory.Contents = myString
Set myTable = myStory.InsertionPoints.Item(-1).Tables.Add
myTable.ColumnCount = 4
myTable.BodyRowCount = 4
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 を参照して
第 4 章 テキストと組版 表 55 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
表にヘッダー行とフッター行を作成する方法を、次のスクリプトに示します(完全なスクリプトについては、
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
表にフォーマットを適用する方法を、次のスクリプトに示します(完全なスクリプトについては、
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
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 you also set the
Rem 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
表に反復行フォーマットを追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
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 Applly 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
第 4 章 テキストと組版 自動修正 56
テキストや表セルが選択されている場合の選択の処理方法を、次のスクリプトに示します。 このスクリプト
では、選択状況に応じて警告を表示していますが、実際のスクリプトでは選択されているアイテムに応じて
何らかの操作を行うことになります (完全なスクリプトについては、TableSelection を参照してください)。
If myInCopy.Documents.Count <> 0 Then
If myInCopy.Selection.Count <> 0 Then
Select Case TypeName(myInCopy.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(myInCopy.Selection.Item(1).Parent) = "Cell" Then
MsgBox ("The selection is inside a table cell.")
Else
MsgBox ("The selection is not inside a table.")
End If
Case Else
MsgBox ("The selection is not inside a table.")
End Select
End If
End If
自動修正
自動修正機能を使用すると、テキストが入力されたときにテキストを自動的に修正することができます。 次
のスクリプトにその例を示します(完全なスクリプトについては、Autocorrect を参照してください)。
Rem The autocorrect preferences object turns the autocorrect feature
Rem on or off.
ReDim myNewWordPairList(0)
Set myInCopy = CreateObject("InCopy.Application")
Rem Add a word pair to the autocorrect list. Each AutoCorrectTable is linked
Rem to a specific language.
Set myAutoCorrectTable = myInCopy.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) - 1
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 myInCopy.AutoCorrectPreferences.AutoCorrect = False Then
yInCopy.AutoCorrectPreferences.AutoCorrect = True
End If
myInCopy.AutoCorrectPreferences.AutoCorrectCapitalizationErrors = True
第 4 章 テキストと組版
脚注
脚注 57
ストーリーに脚注を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、Footnotes
を参照してください)。
Set myDocument = myInCopy.Documents.Item(1)
With myDocument.FootnoteOptions
.SeparatorText = vbTab
.MarkerPositioning = idFootnoteMarkerPositioning.idSuperscriptMarker
End With
Set myStory = myDocument.Stories.Item(1)
Rem Add four footnotes at random locations in the story.
For myCounter = 1 To 4
myRandomNumber = CLng(myGetRandom(1, myStory.Words.Count))
Set myWord = myStory.Words.Item(myRandomNumber)
Set myFootnote = myWord.InsertionPoints.Item(-1).Footnotes.Add
Rem Note: when you create a footnote, it contains text--the footnote
Rem marker and the separator text (if any). If you try to set the text of
Rem the footnote by setting the footnote contents, you will delete the
Rem marker. Instead, append the footnote text, as shown below.
myFootnote.InsertionPoints.Item(-1).Contents = "This is a footnote."
Next
Rem This function gets a random number in the range myStart to myEnd.
Function myGetRandom(myStart, myEnd)
Rem Here's how to generate a random number from a given range:
Rem Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
myGetRandom = (myEnd - (myStart + 1)) * Rnd + myStart
End Function
5
ユーザーインターフェイス
章の更新ステータス
CS6
変更なし
イアログボックスか、テキストを入力するためのダイアログボックスに限られていますが、より複雑なダイ
アログボックスを使用したいこともあります。 InCopy スクリプティングを使用すれば、ポップアップリスト、
テキスト入力フィールド、数値入力フィールドなどの一般的なユーザーインターフェイスコントロールを備
えたダイアログボックスを作成できます。 ユーザー(または自分)から情報を受け取って、それに基づいて
処理を実行したい場合は、 dialog
オブジェクトが役に立ちます。
この章では、InCopy のダイアログボックスを使用したスクリプトについて説明します。 最初は簡単なサンプ
ルスクリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
注意 : JavaScript で InCopy スクリプトを作成する場合は、Adobe ScriptUI コンポーネントを使用してユーザー
インターフェイスを作成することもできます。 この章には、ScriptUI スクリプティングのチュートリアルも含
まれています。詳しくは、『Adobe Creative Suite® 5 JavaScript Tools Guide』を参照してください。
注意 : Visual Basic アプリケーションでは非常に複雑なユーザーインターフェイスが作成できますが、このイ
ンターフェイスは独立した Visual Basic 実行可能ファイルとして実行しなければなりません。 InCopy スクリプ
ティングには、InCopy の標準ユーザーインターフェイスによく似た外観を持つ複雑なダイアログボックスを
作成して、InCopy の中に表示する機能が用意されています。 VBScript は、外部アプリケーションから実行す
るよりも、スクリプトパレットから実行するほうが実行速度が速くなります。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
ダイアログボックスの概要
InCopy のダイアログボックスは、InCopy の他のスクリプティングオブジェクトと同じく、1 つのオブジェク
ることができます。
58
第 5 章 ユーザーインターフェイス ダイアログボックスの概要 59 dialog dialog column static text border panel checkbox control radiobutton group radiobutton control measurement editbox dropdown
この図に示されている各アイテムについて、次の表で説明します。
ダイアログボックスの要素
テキスト編集フィールド
数値入力フィールド
ポップアップメニュー
テキスト編集フィールドとポップアップメニューを
組み合わせたコントロール
チェックボックス
ラジオボタン
InCopy での名前
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
。
InCopy の他のスクリプティングオブジェクトと同じように、ダイアログボックスの各パーツにも固有のプロ
パティがあります。 例えば、
CheckboxControl
には、表示されるテキストを表すプロパティ(
StaticLabel
)
や、コントロールの状態を表すプロパティ(
CheckedState
)があります。 また、
Dropdown
コントロールには、
メニューに表示されるオプションのリストを表すプロパティ(
StringList
)があります。
スクリプトの中でダイアログボックスを使用するには、まず dialog
オブジェクトを作成し、そこに様々なコ
ントロールを配置して、ダイアログボックスを表示します。そして、スクリプトの処理に必要な値をそれら
のコントロールから収集します。 ダイアログボックスは、破棄されるまで InCopy のメモリ内に維持されま
を複数のスクリプトで使用することが可能です。ただし、ダイアログボックスを保持するためにメモリが消
費されるので、必要がなくなったら破棄するようにしてください。 一般的には、スクリプトが処理を終了す
る前にダイアログボックスオブジェクトを破棄します。
第 5 章 ユーザーインターフェイス
最初の InCopy ダイアログボックスの作成
最初の InCopy ダイアログボックスの作成 60
クスにダイアログコラムを追加し、ダイアログコラムにコントロールを追加します。 次のスクリプトにその
例を示します(完全なスクリプトについては、SimpleDialog を参照してください)。
Set myInCopy = CreateObject("InCopy.Application")
Set myDialog = myInCopy.Dialogs.Add
myDialog.name = "Simple Dialog"
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 box from memory.
myDialog.Destroy
「Hello World」へのユーザーインターフェイスの追加
次の例は、 第 2 章「はじめに」 で作成した Hello World チュートリアルスクリプトに、簡単なユーザーイン
ターフェイスを追加したものです。 ダイアログボックスに表示されるオプションを使用して、表示するテキ
ストを指定したり、テキストのポイントサイズを変更したりすることができます。 完全なスクリプトについ
ては、HelloWorldUI を参照してください。
Set myInCopy = CreateObject("InCopy.Application")
Set myDialog = myInCopy.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.RealEditboxes.Add
myPointSizeField.EditValue = 72
myDialog.Show
Rem Get the values from the dialog box controls.
myString = myTextEditField.EditContents
myPointSize = myPointSizeField.EditValue
Rem Remove the dialog box from memory.
myDialog.Destroy
Rem Create a new document.
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
Rem Enter the text from the dialog box.
myStory.Contents = myString
Rem Set the size of the text to the size you entered in the dialog box.
myStory.Texts.Item(1).PointSize = myPointSize
第 5 章 ユーザーインターフェイス さらに複雑なユーザーインターフェイスの作成 61
さらに複雑なユーザーインターフェイスの作成
次の例では、様々なコントロールをサンプルダイアログボックスに追加します。 この例では、次のようなダ
イアログボックスが作成されます。
完全なスクリプトについては、ComplexUI を参照してください。
Function myDisplayDialog(myInCopy)
ReDim mySwatchNames(myInCopy.Swatches.Count -1)
For myCounter = 1 To myInCopy.Swatches.Count
Set mySwatch = myInCopy.Swatches.Item(myCounter)
mySwatchNames(myCounter - 1) = mySwatch.Name
Next
Set myDialog = myInCopy.Dialogs.Add
myDialog.CanCancel = True
myDialog.Name = "ComplexUI"
Rem Create a dialog column.
With myDialog.DialogColumns.Add
Rem Create a border panel.
With .BorderPanels.Add
With .DialogColumns.Add
With .DialogRows.Add
With .StaticTexts.Add
.StaticLabel = "Message:"
End With
Set myTextEditField = .TextEditboxes.Add
myTextEditField.EditContents = "Hello World!"
myTextEditField.MinWidth = 180
End With
End With
End With
With .BorderPanels.add
With .DialogColumns.Add
With .DialogRows.Add
With .StaticTexts.Add
.StaticLabel = "Point Size:"
End With
Set myPointSizeField = .MeasurementEditboxes.Add
myPointSizeField.EditUnits = idMeasurementUnits.idPoints
myPointSizeField.EditValue = 72
End With
End With
End with
With .BorderPanels.Add
With .DialogColumns.Add
With .DialogRows.Add
With .StaticTexts.Add
.StaticLabel = "Paragraph Alignment:"
End With
Set myRadioButtonGroup = .RadiobuttonGroups.Add
With myRadioButtonGroup
第 5 章 ユーザーインターフェイス さらに複雑なユーザーインターフェイスの作成 62
With .RadiobuttonControls.Add
.StaticLabel = "Left"
.CheckedState = True
End With
With .RadiobuttonControls.Add
.StaticLabel = "Center"
End With
With .RadiobuttonControls.Add
.StaticLabel = "Right"
End With
End With
End With
End With
End With
With .BorderPanels.Add
With .DialogColumns.Add
With .DialogRows.Add
With .StaticTexts.Add
.StaticLabel = "Text Color:"
End With
Set mySwatchDropdown = .Dropdowns.Add
mySwatchDropdown.StringList = mySwatchNames
mySwatchDropdown.SelectedIndex = 2
End With
End With
End With
End With
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
myParagraphAlignment = myRadioButtonGroup.SelectedButton
mySwatchName = mySwatchNames(mySwatchDropdown.SelectedIndex)
myDialog.Destroy
myCreateExampleDocument myInCopy, myString, myPointSize,
myParagraphAlignment, mySwatchName
Else
myDialog.Destroy
End If
End Function
Function myCreateExampleDocument(myInCopy, myString, myPointSize, myParagraphAlignment, mySwatchName)
Set myDocument = myInCopy.Documents.Add
Set myStory = myDocument.Stories.Item(1)
Rem Enter the text from the dialog box in the story.
myStory.Contents = myString
Rem Set the size of the text to the size you entered in the dialog box.
myStory.Texts.Item(1).PointSize = myPointSize
Rem set the paragraph alignment of the text to the
Remdialog radio button choice.
Select Case myParagraphAlignment
Case 0
myStory.Texts.Item(1).Justification = idJustification.idLeftAlign
Case 1
myStory.Texts.Item(1).Justification = idJustification.idCenterAlign
Case Else
myStory.Texts.Item(1).Justification = idJustification.idRightAlign
End Select
Rem Apply the selected swatch to the fill of the text.
myStory.Texts.Item(1).FillColor = myDocument.Swatches.Item(mySwatchName)
End function
第 5 章 ユーザーインターフェイス
ScriptUI の使用 63
ScriptUI の使用
JavaScript では、ScriptUI というアドビ システムズ社独自のスクリプティングコンポーネントを使用して、
ユーザーインターフェイス要素の作成や定義が行えます。 ScriptUI を使用すれば、InCopy の組み込みの dialog
オブジェクトよりも格段に複雑なインタラクティブダイアログボックスを作成できます。また、フ
ローティングパレットやプログレスバーも作成できます。
AppleScript や VBScript でも、ScriptUI を使用して定義されたユーザーインターフェイス要素にアクセスするこ
とができます。 do script メソッド(AppleScript の場合)や DoScript メソッド(VBScript の場合)を使用すれ
ば、他のスクリプト言語で書かれたスクリプトを実行できます。
ScriptUI を使用したプログレスバーの作成
JavaScript で ScriptUI を使用してプログレスバーを作成する方法を、次のスクリプトに示します(完全なスク
リプトについては、ProgressBar を参照してください)。このスクリプトで作成したプログレスバーは、
AppleScript や VBScript でも使用することが可能です。
#targetengine "session"
var myProgressPanel;
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 を参照してください)。
Set myInCopy = CreateObject("InCopy.Application")
myString = "myProgressPanel = myCreateProgressPanel(100, 400);" & vbcr
myString = myString & "myProgressPanel.show();" & vbcr
myInCopy.DoScript myString, idScriptLanguage.idJavascript
For myCounter = 1 to 100
Set myStory = myInCopy.Documents.Item(1)
myStory.InsertionPoints.Item(-1).Contents = "x"
myString = "myProgressPanel.myProgressBar.value = " & cstr(myCounter) &
"/myIncrement;" & vbcr
myInCopy.DoScript myString, idScriptLanguage.idJavascript
If(myCounter = 100) Then
myString = "myProgressPanel.myProgressBar.value = 0;" & vbcr
myString = myString & "myProgressPanel.hide();" & vbcr
myInCopy.DoScript myString, idScriptLanguage.idJavascript
End If
Next
ScriptUI を使用したボタンバーパネルの作成
スクリプトを実行するボタンが並んだフローティングパレットも、JavaScript と ScriptUI を使用して作成する
ことができます。 実行するスクリプトはどの言語であってもかまいません。
簡単なフローティングパネルの作成方法を、次のチュートリアルスクリプトに示します。 パネルには一連の
ボタンが配置され、各ボタンはディスク上のスクリプトに関連付けられています。 ボタンをクリックすると
スクリプトが実行されます(このスクリプトで、ダイアログボックスや他のユーザーインターフェイス要素
第 5 章 ユーザーインターフェイス
ScriptUI の使用 64
(完全なスクリプトについては、ButtonBar を参照してください)。
このチュートリアルスクリプトは、次の形式の XML ファイルを読み込みます。
<buttons>
<button>
<buttonType></buttonType>
<buttonName></buttonName>
<buttonFileName></buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
...
</buttons>
次に例を示します。
<buttons>
<button>
<buttonType>text</buttonType>
<buttonName>FindChangeByList</buttonName>
<buttonFileName>/c/buttons/FindChangeByList.jsx</buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
<button>
<buttonType>text</buttonType>
<buttonName>SortParagraphs</buttonName>
<buttonFileName>/c/buttons/SortParagraphs.jsx</buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
</buttons>
XML ファイルを読み込んでボタンバーをセットアップする関数は、次のとおりです。
#targetengine "session"
var myButtonBar;
main();
function main(){
myButtonBar = myCreateButtonBar();
myButtonBar.show();
}
function myCreateButtonBar(){
var myButtonName, myButtonFileName, myButtonType, myButtonIconFile, myButton;
var myButtons = myReadXMLPreferences();
if(myButtons != ""){
myButtonBar = new Window('window', 'Script Buttons', undefined,
{maximizeButton:false, minimizeButton:false});
with(myButtonBar){
spacing = 0;
margins = [0,0,0,0];
with(add('group')){
spacing = 2;
orientation = 'row';
for(var myCounter = 0; myCounter < myButtons.length(); myCounter++){
myButtonName = myButtons[myCounter].xpath("buttonName");
myButtonType = myButtons[myCounter].xpath("buttonType");
myButtonFileName = myButtons[myCounter].xpath("buttonFileName");
myButtonIconFile = myButtons[myCounter].xpath("buttonIconFile");
if(myButtonType == "text"){
myButton = add('button', undefined, myButtonName);
}
else{
myButton = add('iconbutton', undefined,
File(myButtonIconFile));
}
myButton.scriptFile = myButtonFileName;
第 5 章 ユーザーインターフェイス myButton.onClick = function(){
myButtonFile = File(this.scriptFile)
app.doScript(myButtonFile);
}
}
}
}
}
return myButtonBar;
}
function myReadXMLPreferences(){
myXMLFile = File.openDialog("Choose the file containing your
button bar defaults");
var myResult = myXMLFile.open("r", undefined, undefined);
var myButtons = "";
if(myResult == true){
var myXMLDefaults = myXMLFile.read();
myXMLFile.close();
var myXMLDefaults = new XML(myXMLDefaults);
var myButtons = myXMLDefaults.xpath("/buttons/button");
}
return myButtons;
}
ScriptUI の使用 65
6
メニュー
章の更新ステータス
CS6
変更なし
InCopy スクリプティングでは、メニュー項目の追加と削除、任意のメニューコマンドの実行、メニュー項目
へのスクリプトの割り当てを行うことができます。
この章では、InCopy のメニューをスクリプトで操作する方法について説明します。 最初は簡単なサンプルス
クリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
メニューモデルについて
InCopy のメニュースクリプトモデルは、アプリケーションのユーザーインターフェイスに表示されるメ
ニューに対応する一連のオブジェクトによって構成されています(メインのメニューバーに表示されるメ
ニューだけでなく、パネルに用意されているメニューも含みます)。
オブジェクトには、次のオブジェク
トが含まれています。
MenuItems
— メニューに表示されるメニューオプション (サブメニューは含まれません)
MenuSeparators
— メニュー内のメニューオプションを区切るために使用される線
Submenus
— 更なるメニュー選択が含まれているメニューオプション
MenuElements
— メニューに表示されるすべての
MenuItems
、
MenuSeparators
、
Submenus
EventListeners
— メニューに対するユーザーアクションやスクリプトアクションに応答するためのリス
ナー
Events
— メニューによって発生した events
どの
MenuItem
にも、
AssociatedMenuAction
というプロパティによって
MenuAction
が割り当てられていま
す。 そのメニュー項目が選択されたときの処理は、
MenuAction
のプロパティによって定義されています。
ユーザーインターフェイスで定義されている
MenuAction
に加えて、独自の
ScriptMenuAction
を作成して、
メニュー項目にスクリプトを割り当てることができます。
1 つの
MenuAction
や
ScriptMenuAction
は、0 個以上の
MenuItem
に関連付けることができます。
次の図に、様々なメニューオブジェクトの関係を示します。
66
第 6 章 メニュー メニューモデルについて 67 application menuActions menuAction area checked enabled eventListeners id index label name events parent title scriptMenuActions scriptMenuAction same as menuAction eventListener eventListener
...
event event
...
表示可能なすべてのメニューアクションのリスト(テキストファイル)を作成するには、次のスクリプトを
実行します(チュートリアルスクリプトの GetMenuActions より)。
Set myInCopy = CreateObject("InCopy.Application")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Rem You'll need to fill in a valid file path on your system.
Set myTextFile = myFileSystemObject.CreateTextFile("c:¥menuactions.txt", True, False)
For myCounter = 1 To myInCopy.MenuActions.Count
Set myMenuAction = myInCopy.MenuActions.Item(myCounter)
myTextFile.WriteLine myMenuAction.name
Next
myTextFile.Close
MsgBox "done!"
利用可能なメニューのリスト(テキストファイル)を作成するには、次のスクリプトを実行します(完全な
スクリプトについては、GetMenuNames というチュートリアルスクリプトを参照してください)。 InCopy には
多数のメニューがあるので、このスクリプトの実行には時間がかかる場合があります。
第 6 章 メニュー メニューモデルについて 68
Set myInCopy = CreateObject("InCopy.Application")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myTextFile = myFileSystemObject.CreateTextFile("c:¥menunames.txt", True, False)
For myMenuCounter = 1 To myInCopy.Menus.Count
Set myMenu = myInCopy.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
ローカライゼーションとメニュー名
InCopy スクリプティングでは、
MenuItem
、
Menu
、
MenuAction
、
Submenu
はすべて名前で参照されます。
がって、アプリケーションがインストールされているロケールに依存せずにオブジェクトを指定する方法が
必要になります。 これを行うには、ロケールに依存せずに特定の項目を参照するための文字列が格納されて
いる内部データベースを使用します。 例えば、次のスクリプトを使用すれば、ロケールに依存しないメ
ニューアクション名を取得することができます(完全なスクリプトについては、GetKeyStrings を参照してく
ださい)。
Set myInCopy = CreateObject("InCopy.Application")
Rem Fill in the name of the menu action you want.
Set myMenuAction = myInCopy.MenuActions.Item("$ID/Convert to Note")
myKeyStrings = myInCopy.FindKeyStrings(myMenuAction.Name)
myString = ""
For Each myKeyString In myKeyStrings
myString = myString & myKeyString & vbCr
Next
MsgBox myString
注意 : ロケールに依存しない名前を取得する場合は、
Menu
、
MenuItem
、
Submenu
の名前を取得するよりも、
MenuAction
の名前を取得するほうが便利です。
MenuAction
のタイトルは、単一の文字列である場合が多いか
第 6 章 メニュー スクリプトからのメニューアクションの実行 69
らです。
GetKeyStrings
メソッドで複数の文字列が返されま
す。
ロケールに依存しない名前を取得したら、スクリプトで使用することができます。 この文字列を使用したス
クリプトは、現在使用している InCopy と異なるロケールにインストールされている InCopy でも正常に機能
します。
ロケールに依存しない文字列を現在のロケールに変換するには、次のスクリプトを使用します(チュートリ
アルスクリプトの TranslateKeyString より)。
Set myInCopy = CreateObject("InCopy.Application")
Rem Fill in the appropriate key string in the following line.
myString = myInCopy.TranslateKeyString("$ID/Convert to Note")
MsgBox myString
スクリプトからのメニューアクションの実行
InCopy に組み込まれている
MenuAction
は、いずれもスクリプトから実行することができます。
MenuAction
が
MenuItem
に割り当てられているとは限りませんが、その点を除けば、スクリプトから
MenuAction
を実行することは、ユーザーインターフェイスでメニューオプションを選択することとまったく
応する
MenuAction
をスクリプトから実行すると同じダイアログボックスが表示されます。
スクリプトから
MenuAction
を実行する方法を、次のスクリプトに示します(完全なスクリプトについては、
Set myInCopy = CreateObject("InCopy.Application")
Rem Get a reference to a menu action.
Set myMenuAction = myInCopy.MenuActions.Item("$ID/Convert to Note")
Rem Run the menu action. The example action will fail if you do not
Rem have text selected.
myMenuAction.Invoke
注意 : 一般的に、InCopy のプロセスをスクリプトで自動化する場合、メニューアクションやユーザーイン
ターフェイスを選択することで必要な処理を実行するのは、あまりよい方法とは言えません。InCopy のスク
リプトオブジェクトモデルを操作するほうが、はるかに確実で強力な処理を実現できます。 メニューアク
ションは、選択やウィンドウの状態など、ユーザーインターフェイスの様々な条件に依存しています。 オブ
ジェクトモデルを使用すれば、InCopy ドキュメント内のオブジェクトを直接操作できるので、ユーザーイン
ターフェイスに依存することなく、一貫性のある高速な処理を実現できます。
メニューやメニュー項目の追加
InCopy のユーザーインターフェイスと同じように、スクリプトでもメニューやメニュー項目の作成や削除が
法を、次のサンプルスクリプトに示します(完全なスクリプトについては、CustomizeMenu を参照してくだ
さい)。
Set myInCopy = CreateObject("InCopy.Application")
Set myMainMenu = myInCopy.Menus.Item("Main")
Set myTypeMenu = myMainMenu.MenuElements.Item("Type")
Set myFontMenu = myTypeMenu.MenuElements.Item("Font")
Set myKozukaMenu = myFontMenu.Submenus.Item("Kozuka Mincho Pro ")
Set mySpecialFontMenu = myMainMenu.Submenus.Add("Kozuka Mincho Pro")
For myCounter = 1 To myKozukaMenu.MenuItems.Count
Set myAssociatedMenuAction = myKozukaMenu.MenuItems.Item(myCounter).AssociatedMenuAction
mySpecialFontMenu.MenuItems.Add myAssociatedMenuAction
Next
このスクリプトで追加したカスタムメニューを削除するには、RemoveSpecialFontMenu スクリプトを実行し
ます。
第 6 章 メニュー メニューとイベント 70
Set myMainMenu = myInCopy.Menus.Item("Main")
Set mySpecialFontMenu = myMainMenu.Submenus.Item("Kozuka Mincho Pro")
mySpecialFontMenu.Delete
メニューとイベント
ユーザーインターフェイスでメニューやサブメニューを選択すると、イベントが生成されます。これと同じ
ように、
MenuAction
や
ScriptMenuAction
を実行した場合にも、イベントが生成されます。
用すれば、これらのイベントに応答するために
EventListener
を登録することができます。
スクリプティングコンポーネントのイベントを次の表に示します。
オブジェクト
Menu
MenuAction
ScriptMenuAction
Submenu
イベント
beforeDisplay afterInvoke beforeInvoke afterInvoke beforeInvoke beforeDisplay onInvoke beforeDisplay
説明
メニューの内容が表示される前に、登録したスクリプトが実
行されます。
関連付けられている
MenuItem
が選択されて、 onInvoke
イベン
トが発生した後に、登録したスクリプトが実行されます。
関連付けられている
MenuItem
が選択されて、 onInvoke
イベン
トが発生する前に、登録したスクリプトが実行されます。
関連付けられている
MenuItem
が選択されて、 onInvoke
イベン
トが発生した後に、登録したスクリプトが実行されます。
関連付けられている
MenuItem
が選択されて、 onInvoke
イベン
トが発生する前に、登録したスクリプトが実行されます。
ScriptMenuAction
の有効/チェックのステータスに対する内
部要求が行われる前に、登録したスクリプトが実行されます。
ScriptMenuAction
が呼び出されたときに、登録したスクリプ
トが実行されます。
Submenu
の内容が表示される前に、登録したスクリプトが実行
されます。
Event
や
EventListener
を参照してください。
メニューに表示する項目を変更するには、 beforeDisplay Event
に対する
EventListener
メ
ニューが選択されると、登録したスクリプト(メニュー項目の有効化/無効化や名前の変更などの、メ
ニューに関連するタスクを実行するスクリプト)が
EventListener
によって実行されます。
利用可能なフォント、最近使用したドキュメント、開いているウィンドウなどをメニューに表示するために、
内部的に使用されています。
スクリプトメニューアクションの操作
ScriptMenuAction
を使用すると、
MenuAction
を新しく作成して、 onInvoke Event
の発生時に指定のスクリプ
トを実行することができます。
ScriptMenuAction
を作成してメニュー項目に割り当てる方法を、次のスクリプトに示します(完全なスクリ
プトについては、MakeScriptMenuAction を参照してください)。 このスクリプトでは、メニュー項目が選択さ
れると、単に警告が表示されます。
第 6 章 メニュー スクリプトメニューアクションの操作 71
Set myInCopy = CreateObject("InCopy.Application")
Set mySampleScriptAction = myInCopy.ScriptMenuActions.Add("Display Message")
Set myEventListener = mySampleScriptAction.EventListeners.Add("onInvoke", "c:¥message.vbs")
Set mySampleScriptMenu = myInCopy.Menus.Item("$ID/Main").Submenus.Add("Script Menu Action")
Set mySampleScriptMenuItem = mySampleScriptMenu.MenuItems.Add(mySampleScriptAction) message.vbs
スクリプトファイルには、次のコードが含まれます。
MsgBox("You selected an example script menu action.")
このスクリプトで作成した
Menu
、
Submenu
、
MenuItem
、
ScriptMenuAction
を削除するには、次のスクリプト
を実行します(チュートリアルスクリプトの RemoveScriptMenuAction より)。
Set myInCopy = CreateObject("InCopy.Application")
Set mySampleScriptAction = myInCopy.ScriptMenuActions.Item("Display Message")
mySampleScriptAction.Delete
Set mySampleScriptMenu = myInCopy.Menus.Item("$ID/Main").Submenus.Item("Script Menu Action")
mySampleScriptMenu.Delete
すべての
ScriptMenuAction
を削除することもできます。次のスクリプトにその例を示します(チュートリア
ルスクリプトの RemoveAllScriptMenuActions より)。 このスクリプトでは、
ScriptMenuAction
のメニューリス
トも削除されますが、作成したメニューやサブメニューは削除されません。
Set myInCopy = CreateObject("InCopy.Application")
For myCounter = myInCopy.ScriptMenuActions.Count To 1 Step -1
myInCopy.ScriptMenuActions.Item(myCounter).Delete
Next
現在のすべての
ScriptMenuAction
のリストを作成することができます。次のスクリプトにその例を示します
(チュートリアルスクリプトの GetScriptMenuActions より)。
Set myInCopy = CreateObject("InCopy.Application")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Rem You'll need to fill in a valid file path for your system.
Set myTextFile = myFileSystemObject.CreateTextFile("c:¥scriptmenuactionnames.txt", True, False)
For myCounter = 1 To myInCopy.ScriptMenuActions.Count
Set myScriptMenuAction = myInCopy.ScriptMenuActions.Item(myMenuCounter)
myTextFile.WriteLine myScriptMenuAction.Name
Next
myTextFile.Close
ScriptMenuAction
を使用して、 beforeDisplay Event
の発生時にスクリプトを実行することもできます。こ
の場合は、
ScriptMenuAction
の状態に対する内部要求が行われる前に(メニュー項目が表示される直前に)
スクリプトが実行されます。 これは、スクリプトでメニュー名を変更したり、有効/チェックのステータス
を設定したりする場合に特に役立ちます。
次のサンプルスクリプトでは、 beforeDisplay Event
に対する
EventListener
を追加して、現在の選択を確認
するようにしています。 何も選択されていない場合は、
EventListener
のスクリプトによってメニュー項目が
無効化されます。 アイテムが選択されている場合は、メニュー項目が有効化されます。メニュー項目を選択
すると、選択されている最初のアイテムの種類が表示されます (完全なスクリプトについては、
Set myInCopy = CreateObject("InCopy.Application")
Set mySampleScriptAction = myInCopy.ScriptMenuActions.Add("Display Message")
Set myEventListener = mySampleScriptAction.EventListeners.Add("onInvoke", "c:¥WhatIsSelected.vbs
")
Set mySampleScriptMenu = myInCopy.Menus.Item("$ID/Main").Submenus.Add("Script Menu Action")
Set mySampleScriptMenuItem = mySampleScriptMenu.MenuItems.Add(mySampleScriptAction)
mySampleScriptMenu.EventListeners.Add "beforeDisplay", "c:¥BeforeDisplayHandler.vbs"
BeforeDisplayHander チュートリアルスクリプトファイルには、次のスクリプトが含まれます。
第 6 章 メニュー スクリプトメニューアクションの操作 72
Set myInCopy = CreateObject("InCopy.Application")
Set mySampleScriptAction = myInCopy.ScriptMenuActions.Item("Display Message")
If myInCopy.Selection.Count > 0 Then
mySampleScriptAction.Enabled = True
Else
mySampleScriptAction.Enabled = False
End If
WhatIsSelected チュートリアルスクリプトファイルには、次のスクリプトが含まれます。
Set myInCopy = CreateObject("InCopy.Application")
myString = TypeName(myInCopy.Selection.Item(1))
MsgBox "The first item in the selection is a " & myString & "."
7
イベント
章の更新ステータス
CS6
変更なし
InCopy スクリプティングでは、アプリケーションやドキュメントの一般的なイベント(ファイルのオープ
ン、新規ファイルの作成、印刷、ディスク上のテキストファイルやグラフィックファイルの読み込みなど)
に応答することができます。 アプリケーションで発生するイベントは、 event
オブジェクトによって表されま
す。 イベントにスクリプトを割り当てるには、
EventListener
というスクリプトオブジェクトを使用します。
イベントに割り当てるスクリプトは、通常のスクリプトとほとんど同じですが、通常のスクリプトはユー
ザーが(スクリプトパネルから)実行するのに対して、イベントに割り当てるスクリプトは自動的に(目的
のイベントが発生したときに)実行される点が異なります。
この章では、InCopy のイベントを使用したスクリプトについて説明します。 最初は簡単なサンプルスクリプ
トから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
この章では、アプリケーションやドキュメントに関連するイベントについて説明します。 メニューに関連す
を参照してください。
InCopy のイベントスクリプトモデルは、Worldwide Web Consortium(W3C)勧告のドキュメントオブジェク
トモデルイベントに似ています。 詳しくは、 http://www.w3c.org
を参照してください。
イベントスクリプトモデルについて
InCopy のイベントスクリプトモデルは、アプリケーションで発生する各種のイベントに相当する一連のオブ
ジェクトによって構成されています。 その中心となるのが event
オブジェクトです。これは、InCopy のユー
ザーインターフェイスで行われる特定のアクション(またはスクリプトの処理に相当するアクション)を表
します。
イベントに応答するには、そのイベントを受け取るオブジェクトに
EventListener
を登録します。
ジェクトが指定のイベントを受け取ると、
EventListener
のハンドラー関数に定義されているスクリプト関
数(ディスク上のスクリプトファイルへの参照)が実行されます。
次の表に、
EventListener
で応答できるイベントを示します。
ドショートカット、スクリプトアクションなどの任意の方法で発生させることができます。
73
第 7 章 イベント イベントスクリプトモデルについて 74
ユーザー
インターフェイス
イベント イベント名
任意のメニューア
クション beforeDisplay beforeDisplay
閉じる
書き出し
読み込み
新規
開く
プリント beforeInvoke afterInvoke onInvoke beforeClose afterClose beforeExport afterExport beforeImport afterImport beforeNew afterNew beforeOpen afterOpen beforePrint afterPrint
説明
メニューやサブメニューが表示される
前に発生。
スクリプトメニューアクションが表示
または変更される前に発生。
メニュー項目が選択された後、メ
ニューアクションの内容が実行される
前に発生。
メニューアクションが実行された後に
発生。
オブジェクトタイプ
Event
Event
Event
Event
メニューアクションやスクリプトメ
ニューアクションの実行時に発生。
「ドキュメントを閉じる」要求が発行
された後、ドキュメントが閉じられる
前に発生。
Event
DocumentEvent
ドキュメントが閉じられた後に発生。 DocumentEvent
書き出し要求が発行された後、ドキュ
メントまたはページアイテムが書き出
される前に発生。
ドキュメントまたはページアイテムが
書き出された後に発生。
ImportExportEvent
ImportExportEvent
ファイルが読み込まれる前、ファイル
がドキュメントに読み込まれる前(配
置される前)に発生。
ファイルが読み込まれた後、ファイル
がページに配置される前に発生。
「新規ドキュメント」要求が発行され
た後、ドキュメントが作成される前に
発生。
新規ドキュメントが作成された後に発
生。
ImportExportEvent
ImportExportEvent
DocumentEvent
DocumentEvent
「ドキュメントを開く」要求が発行さ
れた後、ドキュメントが開かれる前に
発生。
ドキュメントが開かれた後に発生。
DocumentEvent
DocumentEvent
DocumentEvent 「ドキュメントのプリント」要求が発
行された後、ドキュメントがプリント
される前に発生。
ドキュメントがプリントされた後に発
生。
DocumentEvent
第 7 章 イベント イベントスクリプトモデルについて 75
ユーザー
インターフェイス
イベント イベント名
復帰
保存
複製を保存
別名で保存 beforeRevert afterRevert beforeSave afterSave
説明
「ドキュメント復帰」要求が発行され
た後、保存されている以前の状態にド
キュメントが戻される前に発生。
保存されている以前の状態にドキュメ
ントが戻された後に発生。
オブジェクトタイプ
DocumentEvent
DocumentEvent
「ドキュメントの保存」要求が発行さ
れた後、ドキュメントが保存される前
に発生。
DocumentEvent
ドキュメントが保存された後に発生。
DocumentEvent beforeSaveACopy
「ドキュメントの複製保存」要求が発
行された後、ドキュメントが保存され
る前に発生。 afterSaveACopy
DocumentEvent
ドキュメントが保存された後に発生。
DocumentEvent beforeSaveAs afterSaveAs
「ドキュメントの別名保存」要求が発
行された後、ドキュメントが保存され
る前に発生。
DocumentEvent
ドキュメントが保存された後に発生。
DocumentEvent
イベントプロパティとイベントの伝達について
ユーザーやスクリプトによってアクションが実行されてイベントが発生すると、そのイベントに応答可能な
スクリプティングオブジェクトにイベントが伝達されます。 特定のイベントに対する
EventListener
が登録
されているオブジェクトにそのイベントが伝達されると、その
EventListener
が呼び出されます。
ントが複数のオブジェクトに伝達されて、複数のオブジェクトで処理が行われる場合もあります。
イベントの伝達には、次の 3 種類があります。
伝達しない — イベントターゲットに登録されている
EventListener
のみが呼び出されます。
イベントの例としては、 beforeDisplay
イベントがあります。
キャプチャ — スクリプトオブジェクトモデルの最上位(アプリケーション)から始まって、イベント
ターゲットまで伝達されます。 target
の上位にあるオブジェクトに登録されている、そのイベントに応
答可能なすべての
EventListener
でイベントが処理されます。
バブル — target
から伝達が開始されます。まず、 target
に登録されている応答可能な
EventListener
が呼び出されます。 次に、スクリプトオブジェクトモデルの上方向にイベントが伝達されます。スクリ
プトオブジェクトモデルで target
の上位にあるオブジェクトに登録されている、そのイベントに応答可
能な
EventListener
が呼び出されます。
次の表に、 event
のプロパティの詳細と、スクリプトオブジェクトモデルでのイベント伝達に与える影響を
示します。
第 7 章 イベント eventListener の操作 76
プロパティ
Bubbles
Cancelable
Captures
CurrentTarget
DefaultPrevented
EventPhase
EventType
PropagationStopped
Target
TimeStamp
説明
true の場合、 event
が発生したオブジェクトの上位にあるスクリプティングオブ
ジェクトにその event
が伝達されます。 true の場合、 target
における event
のデフォルトの動作をキャンセルできます。
これを行うには、
PreventDefault
メソッドを使用します。 true の場合、イベント伝達のキャプチャフェーズで、イベントのターゲットオブ
ジェクトの上位にあるスクリプティングオブジェクトに登録されている
EventListener
EventListener
が呼び出される前に、アプリケーションの
EventListener
でド
キュメントイベントに応答することができます。 event
この表の
Target
を
参照してください。 true の場合、現在の target
(この表の
Target
を参照)における event
のデフォ
ルト動作が実行されず、アクションがキャンセルされます。 event
の伝達プロセスの現在のステージ。 event
のタイプを表す文字列( beforeNew true の場合、 current target
以降への伝達が中止されます(この表の
Target
を
参照してください)。
StopPropagation
メソッド
を使用します。 event
例えば、 beforeImport
イベントの
Target
はド
キュメントであり、 beforeNew
イベントの
Target
はアプリケーションです。 event
が発生した日時。
eventListener の操作
EventListener
、イベントハンドラー(ファイル参照)、
イベントのキャプチャフェーズで
EventListener
を呼び出すかどうかを指定します。
て
EventListener
を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
Set myInDesign = CreateObject("InDesign.Application.CS6"
Set myEventListener = myInDesign.EventListeners.Add("afterNew",
"c:¥ICEventListeners¥Message.vbs", false)
このスクリプトで参照されているスクリプトファイルには、次のコードが含まれています。
Rem "evt" is the event passed to this script by the event listener.
MsgBox ("This event is the " & evt.EventType & " event.")
このスクリプトで作成した
EventListener
を削除するには、次のスクリプトを実行します(チュートリアル
スクリプトの RemoveEventListener より)。
Set myInDesign = CreateObject("InCopy.Application")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myFile = myFileSystemObject.GetFile("c:¥IDEventHandlers¥message.vbs")
myResult = myInDesign.RemoveEventListener("afterNew", myFile, False)
1 つの
EventListener
でイベントが処理されても、そのイベントを監視している他の
EventListener
があれ afterOpen
イベントは、アプリケーションとドキュメントの両方の
EventListener
で監視されている可能性
があります。
第 7 章 イベント eventListener の操作 77
EventListener
すべての InCopy セッ
ションで
EventListener
を利用できるようにしたい場合は、スタートアップスクリプト用のフォルダーであ
る Startup Scripts にスクリプトを追加します(スクリプトのインストールについて詳しくは、 第 2 章「はじめ
を参照してください)。
EventListener
スクリプトを追加しても、ドキュメントとともに
保存されたり、INX に書き出されたりすることはありません。
注意 :
EventListener
を定義するスクリプトで問題が発生した場合は、その
EventListener
を削除するスクリ
プトを実行するか、InCopy を終了して再起動します。
スクリプトオブジェクトモデルの中で 1 つのイベントが伝達されて、複数の
EventListener
が呼び出される
場合があります。 次のサンプルスクリプトでは、様々なオブジェクトに登録されている
EventListener
が 1
つのイベントによって呼び出されます(完全なスクリプトについては、MultipleEventListeners を参照してく
Set myInDesign = CreateObject("InCopy.Application")
Set myEventListener = myInDesign.EventListeners.Add("beforeImport", "c:¥EventInfo.vbs", True)
Set myDocument = myInDesign.Documents.Add
Set myEventListener = myDocument.EventListeners.Add("beforeImport", "c:¥EventInfo.vbs", False)
このスクリプトで参照されている
EventInfo.vbs
というスクリプトファイルには、次のスクリプトコードが
含まれています。 main evt
Function main(myEvent)
myString = "Current Target: " & myEvent.CurrentTarget.Name
MsgBox myString, vbOKOnly, "Event Details"
end function
このスクリプトを実行してファイルを配置すると、ドキュメントの名前を示す警告と、アプリケーションの
名前を示す警告が順に表示されます。
次のサンプルスクリプトでは、サポートされている各イベントの
EventListener
を作成して、簡単なダイア
ログボックスにイベントに関する情報を表示しています。 完全なスクリプトについては、EventListenersOn を
参照してください。
Rem EventListenersOn.vbs
Rem An InCopy CS6 JavaScript
Rem
Rem Installs event listeners for all supported events; displays a
Rem message when each event occurs.
Rem
Set myInCopy = CreateObject("InCopy.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)
myInCopy.AddEventListener myEventNames(myCounter), "c:¥GetEventInfo.vbs", False
If myCounter < UBound(myEventNames) Then
myInCopy.EventListeners.Add myEventNames(myCounter), "c:¥GetEventInfo.vbs", False
End If
Next
このスクリプトで参照されているスクリプトファイルには、次のコードが含まれています。 このファイル参
照で示されているディスク上の場所に、該当するスクリプトファイルが存在している必要があります。 完全
なスクリプトについては、
GetEventInfo.vbs
を参照してください。
第 7 章 イベント 「afterNew」eventListener の例 78
Rem GetEventInfo.vbs
Rem An InCopy CS6 VBScript
Rem
Rem Displays information about an Event object; called from an EventListener.
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 & "Captures: " & myEvent.Captures
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.idCapturingPhase
myPhaseName = "Capturing"
Case idEventPhases.idDone
myPhaseName = "Done"
Case idEventPhases.idNotDispatching
myPhaseName = "Not Dispatching"
end select
myGetPhaseName = myPhaseName
End Function
アプリケーションオブジェクトのすべての
EventListener
をオフにする方法を、次のサンプルスクリプトに
Rem EventListenersOff.vbs
Rem An InCopy CS6 JavaScript
Rem
Rem Removes all event listeners from the application.
Set myInCopy = CreateObject("InCopy.Application")
For myCounter = 1 To myInCopy.EventListeners.Count
myInCopy.EventListeners.Item(1).Delete
Next
「afterNew」eventListener の例
afterNew
イベントは、ユーザー名、ドキュメントの作成日、著作権情報、その他の作業に関する情報などを
ドキュメントに追加したい場合に便利です。 ドキュメントのメタデータ(ファイル情報または XMP 情報とも
呼ばれます)にこのような情報を追加する方法を、次のサンプルスクリプトに示します。 完全なスクリプト
リストについては、AfterNew というチュートリアルスクリプトを参照してください。
Set myInCopy = CreateObject("InCopy.Application")
Set myEventListener = myInCopy.EventListeners.Add("afterNew", "c:¥AfterNewHandler.vbs")
このスクリプトで参照されているスクリプトファイルには、次のコードが含まれています。 このファイル参
照で示されているディスク上の場所に、該当するスクリプトファイルが存在している必要があります。 完全
なスクリプトについては、
AfterNewHandler.vbs
を参照してください。
第 7 章 イベント 「afterNew」eventListener の例 79
Rem AfterNewHandler.vbs
Rem An InCopy CS6 VBScript
Rem
Rem Adds metadata to a new document.
myAddMetadata evt
Function myAddMetadata(myEvent)
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
myInCopy.UserName = "Adobe"
With myDocument.MetadataPreferences
.Author = "Adobe Systems"
.Description = "This is a sample document with XMP metadata." &
vbCr & "Created: " + myEvent.TimeStamp
End With
End Function
8
注釈
章の更新ステータス
CS6
変更なし
InDesign および InCopy では、インライン式の編集上の注釈機能を使用して、ストーリーのフローに影響を与
えることなく、注釈としてコメントを直接テキストに追加できます。 注釈機能は、ワークグループ環境で使
用する目的で設計されています。 特定の条件に基づいて、注釈に色を付けたり、オン / オフを切り替えたりす
ることもできます。
注釈を作成するには、ツールボックスの注釈ツール、注釈/新規注釈のコマンド、または注釈パレットの新
規注釈アイコンを使用します。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、InCopy で注釈を操作する方法を理解しているものとして
います。
注釈の入力と読み込み
ここでは、InCopy ドキュメントに注釈を配置する方法について説明します。 InCopy のユーザーインターフェ
イスを使用して注釈を作成したり、注釈のテキストを置換したりするのと同じように、スクリプトを使用し
て注釈を作成したり、注釈にテキストを挿入したりすることができます。
ストーリーへの注釈の追加
ストーリーに注釈を追加するには、
Add
メソッドを使用します。 次のサンプルでは、最後の挿入点に注釈を追
加しています。 完全なスクリプトについては、InsertNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Rem We'll use the last insertion point in the story.
Set myInsertionPoint = myStory.insertionPoints.Item(-1)
Set myNote = myInsertionPoint.Notes.Add
myNote.Texts.Item(1).Contents = "This is a Note."
注釈のテキストの置換
注釈のテキストを置換するには、
Contents
プロパティを使用します。次のサンプルにその例を示します。 完
全なスクリプトについては、Replace を参照してください。 myInCopy = CreateObject("InCopy.Application.CS6")
myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.Item(1)
Replace text of note with "This is a replaced note."
myNote.Texts.Item(1).Contents = "This is a replaced note."
80
第 8 章 注釈 注釈からテキストへの変換およびテキストから注釈への変換 81
注釈からテキストへの変換およびテキストから注釈への変換
注釈からテキストへの変換
注釈をテキストに変換するには、
ConvertToText
メソッドを使用します。次のサンプルにその例を示します。
完全なスクリプトについては、ConvertToText を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
myNote = myStory.Notes.Item(1)
myNote.convertToText()
テキストから注釈への変換
テキストを注釈に変換するには、
ConvertToNote
メソッドを使用します。次のサンプルにその例を示します。
完全なスクリプトについては、ConvertToNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
myStory.words.Item(1).convertToNote()
注釈の展開と折りたたみ
注釈の折りたたみ
注釈を折りたたむ方法を、次のスクリプトに示します。 完全なスクリプトについては、CollapseNote を参照し
てください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.Item(1)
myNote.Collapsed = True
注釈の展開
注釈を展開する方法を、次のスクリプトに示します。 完全なスクリプトについては、ExpandNote を参照して
ください。 myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.Item(1)
myNote.Collapsed = False
第 8 章 注釈 注釈の削除 82
注釈の削除
注釈を削除するには、
Delete
メソッドを使用します。次のサンプルにその例を示します。 完全なスクリプト
については、RemoveNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.Item(1)
myStory.Notes.Item(1).Delete
注釈間の移動
ストーリー内の最初の注釈への移動
ストーリー内の最初の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
FirstNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.firstItem()
myNote.Texts.Item(1).Contents = "This is the first note."
ストーリー内の次の注釈への移動
ストーリー内の次の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
NextNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.nextItem(myStory.Notes.Item(1))
myNote.Texts.Item(1).Contents = "This is the next note."
ストーリー内の前の注釈への移動
ストーリー内の前の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
PreviousNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.previousItem(myStory.Notes.Item(2))
myNote.Texts.Item(1).Contents = "This is the prev note."
ストーリー内の最後の注釈への移動
ストーリー内の最後の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
LastNote を参照してください。
Set myInCopy = CreateObject("InCopy.Application.CS6")
Set myDocument = myIncopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myNote = myStory.Notes.lastItem()
myNote.Texts.Item(1).Contents = "This is the last note."
9
変更のトラック
章の更新ステータス
CS6
変更なし
原稿作成や編集作業の進行中に、ドキュメントの変更のトラック、表示/非表示、適用、取り消しを実行で
この章では、変更のトラックに関する一般的な操作をスクリプトで実行する方法について説明します。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、InCopy でテキストを操作する方法や、組版に関する基本
的な用語を理解しているものとしています。
変更のトラック
ここでは、スクリプトを使用して、トラックされた変更に移動したり、変更を適用および取り消しする方法
について説明します。
既存のストーリーに含まれているテキストの追加や削除、移動が行われると、その変更がゲラビューおよび
ストーリービューに示されます。
トラックされた変更への移動
トラックされた変更の記録がストーリーに含まれている場合、ユーザーはトラックされた変更に順次移動す
ることができます。 トラックされた変更に移動する方法を、次のスクリプトに示します。
次のスクリプトでは、 nextItem
メソッドを使用して、挿入点の後の変更に移動します。
Set myDocument = myInCopy.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 = myInCopy.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
83
第 9 章 変更のトラック 変更のトラック 84
トラックされた変更の適用と取り消し
ストーリーに対する変更が行われた場合、変更のトラック機能を使用してすべての変更を見直したり、ス
トーリーにすべての変更を組み込むかどうかを決定できます。 ユーザーは、すべてのユーザーが行った変更
(テキストの追加や削除、移動)を適用および取り消しすることができます。
次のスクリプトでは、変更を適用します。
Set myDocument = myInCopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myChange = myStory.Changes.Item(1)
myChange.Accept
次のスクリプトでは、変更を取り消します。
Set myDocument = myInCopy.Documents.Item(1)
Set myStory = myDocument.Stories.Item(1)
Set myChange = myStory.Changes.Item(1)
myChange.Reject
トラックされた変更に関する情報
変更の情報には日付や時間などが含まれています。 次のスクリプトでは、トラックされた変更の情報を表示
します。
Set myDocument = myInCopy.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
第 9 章 変更のトラック 変更のトラックの環境設定 85
変更のトラックの環境設定
変更のトラックの環境設定とは、変更のトラックに関するユーザー設定です。 例えば、トラックされる変更
の種類(テキストの追加や削除、移動)を定義できます。 トラックされた変更の種類別の外観を指定したり、
マージンの色付きの変更バーで変更を識別したりできます。 これらの環境設定を設定して取得する方法を、
次のスクリプトに示します。
Set myTrackChangesPreference = myInCopy.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 for deleted text, or text color for moved text.
Rem idChangeUsesGalleyTextColor,The text color for changed text is the same as the galley text
第 9 章 変更のトラック 変更のトラックの環境設定 86 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.
myShowMovedText = .ShowMovedText
第 9 章 変更のトラック 変更のトラックの環境設定 87
.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
10
アサイン
章の更新ステータス
CS6
変更なし
アサインは、InDesign ファイルに含まれるテキストやグラフィック用のコンテナで、InCopy で表示および編
集できます。 一般的に、アサインには、関連するテキストやグラフィックが含まれます(雑誌の記事を構成
このチュートリアルでは、アサインに関する一般的な操作をスクリプトで実行する方法について説明します。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
アサインオブジェクト
この節では、アサインとアサインファイルを操作する方法について説明します。 スクリプトを使用して、ア
サインファイルを開いてアサインのプロパティを取得できます。
アサインファイルを開く
既存のアサインファイルを開く方法を、次のスクリプトに示します。
Rem Open an exist assignment file
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Open("c:¥a.icma")
Set myAssignement = myDocument.Assignments.Item(1)
アサインのプロパティに対する繰り返し処理
アサインのプロパティ(アサイン名、ユーザー名、アサインファイルの場所、アサインの書き出しオプショ
ンなど)を取得する方法を、次のスクリプトに示します。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
Set myAssignement = myDocument.Assignments.Item(1)
myuserName = myAssignement.UserName
myFilePath = myAssignement.FilePath
myDocPath = myAssignement.DocumentPath
myFramecolor = myAssignement.FrameColor
myincludeLinksWhenPackage = myAssignement.IncludeLinksWhenPackage
Rem Export options for assignment files.
Rem AssignmentExportOptions.ASSIGNED_SPREADS Exports only spreads with assigned frames
Rem AssignmentExportOptions.EMPTY_FRAMES Exports frames but does not export content
Rem AssignmentExportOptions.EVERYTHING Exports the entire document.
myExportOptions = myAssignement.ExportOptions
88
第 10 章 アサイン アサインのストーリー 89
アサインパッケージ
アサインパッケージ(InCopy で作成した .
incp
ファイル)は、アサインファイルが含まれた圧縮フォルダー
です。 createPackage
メソッドを使用すると、アサインをパッケージ化することができます。
クリプトでは、この方法でパッケージファイルを作成しています。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
Set myAssignement = myDocument.Assignments.Item(1)
If myAssignement.Packaged = False Then
Rem idPackageType.idForwardPackage Creates an assignment package for export.
Rem idPackageType.idReturnPackage Create a package to place in the main document.
myAssignement.CreatePackage("c:¥b.icap",idPackageType.idForwardPackage)
End If
アサインのストーリー
次の図に、InCopy のアサインオブジェクトモデルを示します。 アサインドキュメントには、1 つ以上のアサ
インが含まれます。アサインには、アサインされたストーリーが含まれないか、または 1 つ以上のアサイン
されたストーリーが含まれます。 アサインされた各ストーリーは、テキストストーリーまたは画像ストー
リーを参照します。
document
1
1…* assignment
1
0…* assigned story
1 text/image story
1
この節では、アサインされたストーリーとアサインストーリーのプロパティを取得する方法について説明し
ます。
アサインされたストーリーオブジェクト
アサインオブジェクトから、アサインされたストーリーを取得する方法を、次のスクリプトに示します。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
Set myAssignement = myDocument.Assignments.Item(1)
Set myAssignmentStory = myAssignement.AssignedStories.item(1)
アサインされたストーリーのプロパティに対する繰り返し処理
オブジェクトのすべてのプロパティを取得する方法を、次のスクリプトに示します。
第 10 章 アサイン
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
Set myAssignement = myDocument.Assignments.Item(1)
Set myAssignmentStory = myAssignement.AssignedStories.item(1)
myName = myAssignmentStory.Name
myFilePath = myAssignmentStory.FilePath
Set myStoryReference = myAssignmentStory.StoryReference
アサインのストーリー 90
11
XML
章の更新ステータス
CS6
変更なし
XML(Extensible Markup Language)は、World Wide Web Consortium( www.w3.org
)で作成と管理が行われて
いる、テキストベースのマークアップシステムです。 XML では、HTML(Hypertext Markup Language)と同じ
ように、不等号記号で囲まれたマークアップタグ(
<article>
や
<para>
など)が使用されます。
使用できるタグが事前に定義されていますが、XML では独自のタグを作成して、ドキュメントの構造をより
詳細に記述することができます。
高い柔軟性を備えている XML は、データの保存形式として広く利用されています。 InCopy には、XML データ
をページレイアウトに読み込むための様々な機能が用意されていますが、それらはスクリプトを使用して制
御できます。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、XML、DTD、XSLT に関する基礎知識を持っていることを前
提としています。
概要
XML はフォーマットを行うためのものではなく、ドキュメントの構造を記述するためのものです。したがっ
て、ページレイアウト作業で XML を活用するには、やや複雑な手順が必要になります。 InCopy は、XML に完
全かつ柔軟に対応できますが、次のような制約があります。
によって表現された XML 要素は、元の XML 要素とは異なります。
い場合は、XML 要素そのものを複製する必要があります。
XML 要素のレイアウト上での出現順序は、XML 構造での出現順序とほぼ同じになります。
XML 要素に関連付けられているストーリー内のテキストは、その要素のデータになります。
InCopy での XML スクリプティングの推奨事項
XML ファイルの処理は、InCopy の外部で(InCopy のレイアウトに XML ファイルを読み込む前に)そのほと
んどを行うのが一般的です。 InCopy の外部では、XML エディターや XML パーサーなどの様々な便利なツール
が利用できます。
大規模な XML データ構造に含まれている要素を再配置したり複製したりする場合は、XSLT を使用して XML
を変換することを推奨します。 これは、XML ファイルを読み込むときに実行できます。
XML 要素のスクリプティング
ここでは、XML 環境設定や XML 読み込み環境設定の指定、XML の読み込み、XML 要素の作成、XML 属性の追
加を行う方法について説明します。 ここでは、XML コンテンツ自体を操作するスクリプトについて説明しま
91
第 11 章 XML
XML 要素のスクリプティング 92
す。XML 要素にフォーマットを適用するスクリプトについては、
を参照してください。
XML 環境設定の指定
XML ビュー環境設定オブジェクトを使用して、InCopy の構造パネルの外観を制御できます。次のスクリプト
にその例を示します(チュートリアルスクリプトの 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"))
XML の読み込み
XML 読み込み環境設定を指定したら、XML ファイルを読み込みます。次のスクリプトにその例を示します
(チュートリアルスクリプトの ImportXML より)。
第 11 章 XML
XML 要素のスクリプティング 93 myDocument.ImportXML("c:¥completeDocument.xml")
XML ファイルの内容を特定の XML 要素に読み込む必要がある場合は、ドキュメントではなく XML 要素の
Set myXMLTag = myDocument.XMLTags.Add("xml_element")
Set myRootXMLElement = myDocument.XMLElements.Item(1)
set myMXLElement = myRootElement.XMLElements.Add(myXMLTag)
myRootXMLElement.ImportXML "c:¥completeDocument.xml"
または、
XMLImportPreferences
オブジェクトの
ImportToSelected
プロパティを true に設定し、XML 要素を
選択した状態で XML ファイルを読み込む方法もあります。次のスクリプトにその例を示します(チュートリ
アルスクリプトの ImportXMLIntoSelectedXMLElement より)。
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"
XML タグの作成
の要素名が、ドキュメントの XML タグのリストに追加されます。 また、XML タグを直接作成することもでき
ます。次のスクリプトにその例を示します(チュートリアルスクリプトの MakeXMLTags より)。
Rem You can create an XML tag without specifying a color for the tag.
Set myXMLTagA = myDocument.XMLTags.Add("XML_tag_A")
Rem You can define the highlight color of the XML tag using the UIColors enumeration...
Set myXMLTagB = myDocument.XMLTags.Add("XML_tag_B", UIColors.Gray)
Rem ...or you can provide an RGB array to set the color of the tag.
Set myXMLTagC = myDocument.XMLTags.Add("XML_tag_C", Array(0, 92, 128))
XML タグのロード
XML データを読み込む前にタグとスタイルのマッピングを行いたい場合に便利です。次のスクリプトにその
例を示します(チュートリアルスクリプトの LoadXMLTags より)。 myDocument.LoadTags("c:¥test.xml")
XML タグの保存
ファイルから XML タグをロードするのとは逆に、XML タグをファイルに保存することもできます。 これを行
うと、タグだけが XML ファイルに保存されます。ドキュメントデータは保存されません。 この処理は、XML
を書き出すより高速で、生成されるファイルも小さくなります。 XML タグを保存する方法を、次のサンプル
スクリプトに示します(完全なスクリプトについては、SaveXMLTags を参照してください)。 myDocument.SaveXMLTags("c:¥xml_tags.xml", "Tag set created October 5, 2006")
第 11 章 XML
XML 要素のスクリプティング 94
XML 要素の作成
通常、XML 要素は XML ファイルを読み込んで作成しますが、InCopy スクリプティングを使用して XML 要素
を作成することもできます。次のスクリプトにその例を示します(チュートリアルスクリプトの
Set myXMLTag = myDocument.XMLTags.Add("myXMLTag")
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElement = myRootElement.XMLElements.Add(myXMLTag)
myXMLElement.Contents = "This is an XML element containing text."
XML 要素の移動
move
メソッドを使用して、XML 構造内の XML 要素を移動できます。次のスクリプトにその例を示します
(チュートリアルスクリプトの MoveXMLElement より)。
Set myDocument = myInCopy.Documents.Add
Set myXMLTag = myDocument.XMLTags.Add("myXMLTag")
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElementA = myRootElement.XMLElements.Add(myXMLTag)
myXMLElementA.Contents = "This is XML element A."
Set myXMLElementB = myRootElement.XMLElements.Add(myXMLTag)
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 myDocument = myInCopy.Documents.Add
Set myXMLTag = myDocument.XMLTags.Add("myXMLTag")
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElementA = myRootElement.XMLElements.Add(myXMLTag)
myXMLElementA.Contents = "This is XML element A."
Set myXMLElementB = myRootElement.XMLElements.Add(myXMLTag)
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(-2)
myXMLElement.Untag
第 11 章 XML
XML 要素のスクリプティング 95
XML コメントの作成
のスクリプトに示します(チュートリアルスクリプトの MakeXMLComment より)。
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElement = myRootElement.XMLElements.Add(myXMLTag)
Set myXMLComment = myXMLElement.XMLComments.Add("This is an XML comment.")
XML 処理命令の作成
処理命令(PI:Processing Instruction)とは、XML ドキュメントを読み込むアプリケーションに対する命令が
含まれている XML 要素のことです。 XML 処理命令は、InCopy では無視されますが、他のアプリケーションで
使用するために InCopy の XML 構造に挿入することができます。 XML ドキュメントには複数の処理命令を含め
ることができます。
<?xml-stylesheet type="text/css" href="generic.css"?>
XML 処理命令を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
Set myRootXMLElement = myDocument.XMLElements.Item(1)
myRootXMLElement.XMLInstructions.Add "xml-stylesheet type=""text/css""", "href=""generic.css"""
XML 属性の操作
次のスクリプトに示します。 XML 要素には任意の数の XML 属性を追加できますが、各属性の名前はその要素
内で固有のものであることが必要です(例えば、「id」という名前の属性を 2 つ使用することはできません)。
XML 要素に XML 属性を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
Set myDocument = myInCopy.Documents.Add
Set myXMLTag = myDocument.XMLTags.Add("myXMLElement")
Set myRootElement = myDocument.XMLElements.Item(1)
Set myXMLElement = myRootElement.XMLElements.Add(myXMLTag)
Set myXMLAttribure = myXMLElement.XMLAttributes.Add("example_attribute", "This is an XML attribute.")
スクリプトを使用して属性を直接作成する以外に、XML 要素を変換して属性を作成することもできます。 こ
れを行うと、XML 要素のテキスト内容が XML 属性の値として使用され、XML 要素の親に追加されます。 XML
要素の名前が属性の名前になるので、同じ名前を持つ属性が XML 要素の親に既に存在している場合は、作成
に失敗します。 XML 要素にページアイテムが含まれている場合、それらのページアイテムはレイアウトから
削除されます。
は、XML 属性の親の先頭または末尾に追加できます。 デフォルトでは、親要素の先頭に追加されます。
新しい XML 要素に XML マークアップタグを指定することもできます。 このパラメーターを省略すると、その
XML 属性が含まれている XML 要素と同じ XML タグを使用して新しい XML 要素が作成されます。
XML 要素を XML 属性に変換する方法を、次のスクリプトに示します(完全なスクリプトについては、
第 11 章 XML ストーリーへの XML 要素の追加 96
Set myXMLTag = myDocument.XMLTags.Add("myXMLElement")
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myXMLElement = myRootXMLElement.XMLElements.Add(myXMLTag)
Set myTargetXMLElement = myXMLElement.XMLElements.Add(myXMLTag)
myTargetXMLElement.Contents = "This is content in an XML element."
myTargetXMLElement.ConvertToAttribute
XML 属性を XML 要素に変換することもできます。次のスクリプトにその例を示します(チュートリアルスク
リプトの ConvertAttributeToElement より)。
Set myXMLTag = myDocument.XMLTags.Add("myXMLElement")
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myXMLElement = myRootXMLElement.XMLElements.Add(myXMLTag)
Set myXMLattribute = myXMLElement.XMLAttributes.Add("xml_attribute", "This is content in an XML attribute.")
myXMLAttribute.ConvertToElement idXMLElementLocation.idElementEnd, myXMLTag
XML ストーリーの操作
レイアウト要素(ストーリーまたはページアイテム)に関連付けられていない XML 要素を読み込むと、その
要素は XML ストーリーに格納されます。 テキストフレーム内のテキストと同じように、配置されていない
については、XMLStory を参照してください)。
Set myXMLStory = myDocument.XmlStories.Item(1)
Rem Though the text has not yet been placed in the layout, all text
Rem properties are available.
myXMLStory.Texts.Item(1).PointSize = 72
Rem Place the Root XML element in the default story so that
Rem you can see the result in the Structure panel.
myDocument.Stories.Item(1).PlaceXML myRootXMLElement
XML の書き出し
InCopy ドキュメントから XML を書き出す方法としては、ドキュメント内の XML 構造全体を書き出す方法と、
プトにその例を示します(完全なスクリプトについては、ExportXML を参照してください)。 myDocument.Export "XML", "c:¥test.xml"
ストーリーへの XML 要素の追加
これまでの節では、XML データを InCopy ドキュメントに読み込んで、ドキュメント内の XML 構造を操作す
る方法について説明しました。 この節では、XML 情報をストーリーに読み込んでフォーマットを行う方法に
ついて説明します。
XML 要素とテキストとの関連付け
テキストに既存の XML 要素を関連付けるには、
PlaceXML
メソッドを使用します。
と、ページアイテムの内容が XML 要素の内容に置き換わります。次のスクリプトにその例を示します
(チュートリアルスクリプトの PlaceXML より)。 myDocument.Stories.Item(1).PlaceXML(myXMLElements.Item(0)
既存のテキストオブジェクトに既存の XML 要素を関連付けるには、 markup
メソッドを使用します。
ソッドを使用すると、テキストオブジェクトの内容と XML 要素の内容(存在する場合)が結合されます。 markup
メソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについては、Markup を
参照してください)。
第 11 章 XML ストーリーへの XML 要素の追加 97
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myStory = myDocument.Stories.Item(1)
Rem Place the Root XML element in the default story.
myStory.PlaceXML myRootXMLElement
myString = "This is the first paragraph in the story." & vbCr
myString = myString & "This is the second paragraph in the story." & vbCr
myString = myString & "This is the third paragraph the story." & vbCr
myString = myString & "This is the fourth paragraph in the story." & vbCr
myStory.Contents = myString
Set myXMLTag = myDocument.XMLTags.Add("myXMLElement")
Set myXMLElement = myRootXMLElement.XMLElements.Add(myXMLTag)
Rem Mark up one of the paragraphs with another XML element.
myDocument.Stories.Item(1).Paragraphs.Item(3).Markup myXMLElement
XML テキスト要素の内部や周囲へのテキストの挿入
や「住所」などのラベル)を XML 要素のテキストに追加したいことがあります。 XML 要素の内部や周囲にテ
キストを追加する方法を、次のサンプルスクリプトに示します(完全なスクリプトについては、
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,
Rem 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) "
スタイルへのタグのマッピング
XML テキスト要素にフォーマットを適用する最も簡単な方法の 1 つが、
XMLImportMaps
を使用してタグをス
タイルにマッピングする方法です。 この方法では、特定の XML タグを段落スタイルや文字スタイルに関連付
けることができます。 ドキュメントの
MapTagsToStyles
メソッドを使用すると、テキストにスタイルが適用
されます。次のスクリプトにその例を示します(チュートリアルスクリプトの MapTagsToStyles より)。
第 11 章 XML ストーリーへの XML 要素の追加 98
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.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 XML tag to style mapping.
myDocument.MapXMLTagsToStyles
タグへのスタイルのマッピング
XML 要素が関連付けられていないフォーマットされたテキストを XML 構造に移動したい場合は、スタイルを
タグにマッピングします。これによって、段落スタイルや文字スタイルを XML タグに関連付けることができ
ます。 これを行うには、
XMLExportMaps
オブジェクトを使用して、XML タグとスタイルの間にリンクを作成
し、
MapStylesToTags
メソッドを使用して該当する XML 要素を作成します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの MapStylesToTags より)。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.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 tag to style mapping.
myDocument.MapStylesToXMLTags
別の方法としては、単純に、ドキュメント内のすべての段落スタイルや文字スタイルに対して新しい XML タ
グを作成して、スタイルをタグにマッピングする方法があります。次のスクリプトにその例を示します
(チュートリアルスクリプトの MapAllStylesToTags より)。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
Rem Create tags that match the style names in the document,
Rem creating an XMLExportMap for each tag/style pair.
For 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 要素へのスタイルの適用
タグとスタイルをマッピングしたり、XML 要素が関連付けられているテキストやページアイテムにスタイル
を適用したりする以外に、XML 要素にスタイルを直接適用することもできます。
ApplyParagraphStyle
およ
び
ApplyCharacterStyle
メソッドを使用する方法を、次のスクリプトに示します (完全なスクリプトについ
ては、ApplyStylesToXMLElements を参照してください)。
第 11 章 XML ストーリーへの XML 要素の追加 99
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1)
Rem Add XML elements.
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myXMLElementA = myRootXMLElement.XMLElements.Add(myDocument.XMLTags.Item("heading_1"))
myXMLElementA.Contents = "Heading 1"
myXMLElementA.ApplyParagraphStyle myDocument.ParagraphStyles.Item("heading 1"), True
myXMLElementA.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElementB = myRootXMLElement.XMLElements.Add(myDocument.XMLTags.Item("para_1"))
myXMLElementB.Contents = "This is the first paragraph in the article."
myXMLElementB.ApplyParagraphStyle myDocument.ParagraphStyles.Item("para 1"), True
myXMLElementB.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElementC = myRootXMLElement.XMLElements.Add(myDocument.XMLTags.Item("body_text"))
myXMLElementC.Contents = "This is the second paragraph in the article."
myXMLElementC.ApplyParagraphStyle myDocument.ParagraphStyles.Item("body text"), True
myXMLElementC.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElementD = myRootXMLElement.XMLElements.Add(myDocument.XMLTags.Item("heading_2"))
myXMLElementD.Contents = "Heading 2"
myXMLElementD.ApplyParagraphStyle myDocument.ParagraphStyles.Item("heading 2"), True
myXMLElementD.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElementE = myRootXMLElement.XMLElements.Add(myDocument.XMLTags.Item("para_1"))
myXMLElementE.Contents = "This is the first paragraph following the subhead."
myXMLElementE.ApplyParagraphStyle myDocument.ParagraphStyles.Item("para 1"), True
myXMLElementE.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElementF = myRootXMLElement.XMLElements.Add(myDocument.XMLTags.Item("body_text"))
myXMLElementF.Contents = "This is the second paragraph following the subhead."
myXMLElementF.ApplyParagraphStyle myDocument.ParagraphStyles.Item("body text"), True
myXMLElementF.InsertTextAsContent vbCr, idXMLElementPosition.idAfterElement
Set myXMLElementG = myXMLElementF.XMLElements.Add(myDocument.XMLTags.Item("body_text"))
myXMLElementG.Contents = "Note:"
Set myXMLElementG = myXMLElementG.Move(idLocationOptions.idAtBeginning, myXMLElementF)
myXMLElementG.InsertTextAsContent " ", idXMLElementPosition.idAfterElement
myXMLElementG.ApplyCharacterStyle myDocument.CharacterStyles.Item("Emphasis"), True
Set myStory = myDocument.Stories.Item(1)
Rem Associate the root XML element with the story.
myRootXMLElement.PlaceXML myStory
XML 表の操作
HTML 標準の表タグでデータがマークアップされている場合、InCopy はその XML データを自動的に表セルに
読み込みます。 デフォルトの表マークアップを使用できないか、使用を避けたい場合は、
ConvertElementToTable
メソッドを使用して XML 要素を表に変換できます。
このメソッドを使用するには、表に変換する XML 要素が特定の構造になっている必要があります。 表の各行
が特定の XML 要素に対応しており、その要素の中に、行内の各セルに対応する一連の XML 要素が含まれてい
る必要があります。 このメソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについ
ては、ConvertXMLElementToTable を参照してください)。 テーブル行を表すために使用されている XML 要素
は、このプロセスによって変換されます。
第 11 章 XML ストーリーへの XML 要素の追加 100
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
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)
myString = "Row " & CStr(myRowCounter)
For myCellCounter = 1 To 4
With .XMLElements.Add(myCellTag)
Next
End With
.Contents = myString & ":Cell " & CStr(myCellCounter)
End With
Next
End With
End With
Set myTable = myTableXMLElement.ConvertElementToTable(myRowTag, myCellTag)
Set myStory = myDocument.Stories.Item(1)
myStory.PlaceXML myDocument.XMLElements.Item(1)
XML 要素で構成されている表では、XML 要素に関連付けられている表やセルにスタイルを適用するのではな
く、XML 要素に表スタイルやセルスタイルを直接適用することができます。 これを行うには、 applyTableStyle
メソッドや applyCellStyle
メソッドを使用します。次のスクリプトにその例を示します
(チュートリアルスクリプトの ApplyTableStyle より)。
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Add
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.StartRowFillColor = myDocument.Colors.Item("Black")
myTableStyle.StartRowFillTint = 25
myTableStyle.EndRowFillColor = myDocument.Colors.Item("Black")
myTableStyle.EndRowFillTint = 10
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)
myString = "Row " + CStr(myRowCounter)
For myCellCounter = 1 To 4
With .XMLElements.Add(myCellTag)
.Contents = myString & ":Cell " + CStr(myCellCounter)
End With
Next
第 11 章 XML ストーリーへの XML 要素の追加 101
End With
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.Stories.Item(1).PlaceXML myDocument.XMLElements.Item(1)
myTable.AlternatingFills = idAlternatingFillsTypes.idAlternatingRows
İndir
Reklam