Created
May 11, 2020 08:48
-
-
Save mattun/4b6ad2a560ba77b4f0057451f8682b61 to your computer and use it in GitHub Desktop.
photoshop用の選択範囲をテキストに書き出すだけJSX
This file contains 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> | |
<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