Skip to main content
Participating Frequently
September 14, 2023
Question

Photoshop アートボード名を文字列から一括入力

  • September 14, 2023
  • 4 replies
  • 2201 views

Photoshop 24.5.0にて、

(投稿者使用:MacBook Pro (Retina, 13-inch, Late 2013)、macOS Big Sur ver 11.7.8)

アートボード名を文字列から一括で入力できるスクリプトを探しています。

 

例えば

A

B

C

という文字列から「A」「B」「C」と名前のついたアートボードを一括作成するスクリプト

もしくは

新規作成したアートボード3つ(「アートボード1」「アートボード2」「アートボード3」)の

名前を一括で「A」「B」「C」に変更するスクリプト

 

大量のアートボード名を変更する必要があるため、

ぜひお力いただきたいです。

よろしくお願いいたします。

This topic has been closed for replies.

4 replies

gjioseh
Participating Frequently
August 7, 2024

おはようございます。

長らく時間があいてしまいましたが、その後どうでしょう?

やっとPhotoshopが使える状態になったので、ちょっと続きをやってみました。

Numbersで列方向のセルにたとえば、「A」「B」「C」と入力して、入力したところを選択し

Photoshopで新規ドキュメントを開いた状態で、下記スクリプトを実行するとアートボードが作成されると思いますが如何なものでしょう。

アートボードのサイズは、新規ドキュメントを作成したときの大きさを取得してます。

完璧なものではないと思いますが、何かの役に立てば...

 

use AppleScript version "2.4"

use framework "Foundation"

use scripting additions

 

tell application "Numbers"

tell front document

tell active sheet

try

set theTable to first table whose class of selection range is range

on error

beep

display alert "何も選択されていません。"

return --何も選択されてなかった場合は終了

end try

 

tell theTable

set selList to value of (every cell of selection range)

set columnCount to count of (column of selection range) --列をカウント

if columnCount > 1 then

beep

display alert "2列以上選択されています。1列のみ選択してください。"

return

end if

end tell

end tell

end tell

end tell

 

set aList to {}

repeat with i in selList

set ii to contents of i

if ii is not missing value then --空白を除外

log ii

set the end of aList to ii

end if

end repeat

--set |strings| to retDelimedText(aList, ",") of me --文字列として処理する場合

 

if application id "com.adobe.Photoshop" is running then

tell application id "com.adobe.Photoshop"

if exists front document then

tell front document

try

 

--Photoshopでの処理をここに

do javascript "

var dimensions = [app.activeDocument.width.value,app.activeDocument.height.value];

var bottom = dimensions[1];

var left = 0.000000;

var right = dimensions[0];

 

for (var i = 0;i < arguments.length; i++) {

//alert(arguments[i]);

var idmake = stringIDToTypeID( \"make\" );

    var desc66 = new ActionDescriptor();

    var idnull = stringIDToTypeID( \"null\" );

        var ref13 = new ActionReference();

        var idartboardSection = stringIDToTypeID( \"artboardSection\" );

        ref13.putClass( idartboardSection );

    desc66.putReference( idnull, ref13 );

    var idusing = stringIDToTypeID( \"using\" );

        var desc67 = new ActionDescriptor();

        var idname = stringIDToTypeID( \"name\" );

        desc67.putString( idname, arguments[i] );

    var idartboardSection = stringIDToTypeID( \"artboardSection\" );

    desc66.putObject( idusing, idartboardSection, desc67 );

    var idlayerSectionStart = stringIDToTypeID( \"layerSectionStart\" );

    desc66.putInteger( idlayerSectionStart, 6 );

    var idlayerSectionEnd = stringIDToTypeID( \"layerSectionEnd\" );

    desc66.putInteger( idlayerSectionEnd, 7 );

    var idname = stringIDToTypeID( \"name\" );

    desc66.putString( idname, \"\"\"アートボード 1\"\"\" );

    var idartboardRect = stringIDToTypeID( \"artboardRect\" );

        var desc68 = new ActionDescriptor();

        var idtop = stringIDToTypeID( \"top\" );

        desc68.putDouble( idtop, 0.000000 );

        var idleft = stringIDToTypeID( \"left\" );

        desc68.putDouble( idleft, left );

        var idbottom = stringIDToTypeID( \"bottom\" );

        desc68.putDouble( idbottom, bottom );

        var idright = stringIDToTypeID( \"right\" );

        desc68.putDouble( idright, right );

    var idclassFloatRect = stringIDToTypeID( \"classFloatRect\" );

    desc66.putObject( idartboardRect, idclassFloatRect, desc68 );

executeAction( idmake, desc66, DialogModes.NO );

left = right + 100;

}

" with arguments aList --リストを引数として

 

--データを文字列として処理する場合。こんな感じ??

(*

do javascript "

var array = " & (quoted form of |strings|) & ".split(',');

for (var i = 0;i < array.length; i++) {

alert(array[i]);

}

"

*)

 

 

on error msg

return msg

end try

end tell

end if

end tell

end if

 

 

 

-- 数字を削除。このように使う。

--regexReplace("1あ1いうえお0123", "\\d", "") of me

--return regexReplace("1あ1いうえお0123", "[0-9-]", "") of me

 

--正規表現を使ってテキストを置き換えするときに使うハンドラ

on regexReplace(aText as text, pattern as text, replacement as text)

--require framework: Foundation

set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|😞missing value)

return (regularExpression's stringByReplacingMatchesInString:aText options:0 range:{location:0, |length|:count aText} withTemplate:replacement) as text

end regexReplace

 

--リストを入力し、指定の区切り文字で区切ったテキストを返すハンドラ

on retDelimedText(aList, aDelim)

set aText to ""

set curDelim to AppleScript's text item delimiters

set AppleScript's text item delimiters to aDelim

set aText to aList as text

set AppleScript's text item delimiters to curDelim

return aText

end retDelimedText

 

 

gjioseh
Participating Frequently
August 7, 2024

コードの一部が絵文字になってしまった..

これなら??

https://drive.google.com/uc?export=view&id=19RdaSNLxGvLSi2O6416INsF-MiCgwyAD 

ReeeeeiAuthor
Participating Frequently
August 8, 2024

おはようございます。

実の所、少々諦めモードになっておりました...

 

gjiosehさんに今回いただいたスクリプト実行してみたところ、

うまくいきました...!

感動しています...作業時間が大幅に削減できそうです!

 

今回のトピックに参加してくださったみなさんに感謝申し上げます。

本当にありがとうございました。

 

gjioseh
Participating Frequently
September 14, 2023

すみません。何か操作誤ってダブって投稿されてしまいました...

ajabon grinsmith
Community Expert
Community Expert
September 15, 2023

@gjioseh さん

最新のものを残して重複投稿を片付けました。また、残った投稿に、はじめのほうの投稿に貼られていたスクリーンショットを移植させていただきました。

不都合な点があればおっしゃってくださいませ。

gjioseh
Participating Frequently
September 15, 2023

ありがとうございます。

スッキリしました!(感謝)

 

スクリプトのソース 

gjioseh
Participating Frequently
September 14, 2023

下記はNumbersで選択したひとつの列からデータを取り出し、Photoshopへ渡すことができるかもしれないAppleScriptです。
ちょっと歯切れが悪いですが、私の環境では現状Photoshopが使えなくて動作確認およびコードの作成ができません。
どなたか作ってくださると.....

 

下記スクリプトとしては、Numbersでひとつの列にデータを書き込んでおき、その列を選択、実行するとスクリプト内の変数「ii」にリピートでデータが順に一つずつ入ります。
その変数を使ってそれをPhotoshopへ渡し、アートボードが作成できればいけるような気はしてます。
「do javascript "" --Photoshopでの処理をここに」の "" 内にスクリプトを記述すれば、多分いけると思います。多分....
できるとは言い切れてませんのであまり大きな期待は。。。。


use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

tell application "Numbers"
tell front document
tell active sheet
try
set theTable to first table whose class of selection range is range
on error
beep
display alert "何も選択されていません。"
return --何も選択されてなかった場合は終了
end try

tell theTable
set selList to value of (every cell of selection range)
set columnCount to count of (column of selection range) --列をカウント
if columnCount > 1 then
beep
display alert "2列以上選択されています。1列のみ選択してください。"
return
end if
end tell
end tell
end tell
end tell

repeat with i in selList
set ii to contents of i
if ii is not missing value then
log ii
if application id "com.adobe.Photoshop" is running then
tell application id "com.adobe.Photoshop"
if exists front document then
tell front document
try

do javascript "" --Photoshopでの処理をここに

on error msg
return msg
end try
end tell
end if
end tell
end if
end if
end repeat


on regexReplace(aText as text, pattern as text, replacement as text)
--require framework: Foundation
set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value)
return (regularExpression's stringByReplacingMatchesInString:aText options:0 range:{location:0, |length|:count aText} withTemplate:replacement) as text
end regexReplace

 

ReeeeeiAuthor
Participating Frequently
September 15, 2023

Photoshop内の処理のスクリプトについて、

模索し試してみたいと思います!

本当にありがとうございます!

ajabon grinsmith
Community Expert
Community Expert
September 14, 2023

というわけで(探すのをお手伝い)

このあたりとか?

Custom script for renaming artboards, with multiple elements

 

その「文字列」というものがどこに存在しているのかによりますが。

ReeeeeiAuthor
Participating Frequently
September 14, 2023

ありがとうございます!!

当方の知識不足によりうまくお伝えできず申し訳ないです...

 

文字列はNumbersから拾いたいです。

表に名前が羅列されているので、それをそのまま各アートボード名にするイメージです。

ajabon grinsmith
Community Expert
Community Expert
September 14, 2023

Numbersから値を取得するにはAppleScriptなどの、ExtendScript以外の言語を利用することとなります。

AppleScriptでもPhotoshopは制御可能ですが、ネット上に公開されている例文やフリー公開のスクリプトというと極端に弾数が少ないですね。

ExtendScript内で部分的にAppleScriptや他のスクリプト言語を実行することも可能なので、今回はそれをふまえてNumbersのパート、Photoshopのパートそれぞれで探して、どうにかこうにか組み合わせるか、もしくはNumbersパートを妥協して若干の手作業を混ざるか、といったところかと思います。

書ける人に有償依頼する意思があるならその旨を表明しておけば誰か来てくれるかなーとも思います。