Created
October 11, 2025 14:26
-
-
Save Yamonov/097922c94e06c22428ba4665c899bdc6 to your computer and use it in GitHub Desktop.
Photoshopブラシまわりスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| <javascriptresource> | |
| <category>YPresets</category> | |
| </javascriptresource> | |
| */ | |
| // ファイル名を変えることで、 | |
| // ブラシ不透明度、流量を直接指定したりプラス、マイナスするスクリプト | |
| // OpacityFlowExposure_F-.jsx Flow(流量)をマイナス | |
| // OpacityFlowExposure_O+.jsx Opacity(不透明度)をプラス | |
| // OpacityFlowExposure_F15.jsx 流量を15に | |
| // 必要なだけコピーしてファイル名を変えてください。 | |
| // ファイル名から引数を解析する処理 | |
| var fileName = $.fileName; // スクリプト自身のファイル名を取得 | |
| var baseName = fileName.substring(fileName.lastIndexOf("/") + 1); // パス部分を除去 | |
| var commandPart = baseName.substring("OpacityFlowExposure_".length, baseName.lastIndexOf(".")); | |
| // プロパティの略称をフルネームに変換するマッピング | |
| var propMap = { "O": "opacity", "F": "flow" }; | |
| var PropertyLetter = commandPart.charAt(0); // 例:"O" または "F" | |
| var SetValue = commandPart.substring(1); // 例:"+"、"15"、"-" | |
| var Property = propMap[PropertyLetter]; // 例:"opacity" または "flow" | |
| // キャッシュ:頻繁に呼び出すID変換結果 | |
| var idPercentUnit = stringIDToTypeID("percentUnit"); | |
| var idNull = charIDToTypeID("null"); | |
| var idT = charIDToTypeID("T "); | |
| var idOrdn = charIDToTypeID("Ordn"); | |
| var idProperty = stringIDToTypeID("property"); | |
| var idTool = stringIDToTypeID("tool"); | |
| var idCapp = charIDToTypeID("capp"); | |
| var idTrgt = charIDToTypeID("Trgt"); | |
| var idSet = stringIDToTypeID("set"); | |
| var idExposure = stringIDToTypeID("exposure"); | |
| // 許可された段階的な値リスト(必ず昇順) | |
| var valueSteps = [2,4,6,8,10,12,14,16,20,30,40,50,60,70,80,90,100]; | |
| var currentTool = app.currentTool; // 現在選択されているツールを取得 | |
| // 関数: 現在の値に基づき、次のステップ値を返す(二分探索利用) | |
| // direction > 0: 現在値より大きい最小の値、direction < 0: 現在値より小さい最大の値 | |
| function getNextStepValue(current, direction) { | |
| var low = 0, high = valueSteps.length - 1; | |
| var result = current; | |
| if (direction > 0) { | |
| while (low <= high) { | |
| var mid = Math.floor((low + high) / 2); | |
| if (valueSteps[mid] > current) { | |
| result = valueSteps[mid]; | |
| high = mid - 1; | |
| } else { | |
| low = mid + 1; | |
| } | |
| } | |
| } else { | |
| while (low <= high) { | |
| var mid = Math.floor((low + high) / 2); | |
| if (valueSteps[mid] < current) { | |
| result = valueSteps[mid]; | |
| low = mid + 1; | |
| } else { | |
| high = mid - 1; | |
| } | |
| } | |
| } | |
| return result; | |
| } | |
| // 関数: 指定したプロパティIDに対して値を設定する共通関数 | |
| function setToolProperty(toolRef, options, propertyID, value) { | |
| var actDsc = new ActionDescriptor(); | |
| var subActRef = new ActionReference(); | |
| subActRef.putClass(toolRef); | |
| actDsc.putReference(idNull, subActRef); | |
| options.putUnitDouble(propertyID, idPercentUnit, value); | |
| actDsc.putObject(idT, idOrdn, options); | |
| executeAction(idSet, actDsc, DialogModes.NO); | |
| } | |
| // 関数: 現在値を取得し、次の値を計算して設定する処理 | |
| function processToolProperty(propertyID) { | |
| var curValue = curOpts.getUnitDoubleValue(propertyID); | |
| var targetValue = resolveTargetValue(curValue, SetValue); | |
| setToolProperty(curTool, curOpts, propertyID, targetValue); | |
| } | |
| try { | |
| // 現在のツールオプション取得の準備 | |
| var actRef = new ActionReference(); | |
| actRef.putProperty(idProperty, idTool); | |
| actRef.putEnumerated(idCapp, idOrdn, idTrgt); | |
| var actionGet = executeActionGet(actRef); | |
| var curOpts = actionGet.getObjectValue(stringIDToTypeID("currentToolOptions")); | |
| var curTool = actionGet.getEnumerationType(idTool); | |
| // 関数: 入力値に基づき最終的に設定する値を決定 | |
| function resolveTargetValue(current, inputValue) { | |
| if (inputValue === '+') return getNextStepValue(current, 1); | |
| if (inputValue === '-') return getNextStepValue(current, -1); | |
| return parseFloat(inputValue); | |
| } | |
| // 覆い焼き・焼き込みツールの場合は常に露光量、それ以外は指定プロパティ | |
| var targetPropID = (currentTool === 'dodgeTool' || currentTool === 'burnInTool') | |
| ? idExposure | |
| : stringIDToTypeID(Property); | |
| processToolProperty(targetPropID); | |
| } catch (err) { | |
| $.writeln("Error: " + err.message); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #target photoshop | |
| /* | |
| <javascriptresource> | |
| <name>ブラシサイズを画面上の指定pxに変更</name> | |
| <category>YPresets</category> | |
| </javascriptresource> | |
| */ | |
| (function () { | |
| // 画面上で見えるブラシサイズ(px) | |
| var TARGET_SCREEN_SIZE = 150; | |
| // ブラシ未対応ツールの場合は終了 | |
| if (!app.toolSupportsBrushes(app.currentTool)) return; | |
| // ズームレベルを取得し、直径を計算(最大5000pxに制限) | |
| var zoom = getZoomLevel(); | |
| var newDiameter = Math.min(5000, Math.round(TARGET_SCREEN_SIZE / (zoom / 100))); | |
| // 計算したサイズを、ブラシの masterDiameter に直接設定 | |
| setBrushDiameter(newDiameter); | |
| // ズームレベルを取得 | |
| function getZoomLevel() { | |
| var ref = new ActionReference(); | |
| ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom")); | |
| ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); | |
| var desc = executeActionGet(ref); | |
| return desc.getDouble(stringIDToTypeID("zoom")) * 100; | |
| } | |
| // masterDiameter を直接設定(他のブラシ設定は変更しない) | |
| function setBrushDiameter(diameter) { | |
| var idSet = stringIDToTypeID("set"); | |
| var desc = new ActionDescriptor(); | |
| var ref = new ActionReference(); | |
| var idBrush = stringIDToTypeID("brush"); | |
| var idOrdinal = stringIDToTypeID("ordinal"); | |
| var idTargetEnum = stringIDToTypeID("targetEnum"); | |
| ref.putEnumerated(idBrush, idOrdinal, idTargetEnum); | |
| desc.putReference(stringIDToTypeID("null"), ref); | |
| var brushDesc = new ActionDescriptor(); | |
| brushDesc.putUnitDouble(stringIDToTypeID("masterDiameter"), stringIDToTypeID("pixelsUnit"), diameter); | |
| desc.putObject(stringIDToTypeID("to"), idBrush, brushDesc); | |
| executeAction(idSet, desc, DialogModes.NO); | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #target photoshop | |
| /* | |
| <javascriptresource> | |
| <name>ブラシサイズ変更と初期ブラシに戻す</name> | |
| <category>YPresets</category> | |
| </javascriptresource> | |
| */ | |
| (function () { | |
| // 画面上で見えるブラシサイズ(px) | |
| var TARGET_SCREEN_SIZE = 150; | |
| var originalTool = app.currentTool; | |
| // ブラシ未対応ツールの場合は終了 | |
| if (!app.toolSupportsBrushes(app.currentTool)) return; | |
| // 最初のブラシプリセットに戻す | |
| selectFirstBrush(); | |
| // ズームレベルを取得し、直径を計算(最大5000pxに制限) | |
| var zoom = getZoomLevel(); | |
| var newDiameter = Math.min(5000, Math.round(TARGET_SCREEN_SIZE / (zoom / 100))); | |
| // masterDiameter を直接設定(他のブラシ設定は変更しない) | |
| setBrushDiameter(newDiameter); | |
| // --- 関数定義 --- | |
| // ズームレベル取得関数 | |
| function getZoomLevel() { | |
| var ref = new ActionReference(); | |
| ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom")); | |
| ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); | |
| var desc = executeActionGet(ref); | |
| return desc.getDouble(stringIDToTypeID("zoom")) * 100; | |
| } | |
| // masterDiameter を直接設定する関数 | |
| function setBrushDiameter(diameter) { | |
| var idSet = stringIDToTypeID("set"); | |
| var desc = new ActionDescriptor(); | |
| var ref = new ActionReference(); | |
| var idBrush = stringIDToTypeID("brush"); | |
| var idOrdinal = stringIDToTypeID("ordinal"); | |
| var idTargetEnum = stringIDToTypeID("targetEnum"); | |
| ref.putEnumerated(idBrush, idOrdinal, idTargetEnum); | |
| desc.putReference(stringIDToTypeID("null"), ref); | |
| var brushDesc = new ActionDescriptor(); | |
| brushDesc.putUnitDouble(stringIDToTypeID("masterDiameter"), stringIDToTypeID("pixelsUnit"), diameter); | |
| desc.putObject(stringIDToTypeID("to"), idBrush, brushDesc); | |
| executeAction(idSet, desc, DialogModes.NO); | |
| } | |
| // 最初のブラシプリセットを選択する関数 | |
| function selectFirstBrush() { | |
| var ref = new ActionReference(); | |
| ref.putIndex(stringIDToTypeID("brush"), 1); | |
| var desc = new ActionDescriptor(); | |
| desc.putReference(charIDToTypeID("null"), ref); | |
| executeAction(stringIDToTypeID("select"), desc, DialogModes.NO); | |
| } | |
| if (app.currentTool !== originalTool) { | |
| app.currentTool = originalTool; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment