我正在写一些辅助Adobe Illustrator的帮助课程。

我的问题始于孔眼对象。当我实例化时,它首先失败 new Group() 因为显然 Group 没有构造函数。

这是我的代码的删除版本:

/****************** Collection Class **********************/

function Collection() {
    this.parent = app.activeDocument;
    this.typename = "Collection";
}

    Collection.prototype.setName = function(name) {
        this.instance.name = name;
    };

/****************** Group (extends collection) *****************/

function Group(name, parent) {
    this.parent = parent || this.parent;
    this.instance = this.parent.groupItems.add();
    if(name) {
        this.setName(name);
    } else {
        this.setName("Group");
    }
}

Group.prototype = new Collection();

/****************** Shape Class **********************/

function Shape() {
    this.parent = app.activeDocument;
    this.typename = "Shape";
}

Shape.prototype.setName = function(name) {
        this.instance.name = name;
    };

Shape.prototype.stroke = function(width, color) {
        this.instance.stroked = true;
        this.instance.strokeWeight = width;
        this.instance.strokeColor = color;
    };

/****************** Line (extends Shape) **********************/

function Line(parent, start, end) {

    this.instance = parent.pathItems.add();
    // [ [startX, startY], [endX, endY] ]
    this.instance.setEntirePath([start,end]);

}

Line.prototype = new Shape();

/****************** Eyelet (extends Shape) **********************/

function Eyelet(parent, position) {
    this.instance = new Group("Eyelet", parent);
    var whiteCross = new Group("White", this.instance);
    var blackCross = new Group("Black", this.instance);

    var build = function(group, color, width) {
        var vertical = new Line( group , [0 , 0] , [0 , 50] );
        vertical.setName("vertical");
        vertical.stroke(width, color);
        var horizontal = new Line( group , [0 , 50] , [50 , 0] );
        horizontal.setName("horizontal");
        horizontal.stroke(width, color);
    };

    build(whiteCross.instance, white, (3 * scale) );
    build(blackCross.instance, black, (1 * scale) );

    this.instance.position = position;

}

Eyelet.prototype = new Shape();

当我写作时

var eyelet = new Eyelet(layer2, [10,10]);

我明白了

Group does not have a constructor

我已经通过JSlint运行了此代码,我看不出为什么这不起作用。任何帮助将非常感激。

有帮助吗?

解决方案

事实证明,这是在Adobe Illustrator中 相关的。我重命名 Group 反对 MyGroup 正如丹·布雷斯劳(Dan Breslau)所建议的那样,它正如我预期的那样起作用。插画家似乎有一个全球 Group 引起问题的对象。谢谢你的帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top