该脚本用于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. Varnish简介

    Varnish介绍: Varnish是一个反向HTTP代理,有时也被称为HTTP的加速器或网络加速器:它存在于真实服务器的前面(可能有多级代理),将来自于客户端的请求中的部分内容存储在自身的内存中,以 ...

  2. HDMI IP学习笔记

    在HDMI的IP核中点击,生成例子.找到./simulaion/mentor文件夹,把modelsim路径转到该路径下,即可仿真.

  3. Android调试小技巧(LogCat不输出、Log自动清空、install时timeout)

    问题:有时候明明连接了设备,而LogCat却没有输出 解决方法:在device界面点一下对应设备,使其处于选中状态(它适用于查看手机文件不显示的情况) 问题:前面记录的Log看着看着突然被清空了 解决 ...

  4. servlet的session为null?

    servlet的session(会话)显示为null,一般是web.xml中配置不对或者在浏览器输入的url不正确造成的. web.xml配置如下: <servlet> <servl ...

  5. css中一些必要的公共样式

    body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend ...

  6. js的form基础知识点

    在HTML 中,表单是由<form>元素来表示的,而在JavaScript 中,表单对应的则是HTMLForm-Element 类型.HTMLFormElement 继承了HTMLElem ...

  7. Computer Vision 学习 -- 图像存储格式

    本文把自己理解的图像存储格式总结一下. 计算机中的数据,都是二进制的,所以图片也不例外. 这是opencv文档的描述,具体在代码里面,使用矩阵来进行存储. 类似下图是(BGR格式): 图片的最小单位是 ...

  8. Python 基本语法 学习之路(三)

    定义变量 在Python中,定义一个变量是很简单的.而且,在Python中,定义是不需要用分号结尾的.例如: a = 10 b = 3 print(a*b) 判断语句 Pyhon的if判断语句是由if ...

  9. C# 反转字符串方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 反转字符 ...

  10. java中用spring实现数组类型输出

    java 中的几个数组类型 1.Department类 package com.yy.collection; import java.util.List; import java.util.Map; ...