diff --git a/CHANGELOG.md b/CHANGELOG.md index 50bfef5..ed18fbf 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,16 @@

+## checkDayOfWeek.js +### 1.1.0 (2024-06-30) +### Added +- Japanese calendar is now supported. +- Added the function to check the illustrator version. +### Changes +- Updated the UI. +

+ + ## closeAllDocuments.js ### 1.1.0 (2023-08-27) ### Changes @@ -70,6 +80,9 @@ ## compareScale.js +### 1.1.0 (2024-06-30) +### Changes +- Changed the UI to show scale for each object. ### 1.0.1 (2023-08-27) ### Changes - Changed localization method. @@ -325,6 +338,12 @@ ## measureDistance.js +### 1.3.0 (2024-06-30) +### Added +- Added supported units. +### Changes +- To avoid crashing Illustrator, labels are no longer displayed in Illustrator 2020 and earlier versions. +- Updated the UI. ### 1.2.0 (2023-08-27) ### Added - Labels are now displayed at anchor points. @@ -498,6 +517,12 @@

+## sumNumbers.js +### 2.0.0 (2024-06-30) +### Changes +- Changed the UI to allow editing of numeric values in text fields. + + ## syncView.js ### 1.0.1 (2024-04-06) ### Added diff --git a/README.md b/README.md index 2c2ade1..c3c0fde 100755 --- a/README.md +++ b/README.md @@ -55,37 +55,37 @@ If you find a script that interests you, please download it from [![Download](ht ### Path [![Download Path.zip](https://img.shields.io/badge/Download-Path.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Path.zip) -- [Add Anchor Points](#addAnchorPointsjs) `Update` -- [Align in Center of Space (Horizontal)](#alignInCenterOfSpaceHorizontaljsalignInCenterOfSpaceVerticaljs) `Update` -- [Align in Center of Space (Vertical)](#alignInCenterOfSpaceHorizontaljsalignInCenterOfSpaceVerticaljs) `Update` -- [Align Objects](#alignObjectsjs) `Update` +- [Add Anchor Points](#addAnchorPointsjs) +- [Align in Center of Space (Horizontal)](#alignInCenterOfSpaceHorizontaljsalignInCenterOfSpaceVerticaljs) +- [Align in Center of Space (Vertical)](#alignInCenterOfSpaceHorizontaljsalignInCenterOfSpaceVerticaljs) +- [Align Objects](#alignObjectsjs) - [Close Path](#closePathjs) -- [Convert All Anchor Points to Corner](#convertAllAnchorPointsToCornerjs) `Update` +- [Convert All Anchor Points to Corner](#convertAllAnchorPointsToCornerjs) - [Create Grid Lines](#createGridLinesjs) - [Decrease Selected Anchor Points Clockwise](#decreaseSelectedAnchorPointsCWjsdecreaseSelectedAnchorPointsCCWjs) - [Decrease Selected Anchor Points Counterclockwise](#decreaseSelectedAnchorPointsCWjsdecreaseSelectedAnchorPointsCCWjs) - [Disjoin Path](#disjoinPathjs) -- [Distribute in Space (Horizontal)](#distributeInSpaceHorizontaljsdistributeInSpaceVerticaljs) `Update` -- [Distribute in Space (Vertical)](#distributeInSpaceHorizontaljsdistributeInSpaceVerticaljs) `Update` +- [Distribute in Space (Horizontal)](#distributeInSpaceHorizontaljsdistributeInSpaceVerticaljs) +- [Distribute in Space (Vertical)](#distributeInSpaceHorizontaljsdistributeInSpaceVerticaljs) - [Draw Circumscribed Circle](#drawCircumscribedCirclejs) -- [Draw Normal Line](#drawNormalLinejs) `New` -- [Draw Rectangle](#drawRectanglejs) `Update` -- [Draw Shape on Anchor Point](#drawShapeOnAnchorPointjs) `Update` -- [Draw Shape Parallel to Path Segment](#drawShapeParallelToPathSegmentjs) `New` -- [Extend Handle](#extendHandlejs) `Update` -- [Extend Line](#extendLinejs) `Update` +- [Draw Normal Line](#drawNormalLinejs) +- [Draw Rectangle](#drawRectanglejs) +- [Draw Shape on Anchor Point](#drawShapeOnAnchorPointjs) +- [Draw Shape Parallel to Path Segment](#drawShapeParallelToPathSegmentjs) +- [Extend Handle](#extendHandlejs) +- [Extend Line](#extendLinejs) - [Fit Guide in Artboard](#fitGuideInArtboardjs) - [Increase Selected Anchor Points Clockwise](#increaseSelectedAnchorPointsCWjsincreaseSelectedAnchorPointsCCWjs) - [Increase Selected Anchor Points Counterclockwise](#increaseSelectedAnchorPointsCWjsincreaseSelectedAnchorPointsCCWjs) - [Move Guides](#moveGuidesjs) -- [Rearrange Objects](#rearrangeObjectsjs) `Update` +- [Rearrange Objects](#rearrangeObjectsjs) - [Remove Color in Guide Object](#removeColorInGuideObjectjs) - [Select Guides](#selectGuidesjs) - [Shift Selected Anchor Points Clockwise](#shiftSelectedAnchorPointsCWjsshiftSelectedAnchorPointsCCWjs) - [Shift Selected Anchor Points Counterclockwise](#shiftSelectedAnchorPointsCWjsshiftSelectedAnchorPointsCCWjs) -- [Show Dimensions](#showDimensionsjs) `Update` +- [Show Dimensions](#showDimensionsjs) - [Shuffle Objects](#shuffleObjectsjs) -- [Step and Repeat](#stepAndRepeatjs) `Update` +- [Step and Repeat](#stepAndRepeatjs) ### Text [![Download Text.zip](https://img.shields.io/badge/Download-Text.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Text.zip) @@ -95,7 +95,7 @@ If you find a script that interests you, please download it from [![Download](ht - [Copy Line Up](#copyLineDownjscopyLineUpjs) - [Copy Line (empty selection)](#copyLineEmptySelectionjscutLineEmptySelectionjs) - [Create Page Numbers](#createPageNumbersjs) -- [Create Text Parallel to Path Segment](#createTextParallelToPathSegmentjs) `Update` +- [Create Text Parallel to Path Segment](#createTextParallelToPathSegmentjs) - [Create Threaded Text](#createThreadedTextjs) - [Cut Line (empty selection)](#copyLineEmptySelectionjscutLineEmptySelectionjs) - [Delete All Left](#deleteAllLeftjsdeleteAllRightjs) @@ -121,18 +121,20 @@ If you find a script that interests you, please download it from [![Download](ht ### Utility [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) -- [Check Day of Week](#checkDayOfWeekjs) +- [Check Day of Week](#checkDayOfWeekjs) `Update` - [Close All Documents](#closeAllDocumentsjs) -- [Compare Scale](#compareScalejs) -- [Measure Distance](#measureDistancejs) -- [Sum Numbers](#sumNumbersjs) +- [Compare Scale](#compareScalejs) `Update` +- [Measure Distance](#measureDistancejs) `Update` +- [Sum Numbers](#sumNumbersjs) `Update` - [Toggle Align to Glyph Bounds](#toggleAlignToGlyphBoundsjs) - [Toggle Paste Remembers Layers](#togglePasteRemembersLayersjs) - [Toggle Show Handles](#toggleShowHandlesjs) +- [Unit Calculator](#unitCalculatorjs) `New` ### View [![Download View.zip](https://img.shields.io/badge/Download-View.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/View.zip) - [Arrange Windows](#arrangeWindowsjs) +- [Fit Selected Objects in Window](#fitSelectedObjectsInWindowjs) `New` - [Navigate to First Artboard](#navigateToFirstArtboardjsnavigateToLastArtboardjsnavigateToNextArtboardjsnavigateToPreviousArtboardjs) - [Navigate to Last Artboard](#navigateToFirstArtboardjsnavigateToLastArtboardjsnavigateToNextArtboardjsnavigateToPreviousArtboardjs) - [Navigate to Next Artboard](#navigateToFirstArtboardjsnavigateToLastArtboardjsnavigateToNextArtboardjsnavigateToPreviousArtboardjs) @@ -335,21 +337,20 @@ This script checks the day of the week. ![Check Day Of Week](images/checkDayOfWeek.png) ### Usage -Select a date with the cursor, and run this script. +Select a date section in the text with the cursor, and run this script. > [!NOTE] -> If there is no year, it is considered as this year. -> If the date is incorrect, a warning is issued. -> The following formats are supported. +> If there is no year, it will considered as this year. -> **Format** -> `YYYY/MM/DD`, `MM/DD/YYYY`, `DD/MM/YYYY`, -> `YYYY-MM-DD`, `MM-DD-YYYY`, `DD-MM-YYYY`, -> `YYYY.MM.DD`, `MM.DD.YYYY`, `DD.MM.YYYY`, -> `YYYY MM DD`, -> `YYYY年MM月DD日`, -> `Jan(uary) (the) DD(st|nd|rd|th)(,) YYYY`, `MM DD(st|nd|rd|th)(,) YYYY`, -> `DD(st|nd|rd|th) (of) Jan(uary)(,) YYYY`, `DD(st|nd|rd|th) MM(,) YYYY` +### Format +The following formats are supported. +`YYYY/MM/DD`, `MM/DD/YYYY`, `DD/MM/YYYY`, +`YYYY-MM-DD`, `MM-DD-YYYY`, `DD-MM-YYYY`, +`YYYY.MM.DD`, `MM.DD.YYYY`, `DD.MM.YYYY`, +`YYYY MM DD`, `MM DD YYYY`, `DD MM YYYY`, +`Jan(uary) (the) DD(st|nd|rd|th)(,) YYYY`, `MM DD(st|nd|rd|th)(,) YYYY`, +`DD(st|nd|rd|th) (of) Jan(uary)(,) YYYY`, `DD(st|nd|rd|th) MM(,) YYYY`, +`YYYY年MM月DD日`, `令和YY年MM月DD日`, `平成YY年MM月DD日`, `昭和YY年MM月DD日`, `大正YY年MM月DD日`, `明治YY年MM月DD日` ### Requirements Illustrator CS4 or higher @@ -407,10 +408,12 @@ This script compares the scales of two objects. ![Compare Scale](images/compareScale.png) ### Usage -Select two objects, and run this script. +1. Select two objects, and run this script. +2. To include stroke width, check the Use Preview Bounds checkbox. -> [!NOTE] -> The dimension units depend on the ruler units. +### Support units +Point, Pixel, Pica, Inch, Feet, Yard, Millimeter, Centimeter, Meter. +These units depend on the ruler units. ### Requirements Illustrator CS4 or higher @@ -1267,6 +1270,28 @@ Illustrator CS or higher +# fitSelectedObjectsInWindow.js +[![Download View.zip](https://img.shields.io/badge/Download-View.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/View.zip) +This script changes the zoom factor that the selected object fills the display. + +![Fit Selected Objects In Window](images/fitSelectedObjectsInWindow.png) + +### Usage +Select any objects, and run this script. + +> [!NOTE] +> If no objects are selected, all objects should fit in the window. Ignore guides. + +### Requirements +Illustrator CS or higher + +
[ ↑ Back to Top ↑ ]
+
+ + + + + # generateGradientColor.js [![Download Color.zip](https://img.shields.io/badge/Download-Color.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Color.zip) This script generates the gradient color from fill colors or swatches. @@ -1576,10 +1601,13 @@ Select two anchor points with Direct Selection Tool, and run this script. > [!NOTE] > Highlight the measurement points. > The angle is based on point #1. Range: -180.0 to 180.0 -> The dimension units depend on the ruler units. > Anchor points for type on a path and area type are also supported. > Due to the small font size, labels will not appear when enlarged above 15500%. +### Support units +Point, Pixel, Pica, Inch, Feet, Yard, Millimeter, Centimeter, Meter. +These units depend on the ruler units. + ### Requirements Illustrator CS4 or higher @@ -2328,17 +2356,16 @@ Illustrator CS4 or higher # sumNumbers.js [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) -This script sums the numbers in text contents. +This script adds up the numbers in the text. ![Sum Numbers](images/sumNumbers.png) ### Usage -Select text objects, and run this script. -You can also recalculate using only selected items from the list. +Select text objects or specify a text range in an editing state, and run this script. +You can also edit numbers in the text field and recalculate the totals. > [!NOTE] -> Ignore the units of value. -> Only one-byte numbers are supported. +> Editing numbers in the text field does not affect the original text objects. ### Requirements Illustrator CS4 or higher @@ -2490,6 +2517,34 @@ Illustrator CS or higher +# unitCalculator.js +[![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) +This script converts almost all units supported by Illustrator. + +Unit Calculator + +### Usage +1. Run this script. + If you want to refer to an object's width or height value, select any objects with the Selection Tool and then run this script. +2. Enter a value in one of the units. + +> [!NOTE] +> If the document is open, the ruler unit is the reference. + +### Support units +Point, Pixel, Pica, Inch, Feet, Yard, Millimeter, Centimeter, Meter. +These units depend on the ruler units. + +### Requirements +Illustrator CC or higher + +
[ ↑ Back to Top ↑ ]
+
+ + + + + # License All scripts are licensed under the MIT license. See the included LICENSE file for more details. diff --git a/README_ja.md b/README_ja.md index 1e0119e..b137984 100755 --- a/README_ja.md +++ b/README_ja.md @@ -53,37 +53,37 @@ Adobe Illustratorのスクリプト集です。 ### パス [![Download Path.zip](https://img.shields.io/badge/Download-Path.zip-e60012?style=for-the-badge)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Path.zip) -- [**アンカーポイントに図形を描く**](#アンカーポイントに図形を描く) drawShapeOnAnchorPoint.js `Update` -- [**アンカーポイントの追加**](#アンカーポイントの追加) addAnchorPoints.js `Update` -- [**オブジェクトの周囲に長方形を描く**](#オブジェクトの周囲に長方形を描く) drawRectangle.js `Update` -- [**オブジェクトの整列**](#オブジェクトの整列) alignObjects.js `Update` -- [**オブジェクトの並べ替え**](#オブジェクトの並べ替え) rearrangeObjects.js `Update` +- [**アンカーポイントに図形を描く**](#アンカーポイントに図形を描く) drawShapeOnAnchorPoint.js +- [**アンカーポイントの追加**](#アンカーポイントの追加) addAnchorPoints.js +- [**オブジェクトの周囲に長方形を描く**](#オブジェクトの周囲に長方形を描く) drawRectangle.js +- [**オブジェクトの整列**](#オブジェクトの整列) alignObjects.js +- [**オブジェクトの並べ替え**](#オブジェクトの並べ替え) rearrangeObjects.js - [**オブジェクトをシャッフル**](#オブジェクトをシャッフル) shuffleObjects.js - [**外接円を描く**](#外接円を描く) drawCircumscribedCircle.js - [**ガイドオブジェクトの色を削除**](#ガイドオブジェクトの色を削除) removeColorInGuideObject.js - [**ガイドをアートボードにフィット**](#ガイドをアートボードにフィット) fitGuideInArtboard.js - [**ガイドを移動**](#ガイドを移動) moveGuides.js - [**ガイドを選択**](#ガイドを選択) selectGuides.js -- [**繰り返し複製**](#繰り返し複製) stepAndRepeat.js `Update` +- [**繰り返し複製**](#繰り返し複製) stepAndRepeat.js - [**グリッドラインを作成**](#グリッドラインを作成) createGridLines.js -- [**すべてのアンカーをコーナーポイントに切り替え**](#すべてのアンカーをコーナーポイントに切り替え) convertAllAnchorPointsToCorner.js `Update` +- [**すべてのアンカーをコーナーポイントに切り替え**](#すべてのアンカーをコーナーポイントに切り替え) convertAllAnchorPointsToCorner.js - [**選択したアンカーポイントを時計回りに移動**](#選択したアンカーポイントを時計回りに移動選択したアンカーポイントを反時計回りに移動) shiftSelectedAnchorPointsCW.js - [**選択したアンカーポイントを反時計回りに移動**](#選択したアンカーポイントを時計回りに移動選択したアンカーポイントを反時計回りに移動) shiftSelectedAnchorPointsCCW.js - [**選択したアンカーポイントを時計回りに増やす**](#選択したアンカーポイントを時計回りに増やす選択したアンカーポイントを反時計回りに増やす) increaseSelectedAnchorPointsCW.js - [**選択したアンカーポイントを反時計回りに増やす**](#選択したアンカーポイントを時計回りに増やす選択したアンカーポイントを反時計回りに増やす) increaseSelectedAnchorPointsCCW.js - [**選択したアンカーポイントを時計回りに減らす**](#選択したアンカーポイントを時計回りに減らす選択したアンカーポイントを反時計回りに減らす) decreaseSelectedAnchorPointsCW.js - [**選択したアンカーポイントを反時計回りに減らす**](#選択したアンカーポイントを時計回りに減らす選択したアンカーポイントを反時計回りに減らす) decreaseSelectedAnchorPointsCCW.js -- [**直線に平行な図形を描く**](#直線に平行な図形を描く) drawShapeParallelToPathSegment.js `New` -- [**ハンドルを伸縮**](#ハンドルを伸縮) extendHandle.js `Update` -- [**パスの寸法を表示**](#パスの寸法を表示) showDimensions.js `Update` -- [**パスを伸縮**](#パスを伸縮) extendLine.js `Update` +- [**直線に平行な図形を描く**](#直線に平行な図形を描く) drawShapeParallelToPathSegment.js +- [**ハンドルを伸縮**](#ハンドルを伸縮) extendHandle.js +- [**パスの寸法を表示**](#パスの寸法を表示) showDimensions.js +- [**パスを伸縮**](#パスを伸縮) extendLine.js - [**パスを閉じる**](#パスを閉じる) closePath.js - [**パスを分解**](#パスを分解) disjoinPath.js -- [**法線を描く**](#法線を描く) drawNormalLine.js `New` -- [**余白の垂直方向中央に整列**](#余白の垂直方向中央に整列余白の水平方向中央に整列) alignInCenterOfSpace(Vertical).js `Update` -- [**余白の水平方向中央に整列**](#余白の垂直方向中央に整列余白の水平方向中央に整列) alignInCenterOfSpace(Horizontal).js `Update` -- [**余白の垂直方向に分布**](#余白の垂直方向に分布余白の水平方向に分布) distributeInSpace(Vertical).js `Update` -- [**余白の水平方向に分布**](#余白の垂直方向に分布余白の水平方向に分布) distributeInSpace(Horizotal).js `Update` +- [**法線を描く**](#法線を描く) drawNormalLine.js +- [**余白の垂直方向中央に整列**](#余白の垂直方向中央に整列余白の水平方向中央に整列) alignInCenterOfSpace(Vertical).js +- [**余白の水平方向中央に整列**](#余白の垂直方向中央に整列余白の水平方向中央に整列) alignInCenterOfSpace(Horizontal).js +- [**余白の垂直方向に分布**](#余白の垂直方向に分布余白の水平方向に分布) distributeInSpace(Vertical).js +- [**余白の水平方向に分布**](#余白の垂直方向に分布余白の水平方向に分布) distributeInSpace(Horizotal).js ### テキスト [![Download Text.zip](https://img.shields.io/badge/Download-Text.zip-e60012?style=for-the-badge)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Text.zip) @@ -105,7 +105,7 @@ Adobe Illustratorのスクリプト集です。 - [**スレッドテキストを作成**](#スレッドテキストを作成) createThreadedText.js - [**選択なしでカット**](#選択なしでカット選択なしでコピー) cutLine(emptySelection).js - [**選択なしでコピー**](#選択なしでカット選択なしでコピー) copyLine(emptySelection).js -- [**直線に平行なテキストを作成**](#直線に平行なテキストを作成) createTextParallelToPathSegment.js `Update` +- [**直線に平行なテキストを作成**](#直線に平行なテキストを作成) createTextParallelToPathSegment.js - [**テキスト中央揃え**](#テキスト中央揃えテキスト左揃えテキスト右揃え) textAlign_Center.js - [**テキスト左揃え**](#テキスト中央揃えテキスト左揃えテキスト右揃え) textAlign_Left.js - [**テキスト右揃え**](#テキスト中央揃えテキスト左揃えテキスト右揃え) textAlign_Right.js @@ -119,19 +119,21 @@ Adobe Illustratorのスクリプト集です。 ### ユーティリティ [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012?style=for-the-badge)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) -- [**拡大・縮小率を表示**](#拡大縮小率を表示) compareScale.js -- [**距離を測る**](#距離を測る) measureDistance.js +- [**拡大・縮小率の確認**](#拡大縮小率の確認) compareScale.js `Update` +- [**距離の測定**](#距離の測定) measureDistance.js `Update` - [**コピー元のレイヤーにペーストを切り替える**](#コピー元のレイヤーにペーストを切り替える) togglePasteRemembersLayers.js - [**字形の境界に整列を切り替える**](#字形の境界に整列を切り替える) toggleAlignToGlyphBounds.js - [**すべてのドキュメントを閉じる**](#すべてのドキュメントを閉じる) closeAllDocuments.js - [**選択した複数のアンカーポイントのハンドルを表示/隠すを切り替える**](#選択した複数のアンカーポイントのハンドルを表示隠すを切り替える) toggleShowHandles.js -- [**日付の曜日をチェック**](#日付の曜日をチェック) checkDayOfWeek.js -- [**文字列内の数字を足す**](#文字列内の数字を足す) sumNumbers.js +- [**単位を換算**](#単位を換算) unitCalculator.js `New` +- [**日付と曜日の確認**](#日付と曜日の確認) checkDayOfWeek.js `Update` +- [**文字列内の数字の合計**](#文字列内の数字の合計) sumNumbers.js `Update` ### 表示 [![Download View.zip](https://img.shields.io/badge/Download-View.zip-e60012?style=for-the-badge)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/View.zip) - [**ウィンドウの表示位置を同期**](#ウィンドウの表示位置を同期) syncView.js - [**ウィンドウを並べて表示**](#ウィンドウを並べて表示) arrangeWindows.js +- [**オブジェクトを画面全体に拡大表示**](#オブジェクトを画面全体に拡大表示) fitSelectedObjectsInWindow.js `New` - [**最後のアートボードへ移動**](#最後のアートボードへ移動先頭のアートボードへ移動次のアートボードへ移動前のアートボードへ移動) navigateToLastArtboard.js - [**先頭のアートボードへ移動**](#最後のアートボードへ移動先頭のアートボードへ移動次のアートボードへ移動前のアートボードへ移動) navigateToFirstArtboard.js - [**次のアートボードへ移動**](#最後のアートボードへ移動先頭のアートボードへ移動次のアートボードへ移動前のアートボードへ移動) navigateToNextArtboard.js @@ -350,31 +352,31 @@ Illustrator CS6以降 -## 日付の曜日をチェック +## 日付と曜日の確認 [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) ### checkDayOfWeek.js -選択した日付の曜日をチェックします。 +選択した日付の曜日を確認します。 ![Check Day Of Week](images/checkDayOfWeek.png) > [!NOTE] > Illustrator日本語版を使用している場合は、UIは日本語で表示します。 #### 使用方法 -カーソルで日付を選択してスクリプトを実行します。 +テキスト内の日付をカーソルで選択してスクリプトを実行します。 > [!NOTE] > 年がない場合(月日のみ)は、今年とみなします。 -> 日付が正しくない場合は警告を表示します。 -> チェック可能な日付の書式は下記になります。 +> 漢数字には対応していません。 -> **書式** -> `YYYY/MM/DD`, `MM/DD/YYYY`, `DD/MM/YYYY`, -> `YYYY-MM-DD`, `MM-DD-YYYY`, `DD-MM-YYYY`, -> `YYYY.MM.DD`, `MM.DD.YYYY`, `DD.MM.YYYY`, -> `YYYY MM DD`, -> `YYYY年MM月DD日`, -> `Jan(uary) (the) DD(st|nd|rd|th)(,) YYYY`, `MM DD(st|nd|rd|th)(,) YYYY`, -> `DD(st|nd|rd|th) (of) Jan(uary)(,) YYYY`, `DD(st|nd|rd|th) MM(,) YYYY` +#### 書式 +確認できる日付の書式は下記になります。 +`YYYY年MM月DD日`, `令和YY年MM月DD日`, `平成YY年MM月DD日`, `昭和YY年MM月DD日`, `大正YY年MM月DD日`, `明治YY年MM月DD日`, +`YYYY/MM/DD`, `MM/DD/YYYY`, `DD/MM/YYYY`, +`YYYY-MM-DD`, `MM-DD-YYYY`, `DD-MM-YYYY`, +`YYYY.MM.DD`, `MM.DD.YYYY`, `DD.MM.YYYY`, +`YYYY MM DD`, `MM DD YYYY`, `DD MM YYYY`, +`Jan(uary) (the) DD(st|nd|rd|th)(,) YYYY`, `MM DD(st|nd|rd|th)(,) YYYY`, +`DD(st|nd|rd|th) (of) Jan(uary)(,) YYYY`, `DD(st|nd|rd|th) MM(,) YYYY` #### 動作条件 Illustrator CS4以降 @@ -428,7 +430,7 @@ Illustrator CS以降 -## 拡大・縮小率を表示 +## 拡大・縮小率の確認 [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) ### compareScale.js 2つのオブジェクトを比較して拡大・縮小率を表示します。 @@ -438,10 +440,12 @@ Illustrator CS以降 > Illustrator日本語版を使用している場合は、UIは日本語で表示します。 #### 使用方法 -2つのオブジェクトを選択してスクリプトを実行します。 +1. 2つのオブジェクトを選択してスクリプトを実行します。 +2. 線幅を含める場合は、[プレビュー境界を使用]にチェックを付けます。 -> [!NOTE] -> 寸法の単位はルーラー単位により変わります。 +#### 対応する単位 +ポイント、ピクセル、パイカ、インチ、フィート、ヤード、ミリメートル、センチメートル、メートル。 +使用する単位は、定規の単位によります。 #### 動作条件 Illustrator CS4以降 @@ -1357,6 +1361,29 @@ Illustrator CS以降 +## オブジェクトを画面全体に拡大表示 +[![Download View.zip](https://img.shields.io/badge/Download-View.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/View.zip) +### fitSelectedObjectsInWindow.js +選択したオブジェクトが画面全体に収まるようにズーム倍率を変更します。 + +![Fit Selected Objects In Window](images/fitSelectedObjectsInWindow.png) + +#### 使用方法 +オブジェクトを選択してスクリプトを実行します。 + +> [!NOTE] +> オブジェクトを選択していない場合は、すべてのオブジェクトが画面に収まるように表示します。そのときはガイドを無視します。 + +#### 動作条件 +Illustrator CS以降 + +
[ ↑ トップへ戻る ↑ ]
+
+ + + + + ## グラデーションを生成 [![Download Color.zip](https://img.shields.io/badge/Download-Color.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Color.zip) ### generateGradientColor.js @@ -1661,7 +1688,7 @@ Illustrator CS以降 2. 元になるグラデーションを選択します。 > [!NOTE] -> スウォッチにあるグラデーションが対象となります。 +> スウォッチにあるグラデーションが対象になります。 #### 動作条件 Illustrator CS4以降 @@ -1673,10 +1700,10 @@ Illustrator CS4以降 -## 距離を測る +## 距離の測定 [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) ### measureDistance.js -2点間のアンカーポイントの距離を正確に測ります。 +2点間のアンカーポイントの距離をものさしツールよりも正確に測ります。 ![Measure the Distance](images/measureDistance.png) > [!NOTE] @@ -1688,10 +1715,13 @@ Illustrator CS4以降 > [!NOTE] > 測定箇所をハイライトします。 > 角度はポイント#1を基準にします。 -> 寸法の単位はルーラー単位により変わります。 > パス上文字とエリア内文字のアンカーポイントにも対応しています。 > フォントサイズが小さくなりすぎるため、15500%以上に拡大表示するとラベルが表示されません。 +#### 対応する単位 +ポイント、ピクセル、パイカ、インチ、フィート、ヤード、ミリメートル、センチメートル、メートル。 +使用する単位は、定規の単位によります。 + #### 動作条件 Illustrator CS4以降 @@ -2492,22 +2522,21 @@ Illustrator CS4以降 -## 文字列内の数字を足す +## 文字列内の数字の合計 [![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) ### sumNumbers.js -文字列内の数字で足し算します。 +文字列内の数字を足し合わせます。 ![Sum Numbers](images/sumNumbers.png) > [!NOTE] > Illustrator日本語版を使用している場合は、UIは日本語で表示します。 #### 使用方法 -テキストオブジェクトを選択してスクリプトを実行します。 -また、リストから選択した項目のみを使用して再計算することも可能です。 +テキストオブジェクトを選択、または編集状態で範囲を指定してスクリプトを実行します。 +テキストフィールドの数値を編集して合計を再計算することもできます。 > [!NOTE] -> 数値の単位は無視して計算します。 -> 全角数字には対応していません。 +> テキストフィールドの数値を編集しても、元のテキストオブジェクトには影響しません。 #### 動作条件 Illustrator CS4以降 @@ -2667,6 +2696,38 @@ Illustrator CS以降 +## 単位を換算 +[![Download Utility.zip](https://img.shields.io/badge/Download-Utility.zip-e60012)](https://github.com/sky-chaser-high/adobe-illustrator-scripts/releases/latest/download/Utility.zip) +### unitCalculator.js +Illustratorで対応しているほぼすべての単位を換算します。 + +Unit Calculator + +> [!NOTE] +> Illustrator日本語版を使用している場合は、UIは日本語で表示します。 + +#### 使用方法 +1. スクリプトを実行します。 + オブジェクトの幅や高さの値を参照したい場合は、選択ツールでオブジェクトを選択してからスクリプトを実行します。 +2. いずれかの単位に値を入力します。 + +> [!NOTE] +> ドキュメントを開いている場合は、定規の単位が基準になります。 + +#### 対応する単位 +ポイント、ピクセル、パイカ、インチ、フィート、ヤード、ミリメートル、センチメートル、メートル、歯(日本語版のみ)。 +使用する単位は、定規の単位によります。 + +#### 動作条件 +Illustrator CC以降 + +
[ ↑ トップへ戻る ↑ ]
+
+ + + + + # ライセンス MITライセンスのもとで公開しています。 詳しくはLICENSEファイルをご覧ください。 diff --git a/images/checkDayOfWeek.png b/images/checkDayOfWeek.png index f983afe..6af31eb 100644 Binary files a/images/checkDayOfWeek.png and b/images/checkDayOfWeek.png differ diff --git a/images/compareScale.png b/images/compareScale.png index 08edc0d..aa4b11c 100644 Binary files a/images/compareScale.png and b/images/compareScale.png differ diff --git a/images/fitSelectedObjectsInWindow.png b/images/fitSelectedObjectsInWindow.png new file mode 100644 index 0000000..a93450f Binary files /dev/null and b/images/fitSelectedObjectsInWindow.png differ diff --git a/images/measureDistance.png b/images/measureDistance.png index 3a0f7bd..997cb95 100644 Binary files a/images/measureDistance.png and b/images/measureDistance.png differ diff --git a/images/sumNumbers.png b/images/sumNumbers.png index bc71329..0d813fe 100644 Binary files a/images/sumNumbers.png and b/images/sumNumbers.png differ diff --git a/images/unitCalculator.png b/images/unitCalculator.png new file mode 100644 index 0000000..48646e2 Binary files /dev/null and b/images/unitCalculator.png differ diff --git a/scripts/checkDayOfWeek.js b/scripts/checkDayOfWeek.js index f47a664..dfa3c73 100755 --- a/scripts/checkDayOfWeek.js +++ b/scripts/checkDayOfWeek.js @@ -5,28 +5,28 @@ This script checks the day of the week. Usage - Select a date with the cursor, run this script from File > Scripts > Other Script... + Select a date section in the text with the cursor, run this script from File > Scripts > Other Script... Format YYYY/MM/DD, MM/DD/YYYY, DD/MM/YYYY, YYYY-MM-DD, MM-DD-YYYY, DD-MM-YYYY, YYYY.MM.DD, MM.DD.YYYY, DD.MM.YYYY, - YYYY MM DD, - YYYY年MM月DD日, + YYYY MM DD, MM DD YYYY, DD MM YYYY, + YYYY年MM月DD日, 令和YY年MM月DD日, 平成YY年MM月DD日, 昭和YY年MM月DD日, 大正YY年MM月DD日, 明治YY年MM月DD日, Jan(uary) (the) DD(st|nd|rd|th)(,) YYYY, MM DD(st|nd|rd|th)(,) YYYY, DD(st|nd|rd|th) (of) Jan(uary)(,) YYYY, DD(st|nd|rd|th) MM(,) YYYY, Notes - If there is no year, it is considered as this year. - If the date is incorrect, a warning is issued. - In rare cases, you may not be able to create it. - In that case, restart Illustrator and run this script again. + If there is no year, it will considered as this year. + Chinese numerals are not supported. + In rare cases, the script may not work if you continue to use it. + In this case, restart Illustrator and try again. Requirements - Illustrator CS or higher + Illustrator CS4 or higher Version - 1.0.0 + 1.1.0 Homepage github.com/sky-chaser-high/adobe-illustrator-scripts @@ -37,48 +37,105 @@ =============================================================================================================================================== */ (function() { - if (app.documents.length > 0 && app.activeDocument.selection.length > 0) main(); + if (app.documents.length && isValidVersion()) main(); })(); function main() { - try { - var text = app.activeDocument.selection; - if (!text.typename) return; + var text = app.activeDocument.selection; + if (!text.typename) return; - var contents = text.contents.split(/\s+the\s+|\s+of\s+|\/|\s+|-|,\s*|\.\s*|[^\x01-\x7E\uFF61-\uFF9F]/ig); - var format = getFormat(contents); + var contents = splitContents(text.contents); + var format = getDateFormat(contents); - var year = getYear(format, contents); - var month = getMonth(format, contents); - var date = getDate(format, contents); + var year = getYear(contents, format); + var month = getMonth(contents, format); + var date = getDate(contents, format); - var isValid = checkDate(year, month + 1, date); - if (!isValid) return alert(errorMassage()); + var isValid = checkDate(year, month + 1, date); + if (!isValid) return showErrorMassage(text.contents); - var day = getDayOfWeek(year, month, date); - showDialog(year, month + 1, date, day); - } - catch (err) { } + var day = getDayOfWeek(year, month, date); + + showDialog(text.contents, day, year, month + 1, date); +} + + +function splitContents(text) { + var regex = /\s+the\s+|\s+of\s+|\/|\s+|-|,\s*|\.\s*|[^\x01-\x7E\uFF61-\uFF9F]/ig; + var contents = convertToSingleByteCharacters(text); + contents = convertJapaneseToGregorianCalendar(contents); + return contents.split(regex); +} + + +function convertToSingleByteCharacters(text) { + var twoByteChar = /[!-~]/g; + var value = text.replace(twoByteChar, function(str) { + return String.fromCharCode(str.charCodeAt(0) - 0xFEE0); + }); + return value; +} + + +function convertJapaneseToGregorianCalendar(text) { + var meiji = /明治(元|\d+)/; + var taisho = /大正(元|\d+)/; + var showa = /昭和(元|\d+)/; + var heisei = /平成(元|\d+)/; + var reiwa = /令和(元|\d+)/; + var digits = /^\d{1,3}年/; + if (meiji.test(text)) return convertToGregorianCalendar(text, meiji, 1867); + if (taisho.test(text)) return convertToGregorianCalendar(text, taisho, 1911); + if (showa.test(text)) return convertToGregorianCalendar(text, showa, 1925); + if (heisei.test(text)) return convertToGregorianCalendar(text, heisei, 1988); + if (reiwa.test(text)) return convertToGregorianCalendar(text, reiwa, 2018); + if (digits.test(text)) return convertToFourDigits(text, digits); + return text; } -function getFormat(date) { - var regex = new RegExp('^[0-9]{4}$', 'i'); - if (regex.test(date[0])) return 'YMD'; +function convertToGregorianCalendar(text, era, ad) { + var japanese = /[^\x01-\x7E\uFF61-\uFF9F]+/; + var year = text.match(era)[0].replace(japanese, ''); + if (!year) year = 1; + var gregorian = parseInt(year, 10) + ad; + return text.replace(era, gregorian); +} + + +function convertToFourDigits(text, era) { + var japanese = /[^\x01-\x7E\uFF61-\uFF9F]+/; + var year = text.match(era)[0].replace(japanese, ''); + var gregorian = 2000 + parseInt(year, 10) + '年'; + return text.replace(era, gregorian); +} + - regex = new RegExp('^[a-z]+(,|\.)*$', 'i'); - if (regex.test(date[0])) return 'MDY'; - if (regex.test(date[1])) return 'DMY'; +function getDateFormat(contents) { + var regex = /^[0-9]{3,4}$/; + if (regex.test(contents[0])) return 'YMD'; - regex = new RegExp('^[0-9]{1,2}[a-z]{2}(,|\.)*$', 'i'); - if (regex.test(date[0])) return 'DMY'; - if (regex.test(date[1])) return 'MDY'; + if (/jp|kr|zh/i.test($.locale) && contents.length == 3) { + regex = /^[0-9]{1,2}$/; + if (regex.test(contents[0]) && regex.test(contents[2])) { + if (parseInt(contents[2]) > 31) return 'MDY'; + return 'YMD'; + } + } - if (parseInt(date[0]) > 12) return 'DMY'; - if (parseInt(date[1]) > 12) return 'MDY'; + regex = /^[a-z]+(,|\.)*$/i; + if (regex.test(contents[0])) return 'MDY'; + if (regex.test(contents[1])) return 'DMY'; - if (parseInt(date[0]) <= 12 && parseInt(date[1]) <= 12) { + regex = /^[0-9]{1,2}[a-z]{2}(,|\.)*$/i; + if (regex.test(contents[0])) return 'DMY'; + if (regex.test(contents[1])) return 'MDY'; + + if (parseInt(contents[0]) > 12) return 'DMY'; + if (parseInt(contents[1]) > 12) return 'MDY'; + + if (parseInt(contents[0]) <= 12 && parseInt(contents[1]) <= 12) { if (/us|jp|kr|zh/i.test($.locale)) return 'MDY'; return 'DMY'; } @@ -86,20 +143,18 @@ function getFormat(date) { } -function getYear(format, contents) { +function getYear(contents, format) { var year = (format == 'YMD') ? contents[0] : contents[2]; - if (!year) { - return new Date().getFullYear(); - } - return parseInt(year); + if (!year) return new Date().getFullYear(); + if (year.length < 4) return parseInt(year, 10) + 2000; + return parseInt(year, 10); } -function getMonth(format, contents) { - if (format == 'MDY') { - return convertMonth(contents[0]); - } - return convertMonth(contents[1]); +function getMonth(contents, format) { + var month = contents[1]; + if (format == 'MDY') month = contents[0]; + return convertMonth(month); } @@ -117,26 +172,29 @@ function convertMonth(str) { if (/^Nov/i.test(str)) return 10; if (/^Dec/i.test(str)) return 11; - var month = parseInt(str) - 1; + var month = parseInt(str, 10) - 1; return (month < 12) ? month : undefined; } -function getDate(format, contents) { - if (format == 'DMY') return convertDate(contents[0]); - if (format == 'MDY') return convertDate(contents[1]); - if (format == 'YMD') return convertDate(contents[2]); +function getDate(contents, format) { + var date; + if (format == 'DMY') date = contents[0]; + if (format == 'MDY') date = contents[1]; + if (format == 'YMD') date = contents[2]; + return convertDate(date); } function convertDate(str) { if (!str) return undefined; var date = str.replace(/,|\./, ''); - var regex = new RegExp('^[0-9]{1,2}[a-z]{2}(,|\.)*$', 'i'); + var regex = /^[0-9]{1,2}[a-z]{2}(,|\.)*$/i; if (regex.test(str)) { - date = str.replace(/[a-z]{2}(,|\.)*/i, ''); + var alphabet = /[a-z]{2}(,|\.)*/i; + date = str.replace(alphabet, ''); } - return parseInt(date); + return parseInt(date, 10); } @@ -159,30 +217,39 @@ function isLeapYear(year) { function getDayOfWeek(year, month, date) { $.localize = true; + var week = localizeUI(); var day = new Date(year, month, date).getDay(); - if (day == 0) return { en: 'Sunday', ja: '日曜日' }; - if (day == 1) return { en: 'Monday', ja: '月曜日' }; - if (day == 2) return { en: 'Tuesday', ja: '火曜日' }; - if (day == 3) return { en: 'Wednesday', ja: '水曜日' }; - if (day == 4) return { en: 'Thursday', ja: '木曜日' }; - if (day == 5) return { en: 'Friday', ja: '金曜日' }; - if (day == 6) return { en: 'Saturday', ja: '土曜日' }; + if (day == 0) return week.sunday; + if (day == 1) return week.monday; + if (day == 2) return week.tuesday; + if (day == 3) return week.wednesday; + if (day == 4) return week.thursday; + if (day == 5) return week.friday; + if (day == 6) return week.saturday; } -function errorMassage() { +function isValidVersion() { + var cs4 = 14; + var aiVersion = parseInt(app.version); + if (aiVersion < cs4) return false; + return true; +} + + +function showErrorMassage(contents) { $.localize = true; - return { - en: 'Incorrect date.', - ja: '日付が正しくありません。' - }; + var ui = localizeUI(); + showDialog(contents, ui.message, '-', '-', '-'); } -function showDialog(year, month, date, day) { +function showDialog(contents, day, year, month, date) { + $.localize = true; + var ui = localizeUI(); + var dialog = new Window('dialog'); - dialog.text = 'Day of Week'; - dialog.preferredSize.width = 160; + dialog.text = ui.title; dialog.orientation = 'column'; dialog.alignChildren = ['fill', 'top']; dialog.spacing = 10; @@ -192,54 +259,128 @@ function showDialog(year, month, date, day) { group1.orientation = 'row'; group1.alignChildren = ['left', 'center']; group1.spacing = 10; - group1.margins = 0; - - var group2 = group1.add('group', undefined, { name: 'group2' }); - group2.orientation = 'column'; - group2.alignChildren = ['right', 'center']; - group2.spacing = 10; - group2.margins = 0; + group1.margins = [0, 0, 0, 4]; - var statictext1 = group2.add('statictext', undefined, undefined, { name: 'statictext1' }); - statictext1.text = 'Day:'; + var statictext1 = group1.add('statictext', undefined, undefined, { name: 'statictext1', truncate: 'end' }); + statictext1.text = contents; + statictext1.minimumSize.width = 160; - var statictext2 = group2.add('statictext', undefined, undefined, { name: 'statictext2' }); - statictext2.text = 'Year:'; + var divider1 = dialog.add('panel', undefined, undefined, { name: 'divider1' }); + divider1.alignment = 'fill'; - var statictext3 = group2.add('statictext', undefined, undefined, { name: 'statictext3' }); - statictext3.text = 'Month:'; - - var statictext4 = group2.add('statictext', undefined, undefined, { name: 'statictext4' }); - statictext4.text = 'Date:'; + var group2 = dialog.add('group', undefined, { name: 'group2' }); + group2.orientation = 'row'; + group2.alignChildren = ['left', 'center']; + group2.spacing = 10; + group2.margins = [0, 5, 0, 0]; - var group3 = group1.add('group', undefined, { name: 'group3' }); + var group3 = group2.add('group', undefined, { name: 'group3' }); group3.orientation = 'column'; - group3.alignChildren = ['left', 'center']; - group3.spacing = 10; + group3.alignChildren = ['right', 'center']; + group3.spacing = 12; group3.margins = 0; + var statictext2 = group3.add('statictext', undefined, undefined, { name: 'statictext2' }); + statictext2.text = ui.day; + + var statictext3 = group3.add('statictext', undefined, undefined, { name: 'statictext3' }); + statictext3.text = ui.year; + + var statictext4 = group3.add('statictext', undefined, undefined, { name: 'statictext4' }); + statictext4.text = ui.month; + var statictext5 = group3.add('statictext', undefined, undefined, { name: 'statictext5' }); - statictext5.text = day; + statictext5.text = ui.date; + + var group4 = group2.add('group', undefined, { name: 'group4' }); + group4.orientation = 'column'; + group4.alignChildren = ['left', 'center']; + group4.spacing = 12; + group4.margins = 0; + + var statictext6 = group4.add('statictext', undefined, undefined, { name: 'statictext6' }); + statictext6.text = day; - var statictext6 = group3.add('statictext', undefined, undefined, { name: 'statictext6' }); - statictext6.text = year; + var statictext7 = group4.add('statictext', undefined, undefined, { name: 'statictext7' }); + statictext7.text = year; - var statictext7 = group3.add('statictext', undefined, undefined, { name: 'statictext7' }); - statictext7.text = month; + var statictext8 = group4.add('statictext', undefined, undefined, { name: 'statictext8' }); + statictext8.text = month; - var statictext8 = group3.add('statictext', undefined, undefined, { name: 'statictext8' }); - statictext8.text = date; + var statictext9 = group4.add('statictext', undefined, undefined, { name: 'statictext9' }); + statictext9.text = date; - var group4 = dialog.add('group', undefined, { name: 'group4' }); - group4.orientation = 'row'; - group4.alignChildren = ['center', 'center']; - group4.spacing = 10; - group4.margins = [0, 5, 0, 0]; + var group5 = dialog.add('group', undefined, { name: 'group5' }); + group5.orientation = 'row'; + group5.alignChildren = ['right', 'center']; + group5.spacing = 10; + group5.margins = [0, 5, 0, 0]; - var button1 = group4.add('button', undefined, undefined, { name: 'button1' }); - button1.text = 'OK'; - button1.preferredSize.width = 100; - button1.preferredSize.height = 26; + var button1 = group5.add('button', undefined, undefined, { name: 'button1' }); + button1.text = ui.ok; + button1.preferredSize.width = 90; dialog.show(); } + + +function localizeUI() { + return { + title: { + en: 'Day of Week', + ja: '日付と曜日' + }, + day: { + en: 'Day:', + ja: '曜日:' + }, + year: { + en: 'Year:', + ja: '年:' + }, + month: { + en: 'Month:', + ja: '月:' + }, + date: { + en: 'Date:', + ja: '日:' + }, + ok: { + en: 'OK', + ja: 'OK' + }, + sunday: { + en: 'Sunday', + ja: '日曜日' + }, + monday: { + en: 'Monday', + ja: '月曜日' + }, + tuesday: { + en: 'Tuesday', + ja: '火曜日' + }, + wednesday: { + en: 'Wednesday', + ja: '水曜日' + }, + thursday: { + en: 'Thursday', + ja: '木曜日' + }, + friday: { + en: 'Friday', + ja: '金曜日' + }, + saturday: { + en: 'Saturday', + ja: '土曜日' + }, + message: { + en: 'Incorrect date.', + ja: '日付が正しくありません。' + } + }; +} diff --git a/scripts/compareScale.js b/scripts/compareScale.js index 11884de..0301377 100755 --- a/scripts/compareScale.js +++ b/scripts/compareScale.js @@ -5,7 +5,8 @@ This script compares the scales of two objects. Usage - Select two objects, run this script from File > Scripts > Other Script... + 1. Select two objects, run this script from File > Scripts > Other Script... + 2. To include stroke width, check the Use Preview Bounds checkbox. Notes The dimension units depend on the ruler units. @@ -13,10 +14,10 @@ In this case, restart Illustrator and try again. Requirements - Illustrator CS4 or higher + Illustrator CC or higher Version - 1.0.1 + 1.1.0 Homepage github.com/sky-chaser-high/adobe-illustrator-scripts @@ -26,70 +27,99 @@ https://opensource.org/licenses/mit-license.php =============================================================================================================================================== */ -(function () { +(function() { if (app.documents.length && isValidVersion()) main(); })(); function main() { - $.localize = true; var items = app.activeDocument.selection; - if (items.length != 2) return alert(localizeUI().caution); + if (items.length != 2) { + $.localize = true; + var ui = localizeUI(); + return alert(ui.caution); + } - var unit = getRulerUnits(); + var item1 = items[0]; + var item2 = items[1]; + var usePreviewBounds = isUsePreviewBounds(); + var compare = compareScale(item1, item2, usePreviewBounds); - var item1 = { - width: convertUnits(items[0].width + 'pt', unit), - height: convertUnits(items[0].height + 'pt', unit) - }; + var dialog = showDialog(compare.item1, compare.item2); - var item2 = { - width: convertUnits(items[1].width + 'pt', unit), - height: convertUnits(items[1].height + 'pt', unit) - }; + dialog.usePreviewBounds.onClick = function() { + usePreviewBounds = dialog.usePreviewBounds.value; + compare = compareScale(item1, item2, usePreviewBounds); + setCompareValueTo(dialog, compare.item1, compare.item2); + } - var compare = compareScale(item1, item2); - showDialog(compare.width, compare.height, compare.scale, unit); + dialog.show(); } -function compareScale(item1, item2) { - var width = { large: 0, small: 0 }; - var height = { large: 0, small: 0 }; - var scale = { - horizontal: { expanding: 0, shrinking: 0 }, - vertical: { expanding: 0, shrinking: 0 } - }; +function setCompareValueTo(dialog, item1, item2) { + var unit = getRulerUnits(); - var isLarge = (item1.width > item2.width || item1.height > item2.height) ? true : false; + dialog.item1.horizontal.text = round(item1.horizontal); + dialog.item1.vertical.text = round(item1.vertical); - width.large = (isLarge) ? item1.width : item2.width; - height.large = (isLarge) ? item1.height : item2.height; + dialog.item1.width.text = round(item1.width) + ' ' + unit; + dialog.item1.height.text = round(item1.height) + ' ' + unit; - width.small = (isLarge) ? item2.width : item1.width; - height.small = (isLarge) ? item2.height : item1.height; + dialog.item2.horizontal.text = round(item2.horizontal); + dialog.item2.vertical.text = round(item2.vertical); - scale.horizontal.expanding = (isLarge) ? getWidthRatio(item1, item2) : getWidthRatio(item2, item1); - scale.vertical.expanding = (isLarge) ? getHeightRatio(item1, item2) : getHeightRatio(item2, item1); + dialog.item2.width.text = round(item2.width) + ' ' + unit; + dialog.item2.height.text = round(item2.height) + ' ' + unit; +} - scale.horizontal.shrinking = (isLarge) ? getWidthRatio(item2, item1) : getWidthRatio(item1, item2); - scale.vertical.shrinking = (isLarge) ? getHeightRatio(item2, item1) : getHeightRatio(item1, item2); +function compareScale(item1, item2, usePreviewBounds) { + var width1 = getWidth(item1, usePreviewBounds); + var height1 = getHeight(item1, usePreviewBounds); + var width2 = getWidth(item2, usePreviewBounds); + var height2 = getHeight(item2, usePreviewBounds); + var unit = getRulerUnits(); return { - width: width, - height: height, - scale: scale + item1: { + horizontal: getWidthRatio(width2, width1), + vertical: getHeightRatio(height2, height1), + width: convertUnits(width1 + 'pt', unit), + height: convertUnits(height1 + 'pt', unit) + }, + item2: { + horizontal: getWidthRatio(width1, width2), + vertical: getHeightRatio(height1, height2), + width: convertUnits(width2 + 'pt', unit), + height: convertUnits(height2 + 'pt', unit) + } }; } +function getWidth(item, usePreviewBounds) { + var bounds = (usePreviewBounds) ? item.visibleBounds : item.geometricBounds; + var x1 = bounds[0]; + var x2 = bounds[2]; + return Math.abs(x1 - x2); +} + + +function getHeight(item, usePreviewBounds) { + var bounds = (usePreviewBounds) ? item.visibleBounds : item.geometricBounds; + var y1 = bounds[1]; + var y2 = bounds[3]; + return Math.abs(y1 - y2); +} + + function getWidthRatio(item1, item2) { - return item1.width / item2.width * 100 + return item1 / item2 * 100; } function getHeightRatio(item1, item2) { - return item1.height / item2.height * 100 + return item1 / item2 * 100; } @@ -99,6 +129,13 @@ function round(value) { } +function isUsePreviewBounds() { + var key = 'includeStrokeInBounds'; + var pref = app.preferences; + return pref.getBooleanPreference(key); +} + + function convertUnits(value, unit) { try { return Number(UnitValue(value).as(unit)); @@ -110,276 +147,324 @@ function convertUnits(value, unit) { function getRulerUnits() { - switch (app.activeDocument.rulerUnits) { - case RulerUnits.Millimeters: return 'mm'; - case RulerUnits.Centimeters: return 'cm'; - case RulerUnits.Inches: return 'in'; - case RulerUnits.Points: return 'pt'; - case RulerUnits.Pixels: return 'px'; - default: return 'pt'; + var unit = getUnitSymbol(); + if (!app.documents.length) return unit.pt; + + var document = app.activeDocument; + var src = document.fullName; + var ruler = document.rulerUnits; + try { + switch (ruler) { + case RulerUnits.Pixels: return unit.px; + case RulerUnits.Points: return unit.pt; + case RulerUnits.Picas: return unit.pc; + case RulerUnits.Inches: return unit.inch; + case RulerUnits.Millimeters: return unit.mm; + case RulerUnits.Centimeters: return unit.cm; + + case RulerUnits.Feet: return unit.ft; + case RulerUnits.Yards: return unit.yd; + case RulerUnits.Meters: return unit.meter; + } + } + catch (err) { + switch (xmpRulerUnits(src)) { + case 'Feet': return unit.ft; + case 'Yards': return unit.yd; + case 'Meters': return unit.meter; + } } + return unit.pt; +} + + +function xmpRulerUnits(src) { + if (!ExternalObject.AdobeXMPScript) { + ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); + } + var xmpFile = new XMPFile(src.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_READ); + var xmpPackets = xmpFile.getXMP(); + var xmp = new XMPMeta(xmpPackets.serialize()); + + var namespace = 'http://ns.adobe.com/xap/1.0/t/pg/'; + var prop = 'xmpTPg:MaxPageSize'; + var unit = prop + '/stDim:unit'; + + var ruler = xmp.getProperty(namespace, unit).value; + return ruler; +} + + +function getUnitSymbol() { + return { + px: 'px', + pt: 'pt', + pc: 'pc', + inch: 'in', + ft: 'ft', + yd: 'yd', + mm: 'mm', + cm: 'cm', + meter: 'm' + }; } function isValidVersion() { - var cs4 = 14; + var cc = 17; var aiVersion = parseInt(app.version); - if (aiVersion < cs4) return false; + if (aiVersion < cc) return false; return true; } -function showDialog(width, height, scale, unit) { - var aiVersion = parseInt(app.version); - +function showDialog(item1, item2) { $.localize = true; - var local = localizeUI(); + var ui = localizeUI(); + var unit = getRulerUnits(); var dialog = new Window('dialog'); - dialog.text = local.title; + dialog.text = ui.title; dialog.orientation = 'column'; - dialog.alignChildren = ['center', 'top']; + dialog.alignChildren = ['fill', 'top']; dialog.spacing = 10; dialog.margins = 16; - var group1 = dialog.add('group', undefined, { name: 'group1' }); - group1.orientation = 'row'; - group1.alignChildren = ['left', 'center']; - group1.spacing = 10; - group1.margins = 0; - - var panel1 = group1.add('panel', undefined, undefined, { name: 'panel1' }); - panel1.text = local.expanding; - panel1.orientation = 'row'; + var panel1 = dialog.add('panel', undefined, undefined, { name: 'panel1' }); + panel1.text = ui.item + ' #1'; + panel1.orientation = 'column'; panel1.alignChildren = ['left', 'top']; panel1.spacing = 10; panel1.margins = 10; - var group2 = panel1.add('group', undefined, { name: 'group2' }); + var group1 = panel1.add('group', undefined, { name: 'group1' }); + group1.orientation = 'row'; + group1.alignChildren = ['left', 'center']; + group1.spacing = 10; + group1.margins = [0, 5, 0, 0]; + + var group2 = group1.add('group', undefined, { name: 'group2' }); group2.orientation = 'column'; group2.alignChildren = ['right', 'center']; - group2.spacing = (aiVersion > 24) ? 13 : 12; - if (aiVersion > 24) group2.margins = [0, 1, 0, 0]; + group2.spacing = 18; + group2.margins = [0, 4, 0, 0]; var statictext1 = group2.add('statictext', undefined, undefined, { name: 'statictext1' }); - statictext1.text = local.width; - statictext1.preferredSize.height = 20; + statictext1.text = ui.horizontal; var statictext2 = group2.add('statictext', undefined, undefined, { name: 'statictext2' }); - statictext2.text = local.height; - statictext2.preferredSize.height = 20; - - var statictext3 = group2.add('statictext', undefined, undefined, { name: 'statictext3' }); - statictext3.text = local.horizontal; - statictext3.preferredSize.height = 20; + statictext2.text = ui.vertical; - var statictext4 = group2.add('statictext', undefined, undefined, { name: 'statictext4' }); - statictext4.text = local.vertical; - statictext4.preferredSize.height = 20; - - var group3 = panel1.add('group', undefined, { name: 'group3' }); + var group3 = group2.add('group', undefined, { name: 'group3' }); group3.orientation = 'column'; - group3.alignChildren = ['left', 'center']; + group3.alignChildren = ['right', 'center']; group3.spacing = 10; - group3.margins = 0; - - var group4 = group3.add('group', undefined, { name: 'group4' }); - group4.orientation = 'row'; - group4.alignChildren = ['left', 'center']; - group4.spacing = 10; - group4.margins = 0; - - var edittext1 = group4.add('edittext', undefined, undefined, { name: 'edittext1' }); - edittext1.text = round(width.small); - edittext1.preferredSize.width = 85; + group3.margins = [0, 1, 0, 0]; - var statictext5 = group4.add('statictext', undefined, undefined, { name: 'statictext5' }); - statictext5.text = unit; + var statictext3 = group3.add('statictext', undefined, undefined, { name: 'statictext3' }); + statictext3.text = ui.width; - var statictext6 = group4.add('statictext', undefined, undefined, { name: 'statictext6' }); - statictext6.text = '>'; + var statictext4 = group3.add('statictext', undefined, undefined, { name: 'statictext4' }); + statictext4.text = ui.height; - var edittext2 = group4.add('edittext', undefined, undefined, { name: 'edittext2' }); - edittext2.text = round(width.large); - edittext2.preferredSize.width = 85; - - var statictext7 = group4.add('statictext', undefined, undefined, { name: 'statictext7' }); - statictext7.text = unit; + var group4 = group1.add('group', undefined, { name: 'group4' }); + group4.orientation = 'column'; + group4.alignChildren = ['fill', 'center']; + group4.spacing = 10; + group4.margins = 0; - var group5 = group3.add('group', undefined, { name: 'group5' }); + var group5 = group4.add('group', undefined, { name: 'group5' }); group5.orientation = 'row'; group5.alignChildren = ['left', 'center']; group5.spacing = 10; group5.margins = 0; - var edittext3 = group5.add('edittext', undefined, undefined, { name: 'edittext3' }); - edittext3.text = round(height.small); - edittext3.preferredSize.width = 85; - - var statictext8 = group5.add('statictext', undefined, undefined, { name: 'statictext8' }); - statictext8.text = unit; - - var statictext9 = group5.add('statictext', undefined, undefined, { name: 'statictext9' }); - statictext9.text = '>'; - - var edittext4 = group5.add('edittext', undefined, undefined, { name: 'edittext4' }); - edittext4.text = round(height.large); - edittext4.preferredSize.width = 85; + var edittext1 = group5.add('edittext', undefined, undefined, { name: 'edittext1' }); + edittext1.text = round(item1.horizontal); + edittext1.preferredSize.width = 140; - var statictext10 = group5.add('statictext', undefined, undefined, { name: 'statictext10' }); - statictext10.text = unit; + var statictext5 = group5.add('statictext', undefined, undefined, { name: 'statictext5' }); + statictext5.text = '%'; - var group6 = group3.add('group', undefined, { name: 'group6' }); + var group6 = group4.add('group', undefined, { name: 'group6' }); group6.orientation = 'row'; group6.alignChildren = ['left', 'center']; group6.spacing = 10; group6.margins = 0; - var edittext5 = group6.add('edittext', undefined, undefined, { name: 'edittext5' }); - edittext5.text = round(scale.horizontal.expanding); - edittext5.preferredSize.width = 85; + var edittext2 = group6.add('edittext', undefined, undefined, { name: 'edittext2' }); + edittext2.text = round(item1.vertical); + edittext2.preferredSize.width = 140; - var statictext11 = group6.add('statictext', undefined, undefined, { name: 'statictext11' }); - statictext11.text = '%'; + var statictext6 = group6.add('statictext', undefined, undefined, { name: 'statictext6' }); + statictext6.text = '%'; - var group7 = group3.add('group', undefined, { name: 'group7' }); + var group7 = group4.add('group', undefined, { name: 'group7' }); group7.orientation = 'row'; - group7.alignChildren = ['left', 'center']; + group7.alignChildren = ['fill', 'center']; group7.spacing = 10; - group7.margins = 0; + group7.margins = [0, 5, 0, 0]; - var edittext6 = group7.add('edittext', undefined, undefined, { name: 'edittext6' }); - edittext6.text = round(scale.vertical.expanding); - edittext6.preferredSize.width = 85; + var statictext7 = group7.add('statictext', undefined, undefined, { name: 'statictext7' }); + statictext7.text = round(item1.width) + ' ' + unit; - var statictext12 = group7.add('statictext', undefined, undefined, { name: 'statictext12' }); - statictext12.text = '%'; - - var group8 = dialog.add('group', undefined, { name: 'group8' }); + var group8 = group4.add('group', undefined, { name: 'group8' }); group8.orientation = 'row'; - group8.alignChildren = ['left', 'center']; + group8.alignChildren = ['fill', 'center']; group8.spacing = 10; group8.margins = 0; - var panel2 = group8.add('panel', undefined, undefined, { name: 'panel2' }); - panel2.text = local.shrinking; - panel2.orientation = 'row'; + var statictext8 = group8.add('statictext', undefined, undefined, { name: 'statictext8' }); + statictext8.text = round(item1.height) + ' ' + unit; + + var panel2 = dialog.add('panel', undefined, undefined, { name: 'panel2' }); + panel2.text = ui.item + ' #2'; + panel2.orientation = 'column'; panel2.alignChildren = ['left', 'top']; panel2.spacing = 10; panel2.margins = 10; var group9 = panel2.add('group', undefined, { name: 'group9' }); - group9.orientation = 'column'; - group9.alignChildren = ['right', 'center']; - group9.spacing = (aiVersion > 24) ? 13 : 12; - if (aiVersion > 24) group9.margins = [0, 1, 0, 0]; - - var statictext13 = group9.add('statictext', undefined, undefined, { name: 'statictext13' }); - statictext13.text = local.width; - statictext13.preferredSize.height = 20; + group9.orientation = 'row'; + group9.alignChildren = ['left', 'center']; + group9.spacing = 10; + group9.margins = [0, 5, 0, 0]; - var statictext14 = group9.add('statictext', undefined, undefined, { name: 'statictext14' }); - statictext14.text = local.height; - statictext14.preferredSize.height = 20; - - var statictext15 = group9.add('statictext', undefined, undefined, { name: 'statictext15' }); - statictext15.text = local.horizontal; - statictext15.preferredSize.height = 20; + var group10 = group9.add('group', undefined, { name: 'group10' }); + group10.orientation = 'column'; + group10.alignChildren = ['right', 'center']; + group10.spacing = 18; + group10.margins = [0, 4, 0, 0]; - var statictext16 = group9.add('statictext', undefined, undefined, { name: 'statictext16' }); - statictext16.text = local.vertical; - statictext16.preferredSize.height = 20; + var statictext9 = group10.add('statictext', undefined, undefined, { name: 'statictext9' }); + statictext9.text = ui.horizontal; - var group10 = panel2.add('group', undefined, { name: 'group10' }); - group10.orientation = 'column'; - group10.alignChildren = ['left', 'center']; - group10.spacing = 10; - group10.margins = 0; + var statictext10 = group10.add('statictext', undefined, undefined, { name: 'statictext10' }); + statictext10.text = ui.vertical; var group11 = group10.add('group', undefined, { name: 'group11' }); - group11.orientation = 'row'; - group11.alignChildren = ['left', 'center']; + group11.orientation = 'column'; + group11.alignChildren = ['right', 'center']; group11.spacing = 10; - group11.margins = 0; - - var edittext7 = group11.add('edittext', undefined, undefined, { name: 'edittext7' }); - edittext7.text = round(width.large); - edittext7.preferredSize.width = 85; - - var statictext17 = group11.add('statictext', undefined, undefined, { name: 'statictext17' }); - statictext17.text = unit; + group11.margins = [0, 1, 0, 0]; - var statictext18 = group11.add('statictext', undefined, undefined, { name: 'statictext18' }); - statictext18.text = '>'; + var statictext11 = group11.add('statictext', undefined, undefined, { name: 'statictext11' }); + statictext11.text = ui.width; - var edittext8 = group11.add('edittext', undefined, undefined, { name: 'edittext8' }); - edittext8.text = round(width.small); - edittext8.preferredSize.width = 85; + var statictext12 = group11.add('statictext', undefined, undefined, { name: 'statictext12' }); + statictext12.text = ui.height; - var statictext19 = group11.add('statictext', undefined, undefined, { name: 'statictext19' }); - statictext19.text = unit; - - var group12 = group10.add('group', undefined, { name: 'group12' }); - group12.orientation = 'row'; - group12.alignChildren = ['left', 'center']; + var group12 = group9.add('group', undefined, { name: 'group12' }); + group12.orientation = 'column'; + group12.alignChildren = ['fill', 'center']; group12.spacing = 10; group12.margins = 0; - var edittext9 = group12.add('edittext', undefined, undefined, { name: 'edittext9' }); - edittext9.text = round(height.large); - edittext9.preferredSize.width = 85; - - var statictext20 = group12.add('statictext', undefined, undefined, { name: 'statictext20' }); - statictext20.text = unit; - - var statictext21 = group12.add('statictext', undefined, undefined, { name: 'statictext21' }); - statictext21.text = '>'; - - var edittext10 = group12.add('edittext', undefined, undefined, { name: 'edittext10' }); - edittext10.text = round(height.small); - edittext10.preferredSize.width = 85; - - var statictext22 = group12.add('statictext', undefined, undefined, { name: 'statictext22' }); - statictext22.text = unit; - - var group13 = group10.add('group', undefined, { name: 'group13' }); + var group13 = group12.add('group', undefined, { name: 'group13' }); group13.orientation = 'row'; group13.alignChildren = ['left', 'center']; group13.spacing = 10; group13.margins = 0; - var edittext11 = group13.add('edittext', undefined, undefined, { name: 'edittext11' }); - edittext11.text = round(scale.horizontal.shrinking); - edittext11.preferredSize.width = 85; + var edittext3 = group13.add('edittext', undefined, undefined, { name: 'edittext3' }); + edittext3.text = round(item2.horizontal); + edittext3.preferredSize.width = 140; - var statictext23 = group13.add('statictext', undefined, undefined, { name: 'statictext23' }); - statictext23.text = '%'; + var statictext13 = group13.add('statictext', undefined, undefined, { name: 'statictext13' }); + statictext13.text = '%'; - var group14 = group10.add('group', undefined, { name: 'group14' }); + var group14 = group12.add('group', undefined, { name: 'group14' }); group14.orientation = 'row'; group14.alignChildren = ['left', 'center']; group14.spacing = 10; group14.margins = 0; - var edittext12 = group14.add('edittext', undefined, undefined, { name: 'edittext12' }); - edittext12.text = round(scale.vertical.shrinking); - edittext12.preferredSize.width = 85; + var edittext4 = group14.add('edittext', undefined, undefined, { name: 'edittext4' }); + edittext4.text = round(item2.vertical); + edittext4.preferredSize.width = 140; - var statictext24 = group14.add('statictext', undefined, undefined, { name: 'statictext24' }); - statictext24.text = '%'; + var statictext14 = group14.add('statictext', undefined, undefined, { name: 'statictext14' }); + statictext14.text = '%'; - var group15 = dialog.add('group', undefined, { name: 'group15' }); + var group15 = group12.add('group', undefined, { name: 'group15' }); group15.orientation = 'row'; - group15.alignChildren = ['left', 'center']; + group15.alignChildren = ['fill', 'center']; group15.spacing = 10; - group15.margins = 0; - group15.alignment = ['right', 'top']; - - var button1 = group15.add('button', undefined, undefined, { name: 'button1' }); + group15.margins = [0, 5, 0, 0]; + + var statictext15 = group15.add('statictext', undefined, undefined, { name: 'statictext15' }); + statictext15.text = round(item2.width) + ' ' + unit; + + var group16 = group12.add('group', undefined, { name: 'group16' }); + group16.orientation = 'row'; + group16.alignChildren = ['fill', 'center']; + group16.spacing = 10; + group16.margins = 0; + + var statictext16 = group16.add('statictext', undefined, undefined, { name: 'statictext16' }); + statictext16.text = round(item2.height) + ' ' + unit; + + var panel3 = dialog.add('panel', undefined, undefined, { name: 'panel3' }); + panel3.text = ui.option; + panel3.orientation = 'column'; + panel3.alignChildren = ['left', 'top']; + panel3.spacing = 10; + panel3.margins = 10; + + var group17 = panel3.add('group', undefined, { name: 'group17' }); + group17.orientation = 'row'; + group17.alignChildren = ['left', 'center']; + group17.spacing = 10; + group17.margins = [0, 8, 0, 0]; + + var checkbox1 = group17.add('checkbox', undefined, undefined, { name: 'checkbox1' }); + checkbox1.text = ui.bounds; + + var group18 = dialog.add('group', undefined, { name: 'group18' }); + group18.orientation = 'row'; + group18.alignChildren = ['left', 'center']; + group18.spacing = 10; + group18.margins = 0; + group18.alignment = ['right', 'top']; + + var button1 = group18.add('button', undefined, undefined, { name: 'button1' }); button1.text = 'OK'; button1.preferredSize.width = 90; - dialog.show(); + statictext1.addEventListener('click', function() { + edittext1.active = false; + edittext1.active = true; + }); + + statictext2.addEventListener('click', function() { + edittext2.active = false; + edittext2.active = true; + }); + + statictext9.addEventListener('click', function() { + edittext3.active = false; + edittext3.active = true; + }); + + statictext10.addEventListener('click', function() { + edittext4.active = false; + edittext4.active = true; + }); + + dialog.item1 = { + horizontal: edittext1, + vertical: edittext2, + width: statictext7, + height: statictext8 + }; + dialog.item2 = { + horizontal: edittext3, + vertical: edittext4, + width: statictext15, + height: statictext16 + }; + dialog.usePreviewBounds = checkbox1; + return dialog; } @@ -393,13 +478,17 @@ function localizeUI() { en: 'Compare Scale', ja: '拡大・縮小率' }, - expanding: { - en: 'Expanding', - ja: '拡大' + item: { + en: 'Item', + ja: 'アイテム' }, - shrinking: { - en: 'Shrinking', - ja: '縮小' + horizontal: { + en: 'Horizontal:', + ja: '水平方向:' + }, + vertical: { + en: 'Vertical:', + ja: '垂直方向:' }, width: { en: 'Width:', @@ -409,13 +498,13 @@ function localizeUI() { en: 'Height:', ja: '高さ:' }, - horizontal: { - en: 'Horizontal:', - ja: '水平:' + option: { + en: 'Option', + ja: 'オプション' }, - vertical: { - en: 'Vertical:', - ja: '垂直:' + bounds: { + en: 'Use Preview Bounds', + ja: 'プレビュー境界を使用' } }; } diff --git a/scripts/fitSelectedObjectsInWindow.js b/scripts/fitSelectedObjectsInWindow.js new file mode 100755 index 0000000..054980c --- /dev/null +++ b/scripts/fitSelectedObjectsInWindow.js @@ -0,0 +1,157 @@ +/* =============================================================================================================================================== + fitSelectedObjectsInWindow + + Description + This script changes the zoom factor that the selected object fills the display. + + Usage + Select any objects, run this script from File > Scripts > Other Script... + + Notes + If no objects are selected, all objects should fit in the window. Ignore guides. + In rare cases, the script may not work if you continue to use it. + In this case, restart Illustrator and try again. + + Requirements + Illustrator CS or higher + + Version + 1.0.0 + + Homepage + github.com/sky-chaser-high/adobe-illustrator-scripts + + License + Released under the MIT license. + https://opensource.org/licenses/mit-license.php + =============================================================================================================================================== */ + +(function() { + if (app.documents.length && isValidVersion()) main(); +})(); + + +function main() { + var document = app.activeDocument; + var items = document.selection; + if (!items.length) items = getPageItems(); + if (!items.length) return; + + var bounds = getBounds(items); + var item = getItemSize(bounds); + var center = getCenterPosition(item, bounds); + + var view = document.activeView; + view.centerPoint = [center.x, center.y]; + + if (!item.width && !item.height) return; + view.zoom = 1; + + var screen = getScreenSize(view); + var zoom = getZoomFactor(item, screen); + + if ((item.height * screen.ratio) <= item.width) { + view.zoom = zoom.width; + } + else { + view.zoom = zoom.height; + } +} + + +function getZoomFactor(item, screen) { + var correction = 0.90; + return { + width: screen.width / item.width * correction, + height: screen.height / item.height * correction + }; +} + + +function getScreenSize(view) { + var bounds = view.bounds; + var x1 = bounds[0]; + var y1 = bounds[1]; + var x2 = bounds[2]; + var y2 = bounds[3]; + var width = Math.abs(x2 - x1); + var height = Math.abs(y2 - y1); + return { + width: width, + height: height, + ratio: width / height + }; +} + + +function getCenterPosition(item, bounds) { + return { + x: bounds.x1 + item.width / 2, + y: bounds.y1 - item.height / 2 + }; +} + + +function getItemSize(bounds) { + var width = Math.abs(bounds.x2 - bounds.x1); + var height = Math.abs(bounds.y2 - bounds.y1); + return { + width: width, + height: height + }; +} + + +function getBounds(items) { + var item = items[0]; + var bounds = item.visibleBounds; + if (isClipped(item)) bounds = item.pageItems[0].visibleBounds; + + var x1 = bounds[0]; + var y1 = bounds[1]; + var x2 = bounds[2]; + var y2 = bounds[3]; + + for (var i = 1; i < items.length; i++) { + item = items[i]; + bounds = item.visibleBounds; + if (isClipped(item)) bounds = item.pageItems[0].visibleBounds; + + if (bounds[0] < x1) x1 = bounds[0]; + if (bounds[1] > y1) y1 = bounds[1]; + if (bounds[2] > x2) x2 = bounds[2]; + if (bounds[3] < y2) y2 = bounds[3]; + } + + return { + x1: x1, + y1: y1, + x2: x2, + y2: y2 + }; +} + + +function isClipped(item) { + return item.typename == 'GroupItem' && item.clipped; +} + + +function getPageItems() { + var pageItems = []; + var items = app.activeDocument.pageItems; + for (var i = 0; i < items.length; i++) { + var item = items[i]; + if (item.typename == 'PathItem' && item.guides) continue; + pageItems.push(item); + } + return pageItems; +} + + +function isValidVersion() { + var cs = 11; + var aiVersion = parseInt(app.version); + if (aiVersion < cs) return false; + return true; +} diff --git a/scripts/measureDistance.js b/scripts/measureDistance.js index 661e239..9620c21 100755 --- a/scripts/measureDistance.js +++ b/scripts/measureDistance.js @@ -20,7 +20,7 @@ Illustrator CS4 or higher Version - 1.2.0 + 1.3.0 Homepage github.com/sky-chaser-high/adobe-illustrator-scripts @@ -43,17 +43,18 @@ function main() { var points = getSelectedPoints(shapes.concat(texts)); if (points.length < 2) return; - var curve = hasCurve(points); + var curve = isCurve(points); var result = measure(points, curve); - var layer = getLayer('__Distance__'); - showDimensionLine(points, curve, layer); - showDialog(result, layer); + showDimensionLine(points, curve); + app.redraw(); + + showDialog(result); } function measure(points, curve) { - var units = getUnits(app.activeDocument.rulerUnits); + var units = getRulerUnits(); var p1 = points[0]; var p2 = points[1]; @@ -96,7 +97,7 @@ function measure(points, curve) { function getCurve(points) { - var units = getUnits(app.activeDocument.rulerUnits); + var units = getRulerUnits(); var bezier = setBezier(points); var length = getCurveLength(bezier); var handle = { @@ -133,17 +134,18 @@ function getHeight(point1, point2) { function getDistance(point1, point2) { - var adjacent = point2.x - point1.x; - var opposite = point2.y - point1.y; - var hypotenuse = Math.sqrt(Math.pow(adjacent, 2) + Math.pow(opposite, 2)); - return hypotenuse; + var width = point2.x - point1.x; + var height = point2.y - point1.y; + var sq = 2; + var length = Math.sqrt(Math.pow(width, sq) + Math.pow(height, sq)); + return length; } function getAngle(point1, point2) { - var adjacent = point2.x - point1.x; - var opposite = point2.y - point1.y; - return Math.atan2(opposite, adjacent); + var width = point2.x - point1.x; + var height = point2.y - point1.y; + return Math.atan2(height, width); } @@ -151,10 +153,20 @@ function setBezier(points) { var p1 = points[0]; var p2 = points[1]; if (p1.index.point + 1 == p2.index.point) { - return [p1.anchor, p1.handle.right, p2.handle.left, p2.anchor]; + return [ + p1.anchor, + p1.handle.right, + p2.handle.left, + p2.anchor + ]; } else if (p1.index.point == 0 && p2.index.point == p2.count - 1) { - return [p2.anchor, p2.handle.right, p1.handle.left, p1.anchor]; + return [ + p1.anchor, + p1.handle.left, + p2.handle.right, + p2.anchor + ]; } } @@ -216,7 +228,7 @@ function mult(a, t) { } -function showDimensionLine(points, curve, layer) { +function showDimensionLine(points, curve) { var mode = app.activeDocument.documentColorSpace; var CMYK = DocumentColorSpace.CMYK; var color = { @@ -230,6 +242,7 @@ function showDimensionLine(points, curve, layer) { } }; + var layer = getLayer('__Distance__'); var p1 = points[0].anchor; var p2 = points[1].anchor; @@ -238,9 +251,12 @@ function showDimensionLine(points, curve, layer) { drawCircle(p1, layer, color.circle); drawCircle(p2, layer, color.circle); - drawLabel('#1', p1, p2, layer, color.label); - drawLabel('#2', p2, p1, layer, color.label); - app.redraw(); + var aiVersion = parseInt(app.version); + var ai2020 = 24; + if (ai2020 < aiVersion) { + drawLabel('#1', p1, p2, layer, color.label); + drawLabel('#2', p2, p1, layer, color.label); + } } @@ -277,11 +293,17 @@ function drawLine(points, layer, color, curve) { var width = (curve) ? 2 / view.zoom : 4 / view.zoom; var dash = (curve) ? [10 / view.zoom, 8 / view.zoom] : []; + var p1 = [ + points[0].anchor.x, + points[0].anchor.y + ]; + var p2 = [ + points[1].anchor.x, + points[1].anchor.y + ]; + var line = layer.pathItems.add(); - line.setEntirePath([ - [points[0].anchor.x, points[0].anchor.y], - [points[1].anchor.x, points[1].anchor.y] - ]); + line.setEntirePath([p1, p2]); line.filled = false; line.stroked = true; line.strokeWidth = width; @@ -293,9 +315,10 @@ function drawLine(points, layer, color, curve) { function drawCircle(point, layer, color) { var view = app.activeDocument.views[0]; var radius = 6 / view.zoom; + var diameter = radius * 2; var top = point.y + radius; var left = point.x - radius; - var circle = layer.pathItems.ellipse(top, left, radius * 2, radius * 2); + var circle = layer.pathItems.ellipse(top, left, diameter, diameter); circle.stroked = false; circle.filled = true; circle.fillColor = color; @@ -316,7 +339,7 @@ function drawLabel(contents, p1, p2, layer, color) { var stroke = 1 / view.zoom; var rad = getAngle(p1, p2); - var top = (rad >= 0) ? p1.y - margin : p1.y + margin + height; + var top = (rad < 0) ? p1.y + margin + height : p1.y - margin; var left = p1.x - (width / 2); var rect = layer.pathItems.roundedRectangle(top, left, width, height, radius, radius); @@ -335,16 +358,23 @@ function drawLabel(contents, p1, p2, layer, color) { var attributes = text.textRange.characterAttributes; attributes.size = fontsize; attributes.fillColor = color.content; - try { - attributes.textFont = app.textFonts['HelveticaNeue']; - } - catch (err) { } + + var font = getFont('HelveticaNeue'); + if (font) attributes.textFont = font; var paragraph = text.textRange.paragraphAttributes; paragraph.justification = Justification.CENTER; } +function getFont(name) { + try { + return app.textFonts[name]; + } + catch (err) { } +} + + function setCMYKColor(c, m, y, k) { var color = new CMYKColor(); color.cyan = c; @@ -364,7 +394,7 @@ function setRGBColor(r, g, b) { } -function hasCurve(points) { +function isCurve(points) { var p1 = points[0]; var p2 = points[1]; var handle = { left: false, right: false }; @@ -380,25 +410,21 @@ function hasCurve(points) { handle.right = hasHandle(p2.anchor, p2.handle.right); } - if (handle.left || handle.right) return true; - return false; + return handle.left || handle.right; } function hasHandle(anchor, handle) { - if (anchor.x == handle.x && anchor.y == handle.y) return false; - return true; + return anchor.x != handle.x || anchor.y != handle.y; } function getLayer(name) { - if (layerExists(name)) { - var layer = app.activeDocument.layers[name]; - layer.locked = false; - layer.visible = true; - return layer; - } - return createLayer(name); + if (!layerExists(name)) return createLayer(name); + var layer = app.activeDocument.layers[name]; + layer.locked = false; + layer.visible = true; + return layer; } @@ -474,13 +500,11 @@ function getPathItems(items) { function getTextPathItems() { - var AREA = TextType.AREATEXT; - var PATH = TextType.PATHTEXT; var items = []; var texts = app.activeDocument.textFrames; for (var i = 0; i < texts.length; i++) { var text = texts[i]; - if (text.selected && (text.kind == AREA || text.kind == PATH)) { + if (text.selected && text.kind != TextType.POINTTEXT) { items.push(text.textPath); } } @@ -498,15 +522,67 @@ function convertUnits(value, unit) { } -function getUnits(ruler) { - switch (ruler) { - case RulerUnits.Millimeters: return 'mm'; - case RulerUnits.Centimeters: return 'cm'; - case RulerUnits.Inches: return 'in'; - case RulerUnits.Points: return 'pt'; - case RulerUnits.Pixels: return 'px'; - default: return 'pt'; +function getRulerUnits() { + var unit = getUnitSymbol(); + if (!app.documents.length) return unit.pt; + + var document = app.activeDocument; + var src = document.fullName; + var ruler = document.rulerUnits; + try { + switch (ruler) { + case RulerUnits.Pixels: return unit.px; + case RulerUnits.Points: return unit.pt; + case RulerUnits.Picas: return unit.pc; + case RulerUnits.Inches: return unit.inch; + case RulerUnits.Millimeters: return unit.mm; + case RulerUnits.Centimeters: return unit.cm; + + case RulerUnits.Feet: return unit.ft; + case RulerUnits.Yards: return unit.yd; + case RulerUnits.Meters: return unit.meter; + } + } + catch (err) { + switch (xmpRulerUnits(src)) { + case 'Feet': return unit.ft; + case 'Yards': return unit.yd; + case 'Meters': return unit.meter; + } } + return unit.pt; +} + + +function xmpRulerUnits(src) { + if (!ExternalObject.AdobeXMPScript) { + ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); + } + var xmpFile = new XMPFile(src.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_READ); + var xmpPackets = xmpFile.getXMP(); + var xmp = new XMPMeta(xmpPackets.serialize()); + + var namespace = 'http://ns.adobe.com/xap/1.0/t/pg/'; + var prop = 'xmpTPg:MaxPageSize'; + var unit = prop + '/stDim:unit'; + + var ruler = xmp.getProperty(namespace, unit).value; + return ruler; +} + + +function getUnitSymbol() { + return { + px: 'px', + pt: 'pt', + pc: 'pc', + inch: 'in', + ft: 'ft', + yd: 'yd', + mm: 'mm', + cm: 'cm', + meter: 'm' + }; } @@ -518,10 +594,10 @@ function isValidVersion() { } -function showDialog(result, layer) { +function showDialog(result) { $.localize = true; var ui = localizeUI(); - var units = getUnits(app.activeDocument.rulerUnits); + var units = getRulerUnits(); var curve = (result.curve) ? (' [' + ui.curve + ' ' + result.curve + ' ' + units + ']') : ''; var dialog = new Window('dialog'); @@ -531,219 +607,270 @@ function showDialog(result, layer) { dialog.spacing = 10; dialog.margins = 16; - var group1 = dialog.add('group', undefined, { name: 'group1' }); - group1.orientation = 'row'; - group1.alignChildren = ['left', 'center']; - group1.spacing = 10; - group1.margins = 0; - - var panel1 = group1.add('panel', undefined, undefined, { name: 'panel1' }); - panel1.text = ui.point + ' #1'; - panel1.preferredSize.width = 160; + var panel1 = dialog.add('panel', undefined, undefined, { name: 'panel1' }); + panel1.text = ui.result; panel1.orientation = 'row'; panel1.alignChildren = ['left', 'top']; panel1.spacing = 10; panel1.margins = 10; - var group2 = panel1.add('group', undefined, { name: 'group2' }); + var group1 = panel1.add('group', undefined, { name: 'group1' }); + group1.orientation = 'row'; + group1.alignChildren = ['left', 'center']; + group1.spacing = 10; + group1.margins = [0, 8, 0, 0]; + + var group2 = group1.add('group', undefined, { name: 'group2' }); group2.orientation = 'column'; - group2.alignChildren = ['left', 'center']; + group2.alignChildren = ['right', 'center']; group2.spacing = 10; - group2.margins = [0, 8, 0, 0]; + group2.margins = 0; var statictext1 = group2.add('statictext', undefined, undefined, { name: 'statictext1' }); - statictext1.text = 'X:'; + statictext1.text = ui.distance; var statictext2 = group2.add('statictext', undefined, undefined, { name: 'statictext2' }); - statictext2.text = 'Y:'; + statictext2.text = ui.width; + + var statictext3 = group2.add('statictext', undefined, undefined, { name: 'statictext3' }); + statictext3.text = ui.height; + + var statictext4 = group2.add('statictext', undefined, undefined, { name: 'statictext4' }); + statictext4.text = ui.angle; - var group3 = panel1.add('group', undefined, { name: 'group3' }); + var group3 = group1.add('group', undefined, { name: 'group3' }); group3.orientation = 'column'; group3.alignChildren = ['left', 'center']; group3.spacing = 10; - group3.margins = [0, 8, 0, 0]; + group3.margins = 0; - var statictext3 = group3.add('statictext', undefined, undefined, { name: 'statictext3' }); - statictext3.text = result.x1 + ' ' + units; + var statictext5 = group3.add('statictext', undefined, undefined, { name: 'statictext5' }); + statictext5.text = result.distance + ' ' + units + curve; - var statictext4 = group3.add('statictext', undefined, undefined, { name: 'statictext4' }); - statictext4.text = result.y1 + ' ' + units; + var statictext6 = group3.add('statictext', undefined, undefined, { name: 'statictext6' }); + statictext6.text = result.width + ' ' + units; - var panel2 = group1.add('panel', undefined, undefined, { name: 'panel2' }); - panel2.text = ui.point + ' #2'; - panel2.preferredSize.width = 160; + var statictext7 = group3.add('statictext', undefined, undefined, { name: 'statictext7' }); + statictext7.text = result.height + ' ' + units; + + var statictext8 = group3.add('statictext', undefined, undefined, { name: 'statictext8' }); + statictext8.text = result.angle.deg + ui.deg + ' [' + result.angle.rad + ' ' + ui.rad + ']'; + + var panel2 = dialog.add('panel', undefined, undefined, { name: 'panel2' }); + panel2.text = ui.position; panel2.orientation = 'row'; panel2.alignChildren = ['left', 'top']; panel2.spacing = 10; panel2.margins = 10; var group4 = panel2.add('group', undefined, { name: 'group4' }); - group4.orientation = 'column'; + group4.orientation = 'row'; group4.alignChildren = ['left', 'center']; group4.spacing = 10; - group4.margins = [0, 8, 0, 0]; - - var statictext5 = group4.add('statictext', undefined, undefined, { name: 'statictext5' }); - statictext5.text = 'X:'; - - var statictext6 = group4.add('statictext', undefined, undefined, { name: 'statictext6' }); - statictext6.text = 'Y:'; + group4.margins = 0; - var group5 = panel2.add('group', undefined, { name: 'group5' }); + var group5 = group4.add('group', undefined, { name: 'group5' }); group5.orientation = 'column'; group5.alignChildren = ['left', 'center']; group5.spacing = 10; - group5.margins = [0, 8, 0, 0]; + group5.margins = 0; - var statictext7 = group5.add('statictext', undefined, undefined, { name: 'statictext7' }); - statictext7.text = result.x2 + ' ' + units; - - var statictext8 = group5.add('statictext', undefined, undefined, { name: 'statictext8' }); - statictext8.text = result.y2 + ' ' + units; - - var group6 = dialog.add('group', undefined, { name: 'group6' }); - group6.orientation = 'row'; + var group6 = group5.add('group', undefined, { name: 'group6' }); + group6.orientation = 'column'; group6.alignChildren = ['left', 'center']; group6.spacing = 10; - group6.margins = 0; - - var panel3 = group6.add('panel', undefined, undefined, { name: 'panel3' }); - panel3.text = ui.handle + ' #1'; - panel3.preferredSize.width = 160; - panel3.orientation = 'row'; - panel3.alignChildren = ['left', 'top']; - panel3.spacing = 10; - panel3.margins = 10; - - var group7 = panel3.add('group', undefined, { name: 'group7' }); - group7.orientation = 'column'; - group7.alignChildren = ['left', 'center']; - group7.spacing = 10; - group7.margins = [0, 8, 0, 0]; + group6.margins = [0, 8, 0, 0]; - var statictext9 = group7.add('statictext', undefined, undefined, { name: 'statictext9' }); - statictext9.text = 'X:'; + var statictext9 = group6.add('statictext', undefined, undefined, { name: 'statictext9' }); + statictext9.text = ui.point + ' #1'; - var statictext10 = group7.add('statictext', undefined, undefined, { name: 'statictext10' }); - statictext10.text = 'Y:'; + var group7 = group6.add('group', undefined, { name: 'group7' }); + group7.orientation = 'row'; + group7.alignChildren = ['left', 'center']; + group7.spacing = 10; + group7.margins = [10, 0, 0, 0]; - var group8 = panel3.add('group', undefined, { name: 'group8' }); + var group8 = group7.add('group', undefined, { name: 'group8' }); group8.orientation = 'column'; group8.alignChildren = ['left', 'center']; group8.spacing = 10; - group8.margins = [0, 8, 0, 0]; + group8.margins = 0; - var statictext11 = group8.add('statictext', undefined, undefined, { name: 'statictext11' }); - statictext11.text = (result.curve) ? (result.handle.right.x + ' ' + units) : '-'; - - var statictext12 = group8.add('statictext', undefined, undefined, { name: 'statictext12' }); - statictext12.text = (result.curve) ? (result.handle.right.y + ' ' + units) : '-'; + var statictext10 = group8.add('statictext', undefined, undefined, { name: 'statictext10' }); + statictext10.text = 'X:'; - var panel4 = group6.add('panel', undefined, undefined, { name: 'panel4' }); - panel4.text = ui.handle + ' #2'; - panel4.preferredSize.width = 160; - panel4.orientation = 'row'; - panel4.alignChildren = ['left', 'top']; - panel4.spacing = 10; - panel4.margins = 10; + var statictext11 = group8.add('statictext', undefined, undefined, { name: 'statictext11' }); + statictext11.text = 'Y:'; - var group9 = panel4.add('group', undefined, { name: 'group9' }); + var group9 = group7.add('group', undefined, { name: 'group9' }); + group9.preferredSize.width = 120; group9.orientation = 'column'; group9.alignChildren = ['left', 'center']; group9.spacing = 10; - group9.margins = [0, 8, 0, 0]; + group9.margins = 0; - var statictext13 = group9.add('statictext', undefined, undefined, { name: 'statictext13' }); - statictext13.text = 'X:'; + var statictext12 = group9.add('statictext', undefined, undefined, { name: 'statictext12' }); + statictext12.text = result.x1 + ' ' + units; - var statictext14 = group9.add('statictext', undefined, undefined, { name: 'statictext14' }); - statictext14.text = 'Y:'; + var statictext13 = group9.add('statictext', undefined, undefined, { name: 'statictext13' }); + statictext13.text = result.y1 + ' ' + units; - var group10 = panel4.add('group', undefined, { name: 'group10' }); + var group10 = group5.add('group', undefined, { name: 'group10' }); group10.orientation = 'column'; group10.alignChildren = ['left', 'center']; group10.spacing = 10; group10.margins = [0, 8, 0, 0]; - var statictext15 = group10.add('statictext', undefined, undefined, { name: 'statictext15' }); - statictext15.text = (result.curve) ? (result.handle.left.x + ' ' + units) : '-'; - - var statictext16 = group10.add('statictext', undefined, undefined, { name: 'statictext16' }); - statictext16.text = (result.curve) ? (result.handle.left.y + ' ' + units) : '-'; + var statictext14 = group10.add('statictext', undefined, undefined, { name: 'statictext14' }); + statictext14.text = ui.handle + ' #1'; - var panel5 = dialog.add('panel', undefined, undefined, { name: 'panel5' }); - panel5.text = ui.result; - panel5.orientation = 'row'; - panel5.alignChildren = ['left', 'top']; - panel5.spacing = 10; - panel5.margins = 10; - - var group11 = panel5.add('group', undefined, { name: 'group11' }); - group11.orientation = 'column'; - group11.alignChildren = ['right', 'center']; + var group11 = group10.add('group', undefined, { name: 'group11' }); + group11.orientation = 'row'; + group11.alignChildren = ['left', 'center']; group11.spacing = 10; - group11.margins = [0, 8, 0, 0]; - - var statictext17 = group11.add('statictext', undefined, undefined, { name: 'statictext17' }); - statictext17.text = ui.width; - statictext17.preferredSize.height = 18; - - var statictext18 = group11.add('statictext', undefined, undefined, { name: 'statictext18' }); - statictext18.text = ui.height; - statictext18.preferredSize.height = 18; + group11.margins = [10, 0, 0, 0]; - var statictext19 = group11.add('statictext', undefined, undefined, { name: 'statictext19' }); - statictext19.text = ui.distance; - statictext19.preferredSize.height = 18; - - var statictext20 = group11.add('statictext', undefined, undefined, { name: 'statictext20' }); - statictext20.text = ui.angle; - statictext20.preferredSize.height = 18; - - var group12 = panel5.add('group', undefined, { name: 'group12' }); + var group12 = group11.add('group', undefined, { name: 'group12' }); group12.orientation = 'column'; group12.alignChildren = ['left', 'center']; group12.spacing = 10; - group12.margins = [0, 8, 0, 0]; - - var statictext21 = group12.add('statictext', undefined, undefined, { name: 'statictext21' }); - statictext21.text = result.width + ' ' + units; - statictext21.preferredSize.height = 18; + group12.margins = 0; - var statictext22 = group12.add('statictext', undefined, undefined, { name: 'statictext22' }); - statictext22.text = result.height + ' ' + units; - statictext22.preferredSize.height = 18; + var statictext15 = group12.add('statictext', undefined, undefined, { name: 'statictext15' }); + statictext15.text = 'X:'; - var statictext23 = group12.add('statictext', undefined, undefined, { name: 'statictext23' }); - statictext23.text = result.distance + ' ' + units + curve; - statictext23.preferredSize.height = 18; + var statictext16 = group12.add('statictext', undefined, undefined, { name: 'statictext16' }); + statictext16.text = 'Y:'; - var statictext24 = group12.add('statictext', undefined, undefined, { name: 'statictext24' }); - statictext24.text = result.angle.deg + ' ' + ui.deg + ' [' + result.angle.rad + ' ' + ui.rad + ']'; - statictext24.preferredSize.height = 18; - - var group13 = dialog.add('group', undefined, { name: 'group13' }); - group13.orientation = 'row'; - group13.alignChildren = ['right', 'center']; + var group13 = group11.add('group', undefined, { name: 'group13' }); + group13.preferredSize.width = 120; + group13.orientation = 'column'; + group13.alignChildren = ['left', 'center']; group13.spacing = 10; group13.margins = 0; - var button1 = group13.add('button', undefined, undefined, { name: 'button1' }); + var statictext17 = group13.add('statictext', undefined, undefined, { name: 'statictext17' }); + statictext17.text = (result.curve) ? (result.handle.right.x + ' ' + units) : '-'; + + var statictext18 = group13.add('statictext', undefined, undefined, { name: 'statictext18' }); + statictext18.text = (result.curve) ? (result.handle.right.y + ' ' + units) : '-'; + + var group14 = group4.add('group', undefined, { name: 'group14' }); + group14.orientation = 'row'; + group14.alignChildren = ['left', 'center']; + group14.spacing = 10; + group14.margins = 0; + + var group15 = group14.add('group', undefined, { name: 'group15' }); + group15.orientation = 'column'; + group15.alignChildren = ['left', 'center']; + group15.spacing = 10; + group15.margins = 0; + + var group16 = group15.add('group', undefined, { name: 'group16' }); + group16.orientation = 'column'; + group16.alignChildren = ['left', 'center']; + group16.spacing = 10; + group16.margins = [0, 8, 0, 0]; + + var statictext19 = group16.add('statictext', undefined, undefined, { name: 'statictext19' }); + statictext19.text = ui.point + ' #2'; + + var group17 = group16.add('group', undefined, { name: 'group17' }); + group17.orientation = 'row'; + group17.alignChildren = ['left', 'center']; + group17.spacing = 10; + group17.margins = [10, 0, 0, 0]; + + var group18 = group17.add('group', undefined, { name: 'group18' }); + group18.orientation = 'column'; + group18.alignChildren = ['left', 'center']; + group18.spacing = 10; + group18.margins = 0; + + var statictext20 = group18.add('statictext', undefined, undefined, { name: 'statictext20' }); + statictext20.text = 'X:'; + + var statictext21 = group18.add('statictext', undefined, undefined, { name: 'statictext21' }); + statictext21.text = 'Y:'; + + var group19 = group17.add('group', undefined, { name: 'group19' }); + group19.preferredSize.width = 120; + group19.orientation = 'column'; + group19.alignChildren = ['left', 'center']; + group19.spacing = 10; + group19.margins = 0; + + var statictext22 = group19.add('statictext', undefined, undefined, { name: 'statictext22' }); + statictext22.text = result.x2 + ' ' + units; + + var statictext23 = group19.add('statictext', undefined, undefined, { name: 'statictext23' }); + statictext23.text = result.y2 + ' ' + units; + + var group20 = group15.add('group', undefined, { name: 'group20' }); + group20.orientation = 'column'; + group20.alignChildren = ['left', 'center']; + group20.spacing = 10; + group20.margins = [0, 8, 0, 0]; + + var statictext24 = group20.add('statictext', undefined, undefined, { name: 'statictext24' }); + statictext24.text = ui.handle + ' #2'; + + var group21 = group20.add('group', undefined, { name: 'group21' }); + group21.orientation = 'row'; + group21.alignChildren = ['left', 'center']; + group21.spacing = 10; + group21.margins = [10, 0, 0, 0]; + + var group22 = group21.add('group', undefined, { name: 'group22' }); + group22.orientation = 'column'; + group22.alignChildren = ['left', 'center']; + group22.spacing = 10; + group22.margins = 0; + + var statictext25 = group22.add('statictext', undefined, undefined, { name: 'statictext25' }); + statictext25.text = 'X:'; + + var statictext26 = group22.add('statictext', undefined, undefined, { name: 'statictext26' }); + statictext26.text = 'Y:'; + + var group23 = group21.add('group', undefined, { name: 'group23' }); + group23.preferredSize.width = 120; + group23.orientation = 'column'; + group23.alignChildren = ['left', 'center']; + group23.spacing = 10; + group23.margins = 0; + + var statictext27 = group23.add('statictext', undefined, undefined, { name: 'statictext27' }); + statictext27.text = (result.curve) ? (result.handle.left.x + ' ' + units) : '-'; + + var statictext28 = group23.add('statictext', undefined, undefined, { name: 'statictext28' }); + statictext28.text = (result.curve) ? (result.handle.left.y + ' ' + units) : '-'; + + var group24 = dialog.add('group', undefined, { name: 'group24' }); + group24.orientation = 'row'; + group24.alignChildren = ['right', 'center']; + group24.spacing = 10; + group24.margins = 0; + + var button1 = group24.add('button', undefined, undefined, { name: 'button1' }); button1.text = 'Cancel'; - button1.preferredSize.width = 90; + button1.preferredSize.width = 85; button1.hide(); - var button2 = group13.add('button', undefined, undefined, { name: 'button2' }); + var button2 = group24.add('button', undefined, undefined, { name: 'button2' }); button2.text = 'OK'; - button2.preferredSize.width = 90; + button2.preferredSize.width = 85; button1.onClick = function() { - layer.remove(); + app.undo(); + app.redraw(); dialog.close(); } button2.onClick = function() { - layer.remove(); + app.undo(); + app.redraw(); dialog.close(); } @@ -755,20 +882,20 @@ function localizeUI() { return { title: { en: 'Measure Distance', - ja: '距離を測る' - }, - point: { - en: 'Point', - ja: 'ポイント' - }, - handle: { - en: 'Handle', - ja: 'ハンドル' + ja: '距離の測定' }, result: { en: 'Result', ja: '結果' }, + distance: { + en: 'Distance:', + ja: '直線距離:' + }, + curve: { + en: 'Curve:', + ja: '曲線:' + }, width: { en: 'Width:', ja: '幅:' @@ -777,25 +904,29 @@ function localizeUI() { en: 'Height:', ja: '高さ:' }, - distance: { - en: 'Distance:', - ja: '距離:' - }, - curve: { - en: 'Curve:', - ja: '曲線:' - }, angle: { en: 'Angle:', ja: '角度:' }, deg: { - en: 'deg', - ja: '度' + en: '°', + ja: '°' }, rad: { en: 'rad', - ja: 'ラジアン' + ja: 'rad' + }, + position: { + en: 'Position', + ja: '位置' + }, + point: { + en: 'Anchor Point', + ja: 'アンカーポイント' + }, + handle: { + en: 'Handle', + ja: 'ハンドル' } }; } diff --git a/scripts/sumNumbers.js b/scripts/sumNumbers.js index 7c3f738..af9e2ee 100755 --- a/scripts/sumNumbers.js +++ b/scripts/sumNumbers.js @@ -2,22 +2,22 @@ sumNumbers Description - This script sums the numbers in text contents. + This script adds up the numbers in the text. Usage - Select text objects, run this script from File > Scripts > Other Script... - You can also recalculate using only selected items from the list. + Select text objects or specify a text range in an editing state, run this script from File > Scripts > Other Script... + You can also edit numbers in the text field and recalculate the totals. Notes - Ignore the units of value. - In rare cases, if you continue to use the script, it may not work. - In that case, restart Illustrator and try again. + Editing numbers in the text field does not affect the original text objects. + In rare cases, the script may not work if you continue to use it. + In this case, restart Illustrator and try again. Requirements Illustrator CS4 or higher Version - 1.0.0 + 2.0.0 Homepage github.com/sky-chaser-high/adobe-illustrator-scripts @@ -28,22 +28,30 @@ =============================================================================================================================================== */ (function() { - if (app.documents.length > 0 && app.activeDocument.selection.length > 0) main(); + if (app.documents.length && isValidVersion()) main(); })(); function main() { - var texts = getTextFrames(app.activeDocument.selection); + var items = app.activeDocument.selection; + var texts = getTextFrames(items); + if (!texts.length) return; + var numbers = getNumbers(texts); var total = sum(numbers); - var dialog = showResult(total, numbers); + var dialog = showDialog(total, numbers); + + dialog.list.onChanging = function() { + var list = dialog.list.text.split('\n'); + var texts = getListItems(list); + var values = getNumbers(texts); + dialog.total.text = sum(values); + } - dialog.recalc.onClick = function() { - var items = getListItems(dialog.list.items); - var numbers = getNumbers(items); - var total = sum(numbers); + dialog.reset.onClick = function() { dialog.total.text = total; + dialog.list.text = numbers.join('\n'); } dialog.show(); @@ -62,9 +70,10 @@ function sum(numbers) { function getNumbers(items) { var numbers = []; - var regex = /[+-]?[\d](\.|,)?[\d]*/g; + var regex = /-?[\d]+,?[\d]*\.?[\d]*/g; for (var i = 0; i < items.length; i++) { - var contents = items[i].contents; + var item = items[i]; + var contents = getValue(item.contents); var values = contents.match(regex); if (values) numbers = numbers.concat(values); } @@ -72,19 +81,39 @@ function getNumbers(items) { } +function getValue(text) { + var twoByteChar = /[!-~]/g; + var value = text.replace(twoByteChar, function(str) { + return String.fromCharCode(str.charCodeAt(0) - 0xFEE0); + }); + return value; +} + + function getListItems(items) { - var values = []; + var list = []; for (var i = 0; i < items.length; i++) { - if (items[i].selected) { - var contents = items[i].subItems[0].text; - values.push({ contents: contents }); - } + var item = items[i]; + list.push({ + contents: item + }); } - return values; + return list; +} + + +function isTextRange(items) { + return items.typename == 'TextRange' && items.length; +} + + +function getTextRanges(items) { + return [items]; } function getTextFrames(items) { + if (isTextRange(items)) return getTextRanges(items); var texts = []; for (var i = 0; i < items.length; i++) { var item = items[i]; @@ -99,9 +128,18 @@ function getTextFrames(items) { } -function showResult(total, numbers) { +function isValidVersion() { + var cs4 = 14; + var aiVersion = parseInt(app.version); + if (aiVersion < cs4) return false; + return true; +} + + +function showDialog(total, numbers) { $.localize = true; var ui = localizeUI(); + var dialog = new Window('dialog'); dialog.text = ui.title; dialog.preferredSize.width = 300; @@ -111,8 +149,8 @@ function showResult(total, numbers) { dialog.margins = 16; var group1 = dialog.add('group', undefined, { name: 'group1' }); - group1.orientation = 'column'; - group1.alignChildren = ['fill', 'top']; + group1.orientation = 'row'; + group1.alignChildren = ['left', 'center']; group1.spacing = 10; group1.margins = 0; @@ -121,28 +159,17 @@ function showResult(total, numbers) { var edittext1 = group1.add('edittext', undefined, undefined, { name: 'edittext1' }); edittext1.text = total; - edittext1.active = true; - - var listbox1 = group1.add('listbox', undefined, undefined, { - name: 'listbox1', - numberOfColumns: 2, - multiselect: true - }); - listbox1.preferredSize.height = 211; - - for (var i = 0; i < numbers.length; i++) { - var row = listbox1.add('item', i + 1); - row.subItems[0].text = numbers[i]; - } + edittext1.alignment = ['fill', 'center']; var group2 = dialog.add('group', undefined, { name: 'group2' }); - group2.orientation = 'row'; + group2.orientation = 'column'; group2.alignChildren = ['fill', 'center']; group2.spacing = 10; group2.margins = 0; - var statictext2 = group2.add('statictext', undefined, undefined, { name: 'statictext2', multiline: true }); - statictext2.text = ui.description; + var edittext2 = group2.add('edittext', undefined, undefined, { name: 'edittext2', multiline: true }); + edittext2.text = numbers.join('\n'); + edittext2.preferredSize.height = 220; var group3 = dialog.add('group', undefined, { name: 'group3' }); group3.orientation = 'row'; @@ -151,14 +178,12 @@ function showResult(total, numbers) { group3.margins = 0; var button1 = group3.add('button', undefined, undefined, { name: 'button1' }); - button1.text = ui.recalculation; + button1.text = ui.reset; button1.preferredSize.width = 90; - button1.preferredSize.height = 26; var button2 = group3.add('button', undefined, undefined, { name: 'button2' }); button2.text = ui.ok; button2.preferredSize.width = 90; - button2.preferredSize.height = 26; statictext1.addEventListener('click', function() { edittext1.active = false; @@ -166,8 +191,8 @@ function showResult(total, numbers) { }); dialog.total = edittext1; - dialog.list = listbox1; - dialog.recalc = button1; + dialog.list = edittext2; + dialog.reset = button1; return dialog; } @@ -175,20 +200,16 @@ function showResult(total, numbers) { function localizeUI() { return { title: { - en: 'Sum the Numbers', - ja: '数字を合計' + en: 'Sum Numbers', + ja: '数字の合計' }, total: { en: 'Total:', ja: '合計:' }, - description: { - en: 'You can also recalculate using only selected items from the list.', - ja: 'リストから選択した項目のみで再計算することもできます。' - }, - recalculation: { - en: 'Recalculate', - ja: '再計算' + reset: { + en: 'Reset', + ja: 'リセット' }, ok: { en: 'OK', diff --git a/scripts/unitCalculator.js b/scripts/unitCalculator.js new file mode 100755 index 0000000..68d2350 --- /dev/null +++ b/scripts/unitCalculator.js @@ -0,0 +1,699 @@ +/* =============================================================================================================================================== + unitCalculator + + Description + This script converts almost all units supported by Illustrator. + + Usage + 1. Run this script from File > Scripts > Other Script... + If you want to refer to an object's width or height value, select any objects with the Selection Tool and then run this script. + 2. Enter a value in one of the units. + + Notes + If the document is open, the ruler unit is the reference. + In rare cases, the script may not work if you continue to use it. + In this case, restart Illustrator and try again. + + Requirements + Illustrator CC or higher + + Version + 1.0.0 + + Homepage + github.com/sky-chaser-high/adobe-illustrator-scripts + + License + Released under the MIT license. + https://opensource.org/licenses/mit-license.php + =============================================================================================================================================== */ + +(function() { + if (isValidVersion()) main(); +})(); + + +function main() { + var index = 0; + var items = []; + if (app.documents.length) items = app.activeDocument.selection; + + var unit = getUnitSymbol(); + var dialog = showDialog(items); + + dialog.pixel.onChanging = function() { + var value = getValue(dialog.pixel.text); + var px = getUnits(value + unit.px); + showUnits(px, dialog); + } + + dialog.point.onChanging = function() { + var value = getValue(dialog.point.text); + var pt = getUnits(value + unit.pt); + showUnits(pt, dialog); + } + + dialog.pica.onChanging = function() { + var value = getValue(dialog.pica.text); + var pc = getUnits(value + unit.pc); + showUnits(pc, dialog); + } + + dialog.inch.onChanging = function() { + var value = getValue(dialog.inch.text); + var inch = getUnits(value + unit.inch); + showUnits(inch, dialog); + } + + dialog.feet.onChanging = function() { + var value = getValue(dialog.feet.text); + var ft = getUnits(value + unit.ft); + showUnits(ft, dialog); + } + + dialog.yard.onChanging = function() { + var value = getValue(dialog.yard.text); + var yd = getUnits(value + unit.yd); + showUnits(yd, dialog); + } + + dialog.millimeter.onChanging = function() { + var value = getValue(dialog.millimeter.text); + var mm = getUnits(value + unit.mm); + showUnits(mm, dialog); + } + + dialog.centimeter.onChanging = function() { + var value = getValue(dialog.centimeter.text); + var cm = getUnits(value + unit.cm); + showUnits(cm, dialog); + } + + dialog.meter.onChanging = function() { + var value = getValue(dialog.meter.text); + var meter = getUnits(value + unit.meter); + showUnits(meter, dialog); + } + + dialog.ha.onChanging = function() { + var value = getValue(dialog.ha.text); + var ha = getUnits(value + unit.ha); + showUnits(ha, dialog); + } + + dialog.useItemValue.onClick = function() { + var value, ruler; + var width = dialog.item.width; + var height = dialog.item.height; + var nextItem = dialog.nextItem; + var item = items[index]; + if (dialog.useItemValue.value) { + width.enabled = true; + height.enabled = true; + if (items.length > 1) nextItem.enabled = true; + value = width.value ? item.width : item.height; + value = getUnits(value + 'pt'); + } + else { + width.enabled = false; + height.enabled = false; + nextItem.enabled = false; + ruler = getRulerUnits(); + value = getUnits('1' + ruler); + } + showUnits(value, dialog); + } + + dialog.item.width.onClick = function() { + var item = items[index]; + var value = getUnits(item.width + 'pt'); + showUnits(value, dialog); + } + + dialog.item.height.onClick = function() { + var item = items[index]; + var value = getUnits(item.height + 'pt'); + showUnits(value, dialog); + } + + dialog.item.previous.onClick = function() { + index -= 1; + if (index < 0) index = items.length - 1; + var item = items[index]; + var width = dialog.item.width; + var value = width.value ? item.width : item.height; + value = getUnits(value + 'pt'); + showUnits(value, dialog); + } + + dialog.item.next.onClick = function() { + index += 1; + if (items.length - 1 < index) index = 0; + var item = items[index]; + var width = dialog.item.width; + var value = width.value ? item.width : item.height; + value = getUnits(value + 'pt'); + showUnits(value, dialog); + } + + dialog.show(); +} + + +function showUnits(value, dialog) { + dialog.pixel.text = value.px; + dialog.point.text = value.pt; + dialog.pica.text = value.pc; + dialog.inch.text = value.inch; + dialog.feet.text = value.ft; + dialog.yard.text = value.yd; + dialog.millimeter.text = value.mm; + dialog.centimeter.text = value.cm; + dialog.meter.text = value.meter; + dialog.ha.text = value.ha; +} + + +function getUnits(value) { + var unit = getUnitSymbol(); + return { + px: convertUnits(value, unit.px), + pt: convertUnits(value, unit.pt), + pc: convertUnits(value, unit.pc), + inch: convertUnits(value, unit.inch), + ft: convertUnits(value, unit.ft), + yd: convertUnits(value, unit.yd), + mm: convertUnits(value, unit.mm), + cm: convertUnits(value, unit.cm), + meter: convertUnits(value, unit.meter), + ha: convertToHa(value) + }; +} + + +function getValue(text) { + var twoByteChar = /[!-~]/g; + var value = text.replace(twoByteChar, function(str) { + return String.fromCharCode(str.charCodeAt(0) - 0xFEE0); + }); + if (isNaN(value) || !value) return 0; + return Number(value); +} + + +function convertToHa(value) { + var mm = convertUnits(value, 'mm'); + var ha = 4; + return mm * ha; +} + + +function convertHaToMillimeter(value) { + var regex = /H$/; + value = value.replace(regex, ''); + var ha = 4; + var mm = Number(value) / ha; + return mm + 'mm'; +} + + +function convertUnits(value, unit) { + if (/H$/.test(value)) value = convertHaToMillimeter(value); + try { + return Number(UnitValue(value).as(unit)); + } + catch (err) { + return Number(UnitValue('0pt').as('pt')); + } +} + + +function getRulerUnits() { + var unit = getUnitSymbol(); + if (!app.documents.length) return unit.pt; + + var document = app.activeDocument; + var src = document.fullName; + var ruler = document.rulerUnits; + try { + switch (ruler) { + case RulerUnits.Pixels: return unit.px; + case RulerUnits.Points: return unit.pt; + case RulerUnits.Picas: return unit.pc; + case RulerUnits.Inches: return unit.inch; + case RulerUnits.Millimeters: return unit.mm; + case RulerUnits.Centimeters: return unit.cm; + case RulerUnits.Qs: return unit.ha; + + case RulerUnits.Feet: return unit.ft; + case RulerUnits.Yards: return unit.yd; + case RulerUnits.Meters: return unit.meter; + } + } + catch (err) { + switch (xmpRulerUnits(src)) { + case 'Feet': return unit.ft; + case 'Yards': return unit.yd; + case 'Meters': return unit.meter; + } + } + return unit.pt; +} + + +function xmpRulerUnits(src) { + if (!ExternalObject.AdobeXMPScript) { + ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); + } + var xmpFile = new XMPFile(src.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_READ); + var xmpPackets = xmpFile.getXMP(); + var xmp = new XMPMeta(xmpPackets.serialize()); + + var namespace = 'http://ns.adobe.com/xap/1.0/t/pg/'; + var prop = 'xmpTPg:MaxPageSize'; + var unit = prop + '/stDim:unit'; + + var ruler = xmp.getProperty(namespace, unit).value; + return ruler; +} + + +function getUnitSymbol() { + return { + px: 'px', + pt: 'pt', + pc: 'pc', + inch: 'in', + ft: 'ft', + yd: 'yd', + mm: 'mm', + cm: 'cm', + meter: 'm', + ha: 'H' + }; +} + + +function isValidVersion() { + var cc = 17; + var aiVersion = parseInt(app.version); + if (aiVersion < cc) return false; + return true; +} + + +function showDialog(items) { + $.localize = true; + var ui = localizeUI(); + var unit = getUnitSymbol(); + var ruler = getRulerUnits(); + var value = '1' + ruler; + + var dialog = new Window('dialog'); + dialog.text = ui.title; + dialog.orientation = 'column'; + dialog.alignChildren = ['fill', 'top']; + dialog.spacing = 10; + dialog.margins = 16; + + var group1 = dialog.add('group', undefined, { name: 'group1' }); + group1.orientation = 'row'; + group1.alignChildren = ['fill', 'center']; + group1.spacing = 10; + group1.margins = [0, 0, 0, 8]; + + var group2 = group1.add('group', undefined, { name: 'group2' }); + group2.orientation = 'column'; + group2.alignChildren = ['right', 'center']; + group2.spacing = 18; + group2.margins = 0; + group2.alignment = ['left', 'center']; + + var statictext1 = group2.add('statictext', undefined, undefined, { name: 'statictext1' }); + statictext1.text = ui.px; + + var statictext2 = group2.add('statictext', undefined, undefined, { name: 'statictext2' }); + statictext2.text = ui.pt; + + var statictext3 = group2.add('statictext', undefined, undefined, { name: 'statictext3' }); + statictext3.text = ui.pc; + + var statictext4 = group2.add('statictext', undefined, undefined, { name: 'statictext4' }); + statictext4.text = ui.inch; + + var statictext5 = group2.add('statictext', undefined, undefined, { name: 'statictext5' }); + statictext5.text = ui.ft; + + var statictext6 = group2.add('statictext', undefined, undefined, { name: 'statictext6' }); + statictext6.text = ui.yd; + + var statictext7 = group2.add('statictext', undefined, undefined, { name: 'statictext7' }); + statictext7.text = ui.mm; + + var statictext8 = group2.add('statictext', undefined, undefined, { name: 'statictext8' }); + statictext8.text = ui.cm; + + var statictext9 = group2.add('statictext', undefined, undefined, { name: 'statictext9' }); + statictext9.text = ui.meter; + + var statictext10 = group2.add('statictext', undefined, undefined, { name: 'statictext10' }); + statictext10.text = ui.ha; + if ($.locale != 'ja_JP') statictext10.visible = false; + + var group3 = group1.add('group', undefined, { name: 'group3' }); + group3.orientation = 'column'; + group3.alignChildren = ['fill', 'center']; + group3.spacing = 10; + group3.margins = 0; + group3.alignment = ['fill', 'center']; + + var edittext1 = group3.add('edittext', undefined, undefined, { name: unit.px }); + edittext1.text = convertUnits(value, unit.px); + edittext1.preferredSize.width = 150; + if (ruler == unit.px) edittext1.active = true; + + var edittext2 = group3.add('edittext', undefined, undefined, { name: unit.pt }); + edittext2.text = convertUnits(value, unit.pt); + edittext2.preferredSize.width = 150; + if (ruler == unit.pt) edittext2.active = true; + + var edittext3 = group3.add('edittext', undefined, undefined, { name: unit.pc }); + edittext3.text = convertUnits(value, unit.pc); + edittext3.preferredSize.width = 150; + if (ruler == unit.pc) edittext3.active = true; + + var edittext4 = group3.add('edittext', undefined, undefined, { name: unit.inch }); + edittext4.text = convertUnits(value, unit.inch); + edittext4.preferredSize.width = 150; + if (ruler == unit.inch) edittext4.active = true; + + var edittext5 = group3.add('edittext', undefined, undefined, { name: unit.ft }); + edittext5.text = convertUnits(value, unit.ft); + edittext5.preferredSize.width = 150; + if (ruler == unit.ft) edittext5.active = true; + + var edittext6 = group3.add('edittext', undefined, undefined, { name: unit.yd }); + edittext6.text = convertUnits(value, unit.yd); + edittext6.preferredSize.width = 150; + if (ruler == unit.yd) edittext6.active = true; + + var edittext7 = group3.add('edittext', undefined, undefined, { name: unit.mm }); + edittext7.text = convertUnits(value, unit.mm); + edittext7.preferredSize.width = 150; + if (ruler == unit.mm) edittext7.active = true; + + var edittext8 = group3.add('edittext', undefined, undefined, { name: unit.cm }); + edittext8.text = convertUnits(value, unit.cm); + edittext8.preferredSize.width = 150; + if (ruler == unit.cm) edittext8.active = true; + + var edittext9 = group3.add('edittext', undefined, undefined, { name: unit.meter }); + edittext9.text = convertUnits(value, unit.meter); + edittext9.preferredSize.width = 150; + if (ruler == unit.meter) edittext9.active = true; + + var edittext10 = group3.add('edittext', undefined, undefined, { name: unit.ha }); + edittext10.text = convertToHa(value); + edittext10.preferredSize.width = 150; + if (ruler == unit.ha) edittext10.active = true; + if ($.locale != 'ja_JP') edittext10.visible = false; + + var group4 = group1.add('group', undefined, { name: 'group4' }); + group4.orientation = 'column'; + group4.alignChildren = ['left', 'center']; + group4.spacing = 18; + group4.margins = 0; + group4.alignment = ['right', 'center']; + + var statictext11 = group4.add('statictext', undefined, undefined, { name: 'statictext11' }); + statictext11.text = unit.px; + + var statictext12 = group4.add('statictext', undefined, undefined, { name: 'statictext12' }); + statictext12.text = unit.pt; + + var statictext13 = group4.add('statictext', undefined, undefined, { name: 'statictext13' }); + statictext13.text = unit.pc; + + var statictext14 = group4.add('statictext', undefined, undefined, { name: 'statictext14' }); + statictext14.text = unit.inch; + + var statictext15 = group4.add('statictext', undefined, undefined, { name: 'statictext15' }); + statictext15.text = unit.ft; + + var statictext16 = group4.add('statictext', undefined, undefined, { name: 'statictext16' }); + statictext16.text = unit.yd; + + var statictext17 = group4.add('statictext', undefined, undefined, { name: 'statictext17' }); + statictext17.text = unit.mm; + + var statictext18 = group4.add('statictext', undefined, undefined, { name: 'statictext18' }); + statictext18.text = unit.cm; + + var statictext19 = group4.add('statictext', undefined, undefined, { name: 'statictext19' }); + statictext19.text = unit.meter; + + var statictext20 = group4.add('statictext', undefined, undefined, { name: 'statictext20' }); + statictext20.text = unit.ha; + if ($.locale != 'ja_JP') statictext20.visible = false; + + var panel1 = dialog.add('panel', undefined, undefined, { name: 'panel1' }); + panel1.text = ui.option; + panel1.orientation = 'column'; + panel1.alignChildren = ['left', 'top']; + panel1.spacing = 10; + panel1.margins = 10; + + var group5 = panel1.add('group', undefined, { name: 'group5' }); + group5.orientation = 'column'; + group5.alignChildren = ['left', 'center']; + group5.spacing = 10; + group5.margins = [0, 10, 0, 0]; + + var group6 = group5.add('group', undefined, { name: 'group6' }); + group6.orientation = 'row'; + group6.alignChildren = ['left', 'center']; + group6.spacing = 10; + group6.margins = 0; + + var checkbox1 = group6.add('checkbox', undefined, undefined, { name: 'checkbox1' }); + checkbox1.text = ui.useItemValue; + if (!items.length) checkbox1.enabled = false; + + var radiobutton1 = group6.add('radiobutton', undefined, undefined, { name: 'radiobutton1' }); + radiobutton1.text = ui.width; + radiobutton1.value = true; + radiobutton1.enabled = false; + + var radiobutton2 = group6.add('radiobutton', undefined, undefined, { name: 'radiobutton2' }); + radiobutton2.text = ui.height; + radiobutton2.enabled = false; + + var group7 = group5.add('group', undefined, { name: 'group7' }); + group7.orientation = 'row'; + group7.alignChildren = ['left', 'center']; + group7.spacing = 10; + group7.margins = 0; + group7.enabled = false; + + var statictext21 = group7.add('statictext', undefined, undefined, { name: 'statictext21' }); + statictext21.text = ui.selectedObject; + + var button1 = group7.add('button', undefined, undefined, { name: 'button1' }); + button1.text = '←'; + button1.preferredSize.width = 40; + button1.preferredSize.height = 20; + + var button2 = group7.add('button', undefined, undefined, { name: 'button2' }); + button2.text = '→'; + button2.preferredSize.width = 40; + button2.preferredSize.height = 20; + + var group8 = dialog.add('group', undefined, { name: 'group8' }); + group8.orientation = 'row'; + group8.alignChildren = ['right', 'center']; + group8.spacing = 10; + group8.margins = 0; + + var button3 = group8.add('button', undefined, undefined, { name: 'button3' }); + button3.text = ui.ok; + button3.preferredSize.width = 90; + + statictext1.addEventListener('click', function() { + edittext1.active = false; + edittext1.active = true; + }); + + statictext2.addEventListener('click', function() { + edittext2.active = false; + edittext2.active = true; + }); + + statictext3.addEventListener('click', function() { + edittext3.active = false; + edittext3.active = true; + }); + + statictext4.addEventListener('click', function() { + edittext4.active = false; + edittext4.active = true; + }); + + statictext5.addEventListener('click', function() { + edittext5.active = false; + edittext5.active = true; + }); + + statictext6.addEventListener('click', function() { + edittext6.active = false; + edittext6.active = true; + }); + + statictext7.addEventListener('click', function() { + edittext7.active = false; + edittext7.active = true; + }); + + statictext8.addEventListener('click', function() { + edittext8.active = false; + edittext8.active = true; + }); + + statictext9.addEventListener('click', function() { + edittext9.active = false; + edittext9.active = true; + }); + + statictext10.addEventListener('click', function() { + edittext10.active = false; + edittext10.active = true; + }); + + dialog.pixel = edittext1; + dialog.point = edittext2; + dialog.pica = edittext3; + dialog.inch = edittext4; + dialog.feet = edittext5; + dialog.yard = edittext6; + dialog.millimeter = edittext7; + dialog.centimeter = edittext8; + dialog.meter = edittext9; + dialog.ha = edittext10; + + dialog.useItemValue = checkbox1; + dialog.nextItem = group7; + dialog.item = { + width: radiobutton1, + height: radiobutton2, + previous: button1, + next: button2 + }; + + edittext1.addEventListener('keydown', setIncreaseDecrease); + edittext2.addEventListener('keydown', setIncreaseDecrease); + edittext3.addEventListener('keydown', setIncreaseDecrease); + edittext4.addEventListener('keydown', setIncreaseDecrease); + edittext5.addEventListener('keydown', setIncreaseDecrease); + edittext6.addEventListener('keydown', setIncreaseDecrease); + edittext7.addEventListener('keydown', setIncreaseDecrease); + edittext8.addEventListener('keydown', setIncreaseDecrease); + edittext9.addEventListener('keydown', setIncreaseDecrease); + edittext10.addEventListener('keydown', setIncreaseDecrease); + return dialog; +} + + +function setIncreaseDecrease(event) { + var dialog = event.target.window; + var ruler = event.target.properties.name; + var value = getValue(event.target.text); + var keyboard = ScriptUI.environment.keyboardState; + var step = keyboard.shiftKey ? 5 : 1; + if (event.keyName == 'Up') { + value += step; + event.preventDefault(); + } + if (event.keyName == 'Down') { + value -= step; + event.preventDefault(); + } + var unit = getUnits(value + ruler); + showUnits(unit, dialog); +} + + +function localizeUI() { + return { + title: { + en: 'Unit Calculator', + ja: '単位を換算' + }, + px: { + en: 'Pixels:', + ja: 'ピクセル:' + }, + pt: { + en: 'Points:', + ja: 'ポイント:' + }, + pc: { + en: 'Picas:', + ja: 'パイカ:' + }, + inch: { + en: 'Inches:', + ja: 'インチ:' + }, + ft: { + en: 'Feet:', + ja: 'フィート:' + }, + yd: { + en: 'Yards:', + ja: 'ヤード:' + }, + mm: { + en: 'Millimeters:', + ja: 'ミリメートル:' + }, + cm: { + en: 'Centimeters:', + ja: 'センチメートル:' + }, + meter: { + en: 'Meters:', + ja: 'メートル:' + }, + ha: { + en: 'H:', + ja: '歯:' + }, + option: { + en: 'Option', + ja: 'オプション' + }, + useItemValue: { + en: 'Use Selected Object Value', + ja: '選択オブジェクトの数値を使用' + }, + width: { + en: 'Width', + ja: '幅' + }, + height: { + en: 'Height', + ja: '高さ' + }, + selectedObject: { + en: 'Next Object:', + ja: '次のオブジェクト:' + }, + cancel: { + en: 'Cancel', + ja: 'キャンセル' + }, + ok: { + en: 'OK', + ja: 'OK' + } + }; +}