Skip to content

Instantly share code, notes, and snippets.

@mattun
Created May 11, 2020 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattun/4b6ad2a560ba77b4f0057451f8682b61 to your computer and use it in GitHub Desktop.
Save mattun/4b6ad2a560ba77b4f0057451f8682b61 to your computer and use it in GitHub Desktop.
photoshop用の選択範囲をテキストに書き出すだけJSX
//スクリプトに表示
/*
<javascriptresource>
<name>選択範囲書き出し</name>
<menu></menu>
<category>Layers</category>
<enableinfo>true</enableinfo>
</javascriptresource>
*/
#target Photoshop
var docRef = app.activeDocument;
function checkSelection() {
var flag = true;
try {
var boundsObj = docRef.selection.bounds;
x1 = parseInt(boundsObj[0]);
y1 = parseInt(boundsObj[1]);
x2 = parseInt(boundsObj[2]);
y2 = parseInt(boundsObj[3]);
var fullPath = docRef.fullName.fsName.toString();
var fileName = docRef.name;
var result_path = fullPath.split('/');
var class_name = result_path[10];
var result_name = fileName.split('.jpg');
var file_name_txt = result_name[0];
var dir = fullPath.replace(fileName, '');
var file = new File(dir + "/../../labels/" + class_name + "/" + file_name_txt + ".txt");
var openFlag = file.open("w");
if(openFlag) {
//BEGRINGER_FCB1010 0 0 0 41 288 1866 1243 0 0 0 0 0 0 0
var fileInfo = class_name + " 0 0 0 " + x1 + " " + y1 + " " + x2 + " " + y2 + " 0 0 0 0 0 0 0";
file.write(fileInfo);
file.close();
}
} catch (e) {
flag = false;
}
return flag;
}
checkSelection();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment