该脚本用于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格式的更多相关文章

  1. Oralce 导出脚本命令,定时执行

    原文:Oralce 导出脚本命令,定时执行 @echo off @echo ================================================ @echo  window ...

  2. shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)

    shell脚本兼容linux/unix与windows/cygwin的基础 :统一文本格式为:unix文本格式,即于LF为换行符(推荐方案) 在notepad上设置:编辑->档案格式转换-> ...

  3. 关于SQL 导出脚本失败 及SQL 的重装

    说点题外话 最近跳到一家新公司 薪资比较客观 但是技术可能不太尽如人意 而且对.Net方向的开发好像不是很友好  自己也不知道该怎么办 一个人大老远跑这边来 附近也没有什么.net的公司和职位 房子租 ...

  4. 【itext】7步制作兼容各种文档格式的Itext5页眉页脚 实现page x pf y

    itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...

  5. WCF兼容WebAPI输出Json格式数据,从此WCF一举两得

    问题起源: 很多时候为了业务层调用(后台代码),一些公共服务就独立成了WCF,使用起来非常方便,添加服务引用,然后简单配置就可以调用了. 如果这个时候Web站点页面需要调用怎么办呢? 复杂的XML , ...

  6. MySQL数据导出为Excel, json,sql等格式

    MySQL数据经常要导出为Excel, json,sql等格式,通过步骤都很多,麻烦,现在通过Treesoft可以方便的导出你要的数据格式. 1.在线执行SQL,在数据列表中有相应按钮,方便的将数据导 ...

  7. 将Swagger2文档导出为HTML或markdown等格式离线阅读

    网上有很多<使用swagger2构建API文档>的文章,该文档是一个在线文档,需要使用HTTP访问.但是在我们日常使用swagger接口文档的时候,有的时候需要接口文档离线访问,如将文档导 ...

  8. 前端导出Excel兼容写法

    今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...

  9. DB2导出脚本,重新建立数据库

    在做项目的时候,我们经常会涉及到数据库的迁移 所以我们需要导出 db2数据的建库脚本,存储过程脚本,函数脚本, 我是这么做的 windows键---cmd---进入命令-----db2cmd----进 ...

随机推荐

  1. Unity使用Windows弹窗保存图片

    此功能都在类EditorUtility中(using UnityEditor;) 包括 OpenFilePanel打开文件窗口Displays the "open file" di ...

  2. 在oracle里写各种语句得心应手,但是在mybatis.xml文件里呢?

    这个问题我让我搞了大半天,实在气人,话不多说,直接上代码 <select id="*" resultMap="Blog" parameterType=&q ...

  3. Command(命令)-对象行为型模式

    1.意图 将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化:对请求排队或记录请求日志,以及支持可撤销的操作. 2.别名 动作(Action),事务(Transaction) 3.动机 ...

  4. MYSQL-5.5二进制包安装

    groupadd mysql 添加用户组 useradd mysql -s /sbin/nologin -g mysql -M  添加用户 mv mysql-5.5.54-linux2.6-x86_6 ...

  5. JS编码解码

    一.定义和用法 encodeURI() 函数可把字符串作为 URI 进行编码. 语法 encodeURI(URIstring) 参数 描述 URIstring 必需.一个字符串,含有 URI 或其他要 ...

  6. iOS实现类似于歌词进度效果

    先看效果 这里关键的地方在于镂空文字的实现,可以用UILabel的drawRect方法. .h文件 @interface HollowLabel : UILabel @end .m文件 @interf ...

  7. jetty服务器启动方法总结【备用】

    1. 使用Java命令启动 java -jar start.jar ctrl + c 关闭 终端窗口一直存在 2. 使用Java命令启动2 java -jar start.jar & 启动成功 ...

  8. aspnet超级链接 传递 当前页面 textbox值

    一共有两个窗体. 第一个窗体A传参到窗体B  A的参数是A窗体的textbox 窗体A代码 <html xmlns="http://www.w3.org/1999/xhtml" ...

  9. 解决canvas转base64/jpeg时透明区域变成黑色背景的方法

    最近在工作遇到一个问题,在将png图片转jpeg时,透明区域被填充成黑色,通过网上的介绍找到了解决的方法,现在总结下分享给同样遇到这个问题的朋友们,感兴趣的可以通过本文详细学习下. 在用canvas将 ...

  10. OSG配置问题

    BUILD_OSG_ARAPPERS: 这一项要选,不然后面编译自己的测试程序的时候,会报无法打开文件"osgIntrospectiond.lib"错误. Could not fi ...