在文件

时间:2015-07-03 08:05:35

标签: javascript arrays plugins cocoascript

我目前正在编写Sketch插件,并且我试图将数据存储在全局数组中。在 copy.sketchscript 中生成数据,并在 paste.sketchscript 中尝试检索数组数据。但是,当我记录变量时,它返回空。如何正确更新阵列数据以便每个功能都可以访问它?

这是我的代码。

库/ common.js

var verticalRulers = new Array; // global?

function copyVertical(context) {
    var doc = context.document

    var target = [[doc currentPage] currentArtboard] || [doc currentPage]
    var countVertical = [[target verticalRulerData] numberOfGuides]

    for(var i=0; i < countVertical; i++) {
        var thisRuler = [[target verticalRulerData] guideAtIndex:i]
        verticalRulers.push(thisRuler);
    }
}

function pasteVertical(context) {
    var doc = context.document
    var target = [[doc currentPage] currentArtboard] || [doc currentPage]

    for(i = 0; i < verticalRulers.length; i++) {
        var thisRuler = verticalRulers[i];

        [[target verticalRulerData] addGuideWithValue: thisRuler]
    }
}

copy.sketchscript

@import 'library/common.js'

function onRun(context) {
    verticalRulers = copyVertical(context);
    log(verticalRulers) // return right data from variable;
}

paste.sketchscript

@import 'library/common.js'

function onRun(context) {
    pasteVertical(context);
    log(verticalRulers); // returns an empty array
}

0 个答案:

没有答案