`
flex_莫冲
  • 浏览: 1090423 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

adobe creative suite extension builder扩展安装地址及调试方法

    博客分类:
  • flex
阅读更多
1 延时(js)
$.sleep(1000);
$.writeln("testt");

2 执行脚本(as)
var url:String = getAppStoragePath() + "assets/post.jsx";
var back:Object = app.doScript(url, ScriptLanguage.javascript, myArg);
第二种方式(推荐)
package
{
import flash.external.HostObject;
public class HelloCreativeSuiteJSX
{
[Embed(source="./HelloCreativeSuite.jsx", mimeType="application/octet-stream")]

private static var EsInitClass: Class;
public static function run():void
{
var scriptObject: Object = new EsInitClass();

var initScript: String = scriptObject.toString();

var myBridgeScript : HostObject = HostObject.getRoot(HostObject.extensions[0]);
myBridgeScript.eval(initScript);
var jsxReturnStr : String =  myBridgeScript.sayHello();
trace(jsxReturnStr);
}
}
}

3 创建模式面板,非模式面板和提示
public function showModal():void
{
var window:Window = new ModalDialog;
window.type = CSXSWindowType.MODAL_DIALOG;
window.resizable = false;
window.open();
}
public function showModeless():void
{
var modelessWindow:Window = new ModelessDialog;
modelessWindow.type = CSXSWindowType.MODELESS;
modelessWindow.open();
}
public function showTooltip():void
{
var tooltipWindow:Window = new ToolTip;
tooltipWindow.type = CSXSWindowType.TOOLTIP;
tooltipWindow.open();
}

4 创建面板菜单
private const MENU_SHOW_MODAL:String = "Display Modal Dialog";
private const MENU_SHOW_MODELESS:String = "Display Modeless Dialog";
private const MENU_SHOW_TOOLTIP:String = "Display ToolTip Window";

public var xmlBasicMenu:XML =
<Menu>
<MenuItem Label={MENU_SHOW_MODAL}/>
<MenuItem Label={MENU_SHOW_MODELESS}/>
<MenuItem Label={MENU_SHOW_TOOLTIP}/>
</Menu>
CSXSInterface.instance.addEventListener(MenuClickEvent.FLYOUT_MENU_CLICK, menuClickHandler);
var menuAdded:SyncRequestResult = CSXSInterface.instance.setPanelMenu(xmlBasicMenu);
if(SyncRequestResult.COMPLETE != menuAdded.status){
showAlert("initializeMenu() Failed to add menu");
}

5 创建CSXS面板标签
<csxs:CSXSWindowedApplication>
可设置面板title和底部的toolbar

6 获取当前语言环境(hostEnvironment也包含了当前应用类型,如indesign,photoshop。
hostEnv.appName
hostEnv.isAppOffline 是否在线
appLocale 语言
appVersion 版本)

[Bindable]
private var currentUILocale:String;

private function onCreationComplete() : void
{
var result : SyncRequestResult = CSXSInterface.getInstance().initResourceBundle();

if (result.status != SyncRequestResult.COMPLETE)
{
trace(result.status + ": " + result.data.toString());
}

result = CSXSInterface.instance.getHostEnvironment();
var hostEnvironment : HostEnvironment = result.data as HostEnvironment;
currentUILocale = hostEnvironment.appUILocale;
}

7 通过HTTPRequest提交http请求和参数并获取返回值
import com.adobe.awsi.HttpRequest;
import com.adobe.awsi.HttpResponse;
/**
* Uses the AWSI libraries to connect to the Google Translate APIs to:
* 1) Determine if the current language combination is supported
* 2) If supported translates the passed text
* @param text the selection of text to be translated
* @param lang what language to translate it too
* @param onSucccess callback function to return translated string
*/
public function useGoogleApis(text:String, lang:String, onSuccess:Function, onError:Function=null):void
{
var request:HttpRequest = new HttpRequest(HttpRequest.GET, "http://ajax.googleapis.com/ajax/services/language/detect", "");
request.setParam("v", "1.0");
request.setParam("q", text);
request.perform(function(response:HttpResponse):void
{
if((response.succeeded() || response.get_Status() == 0) && (response.isParseable() && response.getRootNode().child_text("responseStatus") == "200"))
{
var language:String = response.getRootNode().child("responseData").child_text("language");

// now try translation API
var translateRequest:HttpRequest = new HttpRequest(HttpRequest.GET, "http://ajax.googleapis.com/ajax/services/language/translate", "");
translateRequest.setParam("q", text);
translateRequest.setParam("v", "1.0");
var langpair:String = language + "|" + lang;
translateRequest.setParam("langpair", langpair);
translateRequest.perform(function(translateResponse:HttpResponse):void
{
if((translateResponse.succeeded() || translateResponse.get_Status() == 0) && (translateResponse.isParseable() && translateResponse.getRootNode().child_text("responseStatus") == "200"))
{
onSuccess(translateResponse.getRootNode().child("responseData").child_text("translatedText"));
}
else
{
// error - translation not supported
onError("The translation from " + language + " to " + lang + " is not supported");
}
});
}
else
{
onError("Sorry but something went wrong");
}
});
}
参考 BASERSSReader
8 判断网络是否可用(as)
/**
* Determines if the Creative Suite product has a network
* connection
*/
public function computeOnline():void
{
var res:Boolean = false;
var result:SyncRequestResult = CSXSInterface.getInstance().getNetworkPreferences();
var networkPreferences:NetworkPreferences;

if ((result.status == SyncRequestResult.COMPLETE) && result.data)
{
networkPreferences = result.data as NetworkPreferences;
if (networkPreferences.overallOnlinePreference)
{
//online preference are enabled, so go online
res = true;
}
}
this.getModel().online = res;
if (this.getModel().online == false)
{
this.getModel().notifier = "Polyglot is unavailable due to lack of network access";
}
}

9 XMPMETA DATA 操作(as)
创建XMPMeta 必须指定命名空间来访问
var meta:XMPMeta = new XMPMeta();
//var xmp:Namespace = new Namespace("http://ns.adobe.com/xap/1.0/");
var nmg:Namespace = new Namespace("my", "http://com.nmg.xmp/");
meta.nmg::CreatorTool = "Indesign";//设置属性CreatorTool为Indesign

//下面是2个命名空间
meta.xmpNS::Rating = 4;
meta.my::simpleProp = "value";

读取属性
trace(meta.xmpNS::Rating);  // shows "4"
trace(meta.my::simpleProp); // shows "value"

更新属性
meta.xmpNS::Rating = 5;
meta.my::simpleProp = "new value";

删除属性
meta.my::simpleProp = null;
—or—
delete meta.my::simpleProp;

判断属性是否存在
trace( meta.xmpNS::Rating.exists() );     // true
trace( meta.my::simpleProp.exists() );    // false
trace( meta.my::simpleProp.toString() );  // null

数据类型转换
The XMPMeta object provides convenience methods for retrieving String property values as literal types:
toBoolean()
toInteger()
toFloat()
toDate()

添加结构化XMP属性(对象属性)
var effect:Namespace = new Namespace("effect","http://com.nmg.xmp.effect/");
var struct:XMPStruct = new XMPStruct();
struct.effect::effectId = "1";
struct.effect::effectType = "slideshow";
// add the structured property to the XMP object
meta.nmg::struct = struct;
// Retrieve a struct field
Log.add (meta.nmg::struct.effect::effectType);
删除结构化XMP属性
meta.nmg::struct = null
—or—
delete meta.nmg::struct

添加数组属性
以下三种添加类型
meta.my::bagArray = XMPArray.newBag();// 保存字符串
meta.my::seqArray = XMPArray.newSeq();
meta.my::altArray = XMPArray.newAlt();//保存struct对象结构
添加数组元素方式
To add items, use the square brackets, "[...]" operator, or the append() and insert() methods of the XMPArray object. 
获取最后一个元素
The special index value "last()" accesses the last item: meta.my::bagArray ["last()"].
trace(meta.my::seqArray[5]); // prints "five"
trace(meta.my::seqArray["last()"]); // prints "five"
length();获取数组长度

通过对象方式设置array
meta.nmg::effectArray = XMPArray.newAlt();
var effectArray:XMPArray = new XMPArray();
effectArray.setType(2);//0:newBag,1:newSeq,2:newAlt
effectArray.append(struct);
effectArray.append(struct2);
meta.nmg::effectArray = effectArray;
注意:不能通过effectArray[1]的方式访问子节点。XMPArray.toString()和struct.toString()(输出<struct>)都无法获取到对应的字符串内容。

输出XMPMETADATA
var metaStr:String = meta.serialize();
var metaBuffer:ByteArray = meta.serializeToBuffer();
var metaXML:XML = meta.serializeToXML();

遍历XMP METADATA
Iterate through all property values of a structured property:
for each (var prop: XMPNode in meta.my::struct)
{
   trace(prop);
}
Iterate through all property names of a structured property:
for (var propName: String in meta.my::struct)
{
   trace(prop);
}
Iterate through the names of all top-level properties:
for (var propName: String in meta)
{
   trace(prop);
}
Iterate through all items of an array property:
for each (var prop: XMPNode in meta.my::array)
{
   trace(prop);
}

10 不通过XMP存储数据(as)
CSXS提供了一种存储和读取的机制,可以再indesign重启后依然能拿到数据。只能存储string类型。
通过ID识别。ID通过AMF转换再转换为BASE64格式的字符串。
可设置是否与其它extention扩展共享数据。
这种机制不支持在不同的电脑中共享数据。只针对当前电脑的indesign。
参考CSXSPrefBase demo项目
/**
* Repopulates the object associated with <code>preferenceID</code>.
**/
public function retrieve(preferenceID:String):void {
//make CSXS call to retrieve preference
var result:SyncRequestResult = CSXSInterface.getInstance().retrievePreference(preferenceID);
if (result.status == SyncRequestResult.COMPLETE && result.data) {
decode(result.data as String);
} else {
throw new Error("Could not retrieve object with id " + preferenceID + ".");
}
}
/**
* Repopulates the shared object associated with <code>preferenceID</code>.
**/
public function retrieveShared(preferenceID:String):void {
//make CSXS call to retrieve shared preference
var result:SyncRequestResult = CSXSInterface.getInstance().retrieveSharedPreference(preferenceID);
if (result.status == SyncRequestResult.COMPLETE && result.data) {
decode(result.data as String);
} else {
throw new Error("Could not retrieve object with id " + preferenceID + ".");
}
}

/**
* Stores the object with the key <code>preferenceID</code>. If no <code>preferenceID</code> is provided a unique one is automatically generated.
* Returns the <code>preferenceID</code> associated with the object.
**/
public function store(preferenceID:String = null):String {
//if key hasn't been set, set one.
if (preferenceID == null) {
preferenceID = UIDUtil.createUID();
}

//make CSXS call to store preference
CSXSInterface.getInstance().storePreference(preferenceID, encode());
return preferenceID;
}

/**
* Stores the shared object with the key <code>preferenceID</code>. If no <code>preferenceID</code> is provided a unique one is automatically generated.
* Returns the <code>preferenceID</code> associated with the object.
**/
public function storeShared(preferenceID:String = null):String {
//if key hasn't been set, set one.
if (preferenceID == null) {
preferenceID = UIDUtil.createUID();
}

//make CSXS call to store shared preference
CSXSInterface.getInstance().storeSharedPreference(preferenceID, encode());
return preferenceID;
}

11 判断当前选择物件的类型(as)
app.selection[counter] is Rectangle:
app.selection[counter] is Oval:
app.selection[counter] is Polygon:
app.selection[counter] is GraphicLine:
app.selection[counter] is TextFrame:

12 事件类型及监听(as)
//Add CSXS "standardized" events.
var myCSXS:CSXSInterface = CSXSInterface.getInstance();
myCSXS.addEventListener("documentAfterActivate", eventHandler);
myCSXS.addEventListener("documentAfterDeactivate", eventHandler);
myCSXS.addEventListener("applicationActivate", eventHandler);
//Add CSXS events.
myCSXS.addEventListener(StateChangeEvent.WINDOW_OPEN, eventHandler);
myCSXS.addEventListener(StateChangeEvent.WINDOW_SHOW, eventHandler);

//参考EVENT WATCHER demo
eventList.addItem( new EventRecord( "After Activate", Event.AFTER_ACTIVATE, false ) );
eventList.addItem( new EventRecord( "After Attibute Changed", MutationEvent.AFTER_ATTRIBUTE_CHANGED, false ) );
eventList.addItem( new EventRecord( "After Close", Event.AFTER_CLOSE, false ) );
eventList.addItem( new EventRecord( "After Context Changes", Event.AFTER_CONTEXT_CHANGED, false ) );
eventList.addItem( new EventRecord( "After Delete", Event.AFTER_DELETE, false ) );
eventList.addItem( new EventRecord( "After Embed", Event.AFTER_EMBED, false ) );
eventList.addItem( new EventRecord( "After Invoke", Event.AFTER_INVOKE, false ) );
eventList.addItem( new EventRecord( "After Links Changed", Event.AFTER_LINKS_CHANGED, false ) );
eventList.addItem( new EventRecord( "After Move", Event.AFTER_MOVE, false ) );
eventList.addItem( new EventRecord( "After New", Event.AFTER_NEW, false ) );
eventList.addItem( new EventRecord( "After Open", Event.AFTER_OPEN, false ) );
eventList.addItem( new EventRecord( "After Place", Event.AFTER_PLACE, false ) );
eventList.addItem( new EventRecord( "After Print", PrintEvent.AFTER_PRINT, false ) );
eventList.addItem( new EventRecord( "After Quit", Event.AFTER_QUIT, false ) );
eventList.addItem( new EventRecord( "After Revert", DocumentEvent.AFTER_REVERT, false ) );
eventList.addItem( new EventRecord( "After Save", DocumentEvent.AFTER_SAVE, false ) );
eventList.addItem( new EventRecord( "After Save a Copy", DocumentEvent.AFTER_SAVE_A_COPY, false ) );
eventList.addItem( new EventRecord( "After Save As", DocumentEvent.AFTER_SAVE_AS, false ) );
eventList.addItem( new EventRecord( "After Selection Attribute Changed", Event.AFTER_SELECTION_ATTRIBUTE_CHANGED, false ) );
eventList.addItem( new EventRecord( "After Selection Changed", Event.AFTER_SELECTION_CHANGED, false ) );
eventList.addItem( new EventRecord( "After Unembed", Event.AFTER_UNEMBED, false ) );
eventList.addItem( new EventRecord( "After Update", Event.AFTER_UPDATE, false ) );
eventList.addItem( new EventRecord( "Before Close", Event.BEFORE_CLOSE, false ) );
eventList.addItem( new EventRecord( "Before Deactivate", Event.BEFORE_DEACTIVATE, false ) );
eventList.addItem( new EventRecord( "Before Delete", Event.BEFORE_DELETE, false ) );
eventList.addItem( new EventRecord( "Before Display", Event.BEFORE_DISPLAY, false ) );
eventList.addItem( new EventRecord( "Before Embed", Event.BEFORE_EMBED, false ) );
eventList.addItem( new EventRecord( "Before Invoke", Event.BEFORE_INVOKE, false ) );
eventList.addItem( new EventRecord( "Before Move", Event.BEFORE_MOVE, false ) );
eventList.addItem( new EventRecord( "Before Place", Event.BEFORE_PLACE, false ) );
eventList.addItem( new EventRecord( "Before Print", PrintEvent.BEFORE_PRINT, false ) );
eventList.addItem( new EventRecord( "Before Quit", Event.BEFORE_QUIT, false ) );
eventList.addItem( new EventRecord( "Before Revert", DocumentEvent.BEFORE_REVERT, false ) );
eventList.addItem( new EventRecord( "Before Save", DocumentEvent.BEFORE_SAVE, false ) );
eventList.addItem( new EventRecord( "Before Save a Copy", DocumentEvent.BEFORE_SAVE_A_COPY, false ) );
eventList.addItem( new EventRecord( "Before Save As", DocumentEvent.BEFORE_SAVE_AS, false ) );
eventList.addItem( new EventRecord( "Before Unembed", Event.BEFORE_UNEMBED, false ) );
eventList.addItem( new EventRecord( "Before Update", Event.BEFORE_UPDATE, false ) );
eventList.addItem( new EventRecord( "On Idle", IdleEvent.ON_IDLE, false ) );
eventList.addItem(new EventRecord("Layer Change",com.adobe.indesign.Event.LAYER_CHANGED,false));
13 写入文件的XMP metadata(js)
注意:若当前文件正在打开,则无法写入。
// load the XMPScript library
if (ExternalObject.AdobeXMPScript == undefined)
    ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

var filePath = "/C/Users/davidhuang/Documents/未命名-2.indd";
var file = new File(filePath);
var xmpFile = new XMPFile(file.fsName, XMPConst.UNKNOWN,XMPConst.OPEN_FOR_UPDATE);//XMPConst.OPEN_FOR_UPDATE
var xmp = xmpFile.getXMP();
// delete existing authors and add a new one
// existing metadata stays untouched
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.appendArrayItem(XMPConst.NS_DC, "going", "DAVIDTEST", 0,XMPConst.ARRAY_IS_ORDERED);
xmp.appendArrayItem(XMPConst.NS_DC, "creator", "INDESIGN", 0,XMPConst.ARRAY_IS_ORDERED);
// write updated metadata into the file
if (xmpFile.canPutXMP(xmp)) {
    xmpFile.putXMP(xmp);
}

xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

14 提取文件的XMP数据并保存到xml文件(js)
//load XMP Library
var XMPload = Boolean(false);
if (ExternalObject.AdobeXMPScript == undefined){
    try {
        ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
        XMPload = true;
    }catch(ex)
    {
        alert("Unable to load the AdobeXMPScript library!");
    }
}
if(XMPload){
    var myFile = File(app.selection[0].graphics[0].itemLink.filePath);//获取当前选择的第一个图片文件路径
    xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
    xmp = xmpFile.getXMP();
    var myXmp = xmp.serialize();
    $.writeln(myXmp);//输出XMPDATA
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
writeXMP(myXmp, File('/e/myxmp.xml'));//保存到指定文件。需先创建文件

function writeXMP(xmpData, xmpFile){
xmpFile.open ( 'w', 'Text');
xmpFile.encoding = 'UTF-8';
xmpFile.write (xmpData);
xmpFile.close ();
}

15 给当前文档的添加新的xmp 属性(js as)
var myDocXMP = app.activeDocument.metadataPreferences;
var destNamespace = "http://ns.adobe.com/xap/1.0/";//这是xmp已存在的命名空间。若输入一个不存在的命名空间则不会添加成功
var destNodeName = "MyTesting";
var nodeValue = "IndiSnip test value";
myDocXMP.setProperty(destNamespace, destNodeName, nodeValue);

as代码实现
private function fileInfo():void{
var fileInfo:FileInfoLibrary = new FileInfoLibrary();
var doc:Document = InDesign.app.activeDocument;
var metaData:MetadataPreference = doc.metadataPreferences;
var effect:Namespace = new Namespace("effect","http://com.nmg.xmp.effect/");
var destNamespace:String = "http://ns.adobe.com/xap/1.0/";
metaData.setProperty(destNamespace,"abc","ddd");
}

16 给当前文档的添加新的xmp 容器(js as)
var myDocXMP = app.activeDocument.metadataPreferences;
var destNamespace = "http://ns.adobe.com/xap/1.0/";
var destContName = "IndiSnip";
myDocXMP.createContainerItem(destNamespace, destContName, undefined, ContainerType.BAG);
输出:
<xmp:IndiSnip>
<rdf:Bag>
   <rdf:li/>
</rdf:Bag>
</xmp:IndiSnip>

as版本
private function fileInfo():void{
var doc:Document = InDesign.app.activeDocument;
var metaData:MetadataPreference = doc.metadataPreferences;
var destNamespace:String = "http://com.nmg.xmp.effect/";
var orgNS:String = "http://ns.adobe.com/xap/1.0/";
var destContName:String = "nmgEffect";
metaData.createContainerItem(destNamespace,destContName,0,ContainerType.ALT);//无法新增 。无此命名空间

metaData.setProperty(orgNS,"effectId","1");//新增属性成功
metaData.setProperty(destNamespace,"effectType","slideshow");//失败。无此命名空间

Log.add(metaData.getProperty(orgNS,"effectId"));//读取属性


//添加結構屬性
metaData.createContainerItem(XMP_NAMESPACE,destContName,0,ContainerType.bag);
metaData.setProperty(XMP_NAMESPACE,destContName+"/*[1]","aaa");
metaData.setProperty(XMP_NAMESPACE,destContName+"/*[2]","bb");
Log.add(metaData.getProperty(XMP_NAMESPACE,destContName+"/*[2]"));

//刪除節點
metaData.setProperty(XMP_NAMESPACE,item,"");//將屬性設置為""就是刪除

doc.save();
//输出
// <xmp:nmgEffect>
// <rdf:Alt>
//    <rdf:li/>
// </rdf:Alt>
// </xmp:nmgEffect>
}

注意:不能通过新增的命名空间添加属性。无法创建新的命名空间。

17 打开idnn文件并注册XMP 命名空间添加属性。(js)
注意:若该文件已经打开则运行失败。
// load XMP Library
function loadXMPLibrary(){
    if ( !ExternalObject.AdobeXMPScript ){
        try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
        catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
    }
    return true;
}

// select destination file
var myFile = File.openDialog("Select destination file", "InDesign:*.indd", false);

// check library and file
if(loadXMPLibrary() && myFile != null){
    xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
    var myXmp = xmpFile.getXMP();
}

if(myXmp){
    var destNamespace = "http://indisnip.wordpress.com/";
    // define new namespace
    XMPMeta.registerNamespace(destNamespace,"IndiSnipXMP");
    // insert nodes
    myXmp.setProperty(destNamespace,"creator","IndiSnip");
    myXmp.setProperty(destNamespace,"e-mail","indisnip@gmail.com");
    myXmp.setProperty(destNamespace,"web_site","http://indisnip.wordpress.com");
    myXmp.setProperty(destNamespace,"Version","1.0b");
    // put XMP into file
    if (xmpFile.canPutXMP(myXmp)){xmpFile.putXMP(myXmp);}else{alert("Error storing XMP");}
    // close file
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

18 AS执行js脚本的另一种方式
//$.sleep是js脚本表示暂停
var result: SyncRequestResult = CSXSInterface.getInstance().evalScript( "$.sleep", "1" );

19 indesign监听事件说明
indesign的监听事件在启动扩展之后执行。若没有removeEventListener,即使关闭掉扩展面板也会继续监听。

20 获取当前选择对象的index和id
alert(app.selection[0].id + ",index:" + app.selection[0].index);

21 遍历取得所有对象的属性和值 并导出到txt
main();
function main(){
if(app.documents.length != 0){
if(app.selection.length != 0){
var txtFile= new File ("~/Desktop/obj/image.txt");
txtFile.encoding = 'UTF-8';
txtFile.open("w");
//alert(app.selection[0].texts[0].color);
getMethodAndPropertys(txtFile, app.selection[0],"|");
txtFile.close();
}
}
}

function getMethodAndPropertys(file, obj, prv) {
for (var id in obj) {
try {
if (id == "parent" || id == "parentPage" || id == "parentStory" || id == "startTextFrame" || id == "endTextFrame" || id == "nextTextFrame" || id == "nextStyle") {
continue;
} else {
if ( typeof (obj[id]) == "function") {
file.write(prv + "." + obj[id].toString() + "\n");

} else if ( typeof (obj[id]) == "object") {
getMethodAndPropertys(file, obj[id], prv + "." + id);
} else {
file.write(prv + "." + id + ": " + obj[id].toString() + "\n");
}
}
} catch (err) {
file.write(prv + "." + id + ": inaccessible\n");
}
}
}

22 如何获取pageItem在document上的层次关系
pageItem的index属性并不是真正的排列顺序(同类型的item,index越大代表层次越低)。文本和图片都会从0开始计数。
而图层上的顺序才是真正的排列顺序。这个值就是pageItem在doc.pageItems的索引值。即doc.pageItems(0)代表最顶层的item。doc.pageItems(1)代表下一层的item

这种方式证明是错误的。因为pageItem的索引首先会根据类型来排。图片排最上面,从1开始.如pageItems(1)到pageItems(10)全是图片。然后是文字,多边形,最后是群组。
因此这种方法无法获取到层次关系。

23 獲取當前文檔的xmp(js)
app.activeDocument.xmpstring;

24 获取指定的属性(js)
// Scrollable alert function
function alert_scroll (title, input){
   if (input instanceof Array)
       input = input.join ("\r");
   var w = new Window ("dialog", title);
   var list = w.add ("edittext", undefined, input, {multiline: true, scrolling: true});
   list.maximumSize.height = w.maximumSize.height-100;
   list.minimumSize.width = 250;
   w.add ("button", undefined, "Close", {name: "ok"});
   w.show ();
}

// object
var reflectProperties = app.colorSettings;

// display properties
alert_scroll("Object properties", reflectProperties.reflect.properties.sort());

25 添加自定义图层(js)
var doc = app.activeDocument;
doc.layers.add({name:'images'});

26 indesign导出PDF文档(js)
var myPresets = app.pdfExportPresets.everyItem().name;
myPresets.unshift("- Select Preset -");

var myWin = new Window('dialog', 'PDF Export Presets');
myWin.orientation = 'row';
with(myWin){
myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
myWin.myPDFExport.selection = 0;
myWin.btnOK = add('button', undefined, 'OK');
};
myWin.center();
var myWindow = myWin.show();

if(myWindow == true && myWin.myPDFExport.selection.index != 0){
    var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));
    myFile = File(File.saveDialog("Save file with preset: " + myPreset.name,"PDF files: *.pdf"));
    if(myFile != null){
        app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);
    }else{
        alert("No File selected");
    }
}else{
    alert("No PDF Preset selected");
}

27 可滚动alert(js)
function alert_scroll (title, input){
   if (input instanceof Array)
       input = input.join ("\r");
   var w = new Window ("dialog", title);
   var list = w.add ("edittext", undefined, input, {multiline: true, scrolling: true});
   list.maximumSize.height = w.maximumSize.height-100;
   list.minimumSize.width = 550;
   w.add ("button", undefined, "Close", {name: "ok"});
   w.show ();
}


var myArray = 'Here is an example from "ScriptUI for Dummies", which is a more useful version of alert: it shows text in a scrollable window.';

//var myArray = app.documentPresets.everyItem().name;
var myArray = Array("Item1","Item2","Item3","Item4","Item5","Item6","Item7");
alert_scroll ("Alert!", myArray);

28 查找数组的项是否存在(js)
Array.prototype.exists = function(search){
for (var i=0; i<this.length; i++)
    if (this[i] == search) return true;
return false;
}

var myA = Array("yes","no","today","monday");

alert(myA.exists("yes")); // true
alert(myA.exists("maybe")); // false

29 redo undo
var docUndo = app.activeDocument.undoHistory;
var docRedo = app.activeDocument.redoHistory;

redo undo面板
var docUndo = app.activeDocument.undoHistory;
var docRedo = app.activeDocument.redoHistory;
if(!docUndo.length){
    var noUndo = Boolean(true);
    docUndo = Array("--- No Undo items ---");
}
if(!docRedo.length){
    var noRedo = Boolean(true);
    docRedo = Array("--- No Redo items ---");
}

var myUndoRedo = new Window('dialog', 'Extended Undo/Redo');
myUndoRedo.orientation = 'row';
with(myUndoRedo){
    myUndoRedo.undoPanel = add('panel', undefined, 'Undo');
    myUndoRedo.undoPanel.orientation = 'column';
    with(myUndoRedo.undoPanel){
        myUndoRedo.undoPanel.undoDrop = add('dropdownlist', undefined, undefined, {items:docUndo});
        myUndoRedo.undoPanel.undoDrop.selection = 0;
        myUndoRedo.undoPanel.btnUndo = add('button', undefined, 'Undo');
        myUndoRedo.undoPanel.btnUndo.onClick = function(){this.window.close(0);}
        }
    myUndoRedo.redoPanel = add('panel', undefined, 'Redo');
    myUndoRedo.redoPanel.orientation = 'column';
    if(noUndo)myUndoRedo.undoPanel.btnUndo.enabled = false;
    with(myUndoRedo.redoPanel){
        myUndoRedo.redoPanel.redoDrop = add('dropdownlist', undefined, undefined, {items:docRedo});
        myUndoRedo.redoPanel.redoDrop.selection = 0;
        myUndoRedo.redoPanel.btnRedo = add('button', undefined, 'Redo');
        myUndoRedo.redoPanel.btnRedo.onClick = function(){this.window.close(1);}
    }
    if(noRedo)myUndoRedo.redoPanel.btnRedo.enabled = false;
    myUndoRedo.infoGrp = add('group');
    myUndoRedo.infoGrp.alignment = 'bottom';
    myUndoRedo.infoGrp.orientation = 'column';
    with(myUndoRedo.infoGrp){
        myUndoRedo.infoGrp.btnCancel = add('button', undefined, 'Cancel');
    }
};

myUndoRedo.center();
myUndo = myUndoRedo.show();

if(myUndo == 0){
    var undoSteps = myUndoRedo.undoPanel.undoDrop.selection;
    for (var i = 0; i <= undoSteps; i++) {
        app.activeDocument.undo();
    }
}else if(myUndo == 1){
    var redoSteps = myUndoRedo.redoPanel.redoDrop.selection;
    for (var i = 0; i <= redoSteps; i++) {
        app.activeDocument.redo();
    }
}

30 document.pageItems.previousItem和nextItem获取的上下层item跟图层中或indesign实际可见的层次是不同的
previousItem和nextItem表示的顺序是区分类别再根据同类别中的顺序来排列的。类别的顺序是
群组-文字-图片。最上层若没有则item.id是0.
先是群组。按照index排列。index最小的群组的previousItem是文字类型的index最大的item。文字中index最小的item的previousItem是图片中index最大的item。

31 com.adobe.indesign.Event.LAYER_CHANGED的事件监听的是图层的改变事件。但是图层内部的对象排序、显示隐藏、锁定解锁,都不会监听。
只监听该图层上的显示隐藏,锁定解锁,重命名,重置颜色等操作事件。只有extend 4.5的SDK才支持
分享到:
评论

相关推荐

    (adobe清理工具)adobe_creativesuite_cleaner_tool

    Adobe Creative Suite Cleaner Tool 是一款由Adobe公司开发的专业清理工具,主要设计用于帮助用户彻底卸载Adobe Creative Suite系列软件。在日常使用中,由于各种原因,Adobe软件可能未能完全卸载,留下残余文件,...

    Adobe creative suite 4 master collection

    根据提供的标题、描述、标签及部分内容,我们可以了解到这些信息与Adobe Creative Suite 4 Master Collection的安装及使用有关,尤其侧重于序列号的应用方面。接下来,将详细解释与这些信息相关的关键知识点。 ### ...

    adobe_creative_suite_cleaner_tool

    Adobe Creative Suite Cleaner Tool 是一款由Adobe公司开发的专用清理工具,用于帮助用户在卸载Adobe Creative Suite系列软件时,更彻底、安全地清除残留在系统中的相关文件和设置。这款工具的主要目的是解决因传统...

    AdobeCreativeSuiteCleanerTool_Adobe清理工具.rar

    Adobe Creative Suite Cleaner Tool是Adobe公司为用户提供的一个专用清理工具,它的主要功能是对Adobe系列软件进行彻底的卸载和清理。在用户遇到Adobe软件安装失败、更新受阻或者出现异常情况时,这款工具就能派上...

    Creative Suite 5 Design Premium CS5 Crack

    Creative Suite 5 Design Premium 组件 • Adobe® Photoshop® CS5 Extended • Adobe® Illustrator® CS5 • Adobe® InDesign® CS5 • Adobe® Acrobat® 9.3 Professional(单独DVD) • Adobe® Flash® ...

    EN_Adobe Creative Suite 6 Production Premium Classroom in a Book.pdf

    ### Adobe Creative Suite 6 Production Premium Classroom in a Book **关键词:** Adobe Creative Suite 6, Production Premium, Classroom in a Book, 官方培训手册, Adobe Systems, DVD-ROM, Windows, MacOS ##...

    [Web网页设计制作一本通] Adobe Creative Suite 3 Web Premium All in One Desk Reference For Dummies

    《Web网页设计制作一本通:Adobe Creative Suite 3 Web Premium All in One Desk Reference For Dummies》是一本全面介绍Adobe Creative Suite 3 Web Premium软件套件的权威指南,由Damon Dean、Andy Cowitt、...

    Adobe Creative Suite 5 Master Collection

    请搜寻 下载 Adobe CS5 Master Collection LS3版本(亚太版)中文版

    Adobe Creative Cloud安装包

    Adobe Creative Cloud 6.4版本,低于5.2版本不能安装PS2022,需要升级Adobe Creative Cloud

    Adobe creative cloud的卸载方法.docx

    Adobe Creative Cloud 是一款由Adobe公司推出的创意应用管理平台,它允许用户下载、安装、更新以及管理Adobe的各种创意软件,如Photoshop、Illustrator、InDesign等。然而,有时候用户可能会遇到需要卸载Adobe ...

    Adobe Creative Cloud官方卸载工具

    Adobe Creative Cloud是Adobe公司推出的一款创意软件套件,它包含了诸如Photoshop、Illustrator、InDesign等多款知名的设计应用。然而,有时用户可能需要卸载这个平台,可能是由于性能问题、更新错误或是想要切换到...

    卸载工具Adobe Creative Cloud Cleaner Tool.zip

    【软件简介】通过使用 Creative Cloud Cleaner Tool,你可以更精确地删除可能已损坏或者导致新安装出现问题的 Creative Cloud 或 Creative Suite 应用程序安装记录。 如果在系统上安装了预发行软件,并且现在想要将...

    creative-suite-scripts:Adobe Creative Suite的脚本集合

    脚本集合,用于在Adobe Creative Suite产品系列中自动执行任务或自动生成图稿。 ##依赖 相关的Adobe Creative Suite产品“ CC”版本或更高版本(可能与较早版本兼容,但尚未经过测试) ##入门 选择右侧的“ ...

    eclipse 安装Adobe Flash Builder 4.5 插件

    在本文中,我们将深入探讨如何在Eclipse集成开发环境中安装Adobe Flash Builder 4.5插件,以便于创建和管理Flex和ActionScript项目。Adobe Flash Builder是一款强大的开发工具,专门用于构建富互联网应用程序(RIA)...

    Adobe+Creative+Suite+4_Master.7z

    这个压缩包“Adobe Creative Suite 4_Master.7z”很可能包含了该套装的主程序安装文件,即"Adobe Creative Suite 4_Master.exe"。下面我们将深入探讨Adobe CS4中的主要组件及其特点。 1. **Photoshop CS4**:作为...

    Adobe_Air_Extension_for_Dreamweaver下载种子

    Adobe Air Extension for Dreamweaver是Adobe公司为Dreamweaver开发的一款重要扩展,它使得开发者能够利用Adobe AIR(Adobe Integrated Runtime)技术在桌面环境下创建富互联网应用程序(RIA)。AIR允许开发者使用...

    Adobe Creative Cloud卸載工具

    Adobe Creative Cloud是Adobe公司推出的一款创意软件套件,它包含了诸如Photoshop、Illustrator、InDesign等多款著名的设计应用。然而,有时用户可能需要卸载这些软件,特别是在更新出现问题或者想要清理系统空间时...

    adobe creative suite cs4 万能补丁

    解压后 请将文件影藏保护去掉 这样子就打开了

    Creative Suite 5 Web Premium 讀我

    - **Adobe Extension Manager**:插件和扩展的管理。 - **Adobe CSlive在线服务整合**:提供额外的在线功能和服务,如BrowserLab、CSReview等。 #### 最低系统需求 CS5 Web Premium对硬件和操作系统有一定的要求,...

Global site tag (gtag.js) - Google Analytics