UI拼图导出脚本,兼容cegui的ImageSet格式
该脚本用于photoshop,美术可以先用photoshop拼接图片,在加载该脚本导出xml格式的文件,该文件记录了每个小的图片坐标信息
// Copyright 2002-2003. Adobe Systems, Incorporated. All rights reserved.
// Set the active layer to the last art layer of the active document, or the
// first if the last is already active. function getLayerSetsIndex()
{
function getNumberLayers()
{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("NmbL") )
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getInteger(charIDToTypeID("NmbL"));
}
function hasBackground()
{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr"), charIDToTypeID( "Bckg" ));
ref.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Back" ))//bottom Layer/background
var desc = executeActionGet(ref);
var res = desc.getBoolean(charIDToTypeID( "Bckg" ));
return res
};
function getLayerType(idx,prop)
{
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( "Lyr " ), idx);
var desc = executeActionGet(ref);
var type = desc.getEnumerationValue(prop);
var res = typeIDToStringID(type);
return res
}; var cnt = getNumberLayers()+1;
var res = new Array();
if(hasBackground())
{
var i = 0;
}
else
{
var i = 1;
}; var prop = stringIDToTypeID("layerSection")
for(i;i<cnt;i++)
{
var temp = getLayerType(i,prop);
if(temp == "layerSectionStart" || temp == "layerSectionContent")
res.push(i);
};
return res;
}; function makeActiveByIndex( idx, visible )
{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( "Lyr " ), idx)
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), visible );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
}; function getLayerBoundsByIndex( idx )
{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "bounds" ));
ref.putIndex( charIDToTypeID( "Lyr " ), idx );
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID( "bounds" ));
var bounds = [];// array of Numbers as pixels regardless of ruler
bounds.push(desc.getUnitDoubleValue(stringIDToTypeID('left')));
bounds.push(desc.getUnitDoubleValue(stringIDToTypeID('top')));
bounds.push(desc.getUnitDoubleValue(stringIDToTypeID('right')));
bounds.push(desc.getUnitDoubleValue(stringIDToTypeID('bottom')));
return bounds;
} function getLayerNameByIndex(idx)
{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "name" ));
ref.putIndex( charIDToTypeID( "Lyr " ), idx );
var name = executeActionGet(ref).getString(stringIDToTypeID( "name" ));
return name;
} function StringBuffer()
{
this._strings = [];
if(arguments.length==1)
{
this._strings.push(arguments[0]);
}
} StringBuffer.prototype.Append = function(str)
{
this._strings.push(str);
return this;
} StringBuffer.prototype.ToString = function()
{
return this._strings.join("");
} var docRef = app.activeDocument; var saveRef = File.saveDialog( "Save as","Text Files:*.xml");
var savename = saveRef.name;
savename = savename.replace(/.xml/, "")
if (saveRef)
{
saveRef.open("w"); var groups = getLayerSetsIndex(); var strCotent = new StringBuffer()
strCotent.Append("<?xml version= "+'/"'+'1.0' +'/"' +"?>");
strCotent.Append("\n");
strCotent.Append("<Imageset Name=");
strCotent.Append(savename);
strCotent.Append(" Imagefile=");
strCotent.Append(savename);
strCotent.Append(">\n") //for(var i = 0; i < groups.length; ++i)
for(var i = groups.length -1; i >= 0; --i)
{
makeActiveByIndex( groups[i], true ); var activelayer = app.activeDocument.activeLayer var _layername = "" + activelayer
var layertype = _layername.substr(1, 8) layername = getLayerNameByIndex(groups[i]) if (layertype == "ArtLayer")
{
var bound = getLayerBoundsByIndex(groups[i]) var boundrect1 = parseInt(bound[0])
var boundrect2 = parseInt(bound[1])
var boundrect3 = parseInt(bound[2])
var boundrect4 = parseInt(bound[3]) strCotent.Append("<Image Name="+ '/"'+ layername + '/"');
strCotent.Append(" XPos=" + boundrect1);
strCotent.Append(" YPos=" + boundrect2); strCotent.Append(" Width=" + boundrect3);
strCotent.Append(" Height=" + boundrect4);
strCotent.Append('/>');
//var StringTemp = "Image" + '\t' + layername
//strCotent.Append(StringTemp)
}
}
strCotent.append('/n</ImageSet>');
saveRef.write(strCotent.ToString())
} saveRef.close();
alert("导出完成!");
docRef = null;
UI拼图导出脚本,兼容cegui的ImageSet格式的更多相关文章
- Oralce 导出脚本命令,定时执行
原文:Oralce 导出脚本命令,定时执行 @echo off @echo ================================================ @echo window ...
- shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)
shell脚本兼容linux/unix与windows/cygwin的基础 :统一文本格式为:unix文本格式,即于LF为换行符(推荐方案) 在notepad上设置:编辑->档案格式转换-> ...
- 关于SQL 导出脚本失败 及SQL 的重装
说点题外话 最近跳到一家新公司 薪资比较客观 但是技术可能不太尽如人意 而且对.Net方向的开发好像不是很友好 自己也不知道该怎么办 一个人大老远跑这边来 附近也没有什么.net的公司和职位 房子租 ...
- 【itext】7步制作兼容各种文档格式的Itext5页眉页脚 实现page x pf y
itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...
- WCF兼容WebAPI输出Json格式数据,从此WCF一举两得
问题起源: 很多时候为了业务层调用(后台代码),一些公共服务就独立成了WCF,使用起来非常方便,添加服务引用,然后简单配置就可以调用了. 如果这个时候Web站点页面需要调用怎么办呢? 复杂的XML , ...
- MySQL数据导出为Excel, json,sql等格式
MySQL数据经常要导出为Excel, json,sql等格式,通过步骤都很多,麻烦,现在通过Treesoft可以方便的导出你要的数据格式. 1.在线执行SQL,在数据列表中有相应按钮,方便的将数据导 ...
- 将Swagger2文档导出为HTML或markdown等格式离线阅读
网上有很多<使用swagger2构建API文档>的文章,该文档是一个在线文档,需要使用HTTP访问.但是在我们日常使用swagger接口文档的时候,有的时候需要接口文档离线访问,如将文档导 ...
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
- DB2导出脚本,重新建立数据库
在做项目的时候,我们经常会涉及到数据库的迁移 所以我们需要导出 db2数据的建库脚本,存储过程脚本,函数脚本, 我是这么做的 windows键---cmd---进入命令-----db2cmd----进 ...
随机推荐
- php js => splice 数组 插入 功能
php array_splice 手册详解 array_splice - 把数组中的一部分去掉并用其它值取代 参数 input 输入的数组. offset 如果 offset 为正,则从 i ...
- tomcat 配置ssi
tomcat想要使用html文件引入html文件的功能可以开启ssi,这样就可以在html文件中使用include指令,从而使得html文件可以动态加载html文件了. 开启ssi步骤如下: 1.ap ...
- The path to the driver executable must be set by the webdriver.gecko.driver system property
报这个错,是因为你使用了selenium3+Firefox.在selenium3中,使用Firefox,需要添加驱动. 您可以从Github上下载驱动程序下载网址- https://github.c ...
- jquery验证
首先要引用js库 <script src="js/jquery-1.7.2.min.js"></script> jquery验证方式 function ch ...
- 序列化--dict与(file)文件读写
在程序运行的过程中,所有的变量都是在内存中,比如,定义一个dict: d = dict(name='Bob', age=20, score=88) 可以随时修改变量,比如把name改成'Bill',但 ...
- 快捷键的记录,Word和PPT的一些常用操作
1)PPT背景设置:右键->背景->背景填充下的下拉箭头->填充效果->图片- >选择图片->确定->选择应用或应用全部 2)Word,PPT求和符号怎么打 ...
- 用keras的cnn做人脸分类
keras介绍 Keras是一个简约,高度模块化的神经网络库.采用Python / Theano开发. 使用Keras如果你需要一个深度学习库: 可以很容易和快速实现原型(通过总模块化,极简主义,和可 ...
- 如何搭建一个WAMP环境
最近的一些比赛需要用到PHP,所以急需配置一个PHP的环境,所以分享出来我的经历 一.使用wampserver 这是一个集成软件包,可以一键配置Apache+Mysql+PHP,还具有简单的图形界面 ...
- vmware安装linux6.3
安装信息: 1.vmware9.0下载地址:http://pan.baidu.com/share/link?shareid=1287299796&uk=2585121485 2.oraclel ...
- 图解VMware内存机制
在写<VMware内存机制初探>之后,原本是计划写一篇<VMware内存机制再探>的,讲一讲VMware内存机制中的另外几个重要内容,比如透明内存共享(TPS, Transpa ...