Frage

Ich bin ein paar Helfer Klassen für scripting Adobe Illustrator zu schreiben.

startet Mein Problem im Eyelet Objekt. Als ich es instanziiert scheitert es an den ersten new Group() weil anscheinend nicht Group keinen Konstruktor hat.

Hier ist eine abgespeckte Version von meinem Code:

/****************** 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();

Wenn ich schreibe

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

ich

Group does not have a constructor

Ich habe diesen Code durch JSLint läuft und ich kann nicht sehen, warum dies nicht funktioniert. Jede Hilfe wäre sehr geschätzt.

War es hilfreich?

Lösung

Es stellt sich heraus die Tatsache, das in Adobe Illustrator ist ist relevant. Ich benannte das Group Objekt MyGroup als Dan Breslau vorgeschlagen und es funktionierte, als ich erwartet hatte. Es scheint, Illustrator ein globales Group Objekt hat, die das Problem verursacht wurde. Vielen Dank für Ihre Hilfe.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top