I think if you move your solid, you should not put the origin in the vertices part. So maybe Shape.vertices should look like this:
Shape.vertices = [
- [this.large, 0],
[this.large, 0],
[this.large, velen - this.arrowheight],
[this.large + this.arrowwidth, velen - this.arrowheight],
[0, velen],
[-this.large - this.arrowwidth, velen - this.arrowheight],
[-this.large, velen - this.arrowheight],
- [this.large, 0]
];
But I would not use solid. Why not use shape layer instead? Something like this may work:
//The origin is supposed to be the place on screen where the arrow gets placed.
function Vector(x, y, origin, r, g, b) {
this.x = x;
this.y = y;
this.angle = -myAngle(x, y);
this.origin = origin;
velen = Math.round(length(x, y));
this.length = velen;
this.r = r;
this.g = g;
this.b = b;
this.lname = "(" + this.x.toString() + "," + this.y.toString() + ")"; //So that the name layer matches the coordinates of the vector.
this.large = 10; //The arrow base it twice as large
this.arrowwidth = 7; //
this.arrowheight = 20;
var myShape = new Shape;
myShape.closed = true;
//The following line is me trying things out :
myShape.vertices = [
- [this.large, 0],
[this.large, 0],
[this.large, velen - this.arrowheight],
[this.large + this.arrowwidth, velen - this.arrowheight],
[0, velen],
[-this.large - this.arrowwidth, velen - this.arrowheight],
[-this.large, velen - this.arrowheight],
- [this.large, 0]
];
myShapeLayer = createShape(this.lname, myShape);
myShapeLayer.rotation.setValue(this.angle);
myShapeLayer.position.setValue(this.origin);
//mySolid.anchorPoint.setValue(origin);
function createShape(shapeName, shapeValue) {
var myShape = app.project.activeItem.layers.addShape();
myShape.name = shapeName;
var myShapeGroup = myShape.property("ADBE Root Vectors Group");
var path1 = myShapeGroup.addProperty("ADBE Vector Shape - Group")("ADBE Vector Shape");
path1.setValue(shapeValue);
//var myStroke = myShape("Contents").addProperty("ADBE Vector Graphic - Stroke");
var myFill = myShape("Contents").addProperty("ADBE Vector Graphic - Fill");
myFill("ADBE Vector Fill Color").setValue([r,g,b]);
return myShape;
}
}
var myVector = new Vector(12, 12, [0, 0], 1, 1, 1)
I have tested this without the angle and the length part, as I am missing those functions (I just used square root of the sum of squares for a few tests for length, ignored the angle part).
Also, as a suggestion. If you do not intend to use your variable outside the function (eg: use myVector.arrowWitdh, myVector.origin etc after declaring myVector) do not declare them with “this.”. That declaration makes them public, and I am not sure you want that.
LE: What’s up with the thread name? 😀