-
1. Re: How to construct a Rectangle element
Ten A May 22, 2011 4:28 PM (in response to Big RA)Hi, try below
var myRectangle = app.activeDocument.pathItems.rectangle(-100,100,150,150);
You can add rectangles use pathItems rectangle method.
PathItem PathItems.rectangle (top: number, left: number, width: number, height: number[, reversed: bool=false])
Ten.
-
2. Re: How to construct a Rectangle element
Big RA May 22, 2011 11:05 PM (in response to Ten A)I am looking for a Rectangle that I can store in an array, not one in a document. Maybe such a thing doesn't exist. Specifically, I am trying to center text labels in circles when they are already in a circle. I can get the geometricBounds or visibleBounds of each, but I don't know how to get that in an array. Placing a Rectangle in the array would satisfy the need. It would be nice to get the functionality of width, height, relative to top, bottom, left, right, that a Rectangle offers. Oddly enough, text objects have different parameters of these available than do circles. I would like a class Rectangle that tracks all these when I set them and ask for them.
-
3. Re: How to construct a Rectangle element
Ten A May 23, 2011 2:11 AM (in response to Big RA)Here is a sample code store rectangles in an Array.
var myRectangle = new Array();
for (i=0;i<10;i++){
myRectangle[i] = app.activeDocument.pathItems.rectangle(-100,i*15+30,10,10);
}var c = new CMYKColor;
c.cyan= 100;
c.magenta = 0;
c.yellow = 0;
c.black = 0;myRectangle[4].fillColor = c;
Ten
-
4. Re: How to construct a Rectangle element
[Jongware] May 23, 2011 4:13 AM (in response to Ten A)Despite your insistence, RA isn't referring to physically drawn rectangles *at all*.
Theoretically, a "rectangle class" would allow one to construct a rectangle in several ways -- origin, size, top left and bottom right points, etc. It seems the built-in "Rect" class is just a thin wrapper around a basic array, so that's not going to work.
Perhaps you could build your own. Javascript allows one to create a new class from scratch and define all of the methods and properties you might need.
-
5. Re: How to construct a Rectangle element
[Jongware] May 23, 2011 4:14 AM (in response to [Jongware])I can get the geometricBounds or visibleBounds of each, but I don't know how to get that in an array.
... Maybe you want to expand on that. Both *are* returned as a simple 4-element array.
-
6. Re: How to construct a Rectangle element
Big RA May 23, 2011 7:40 AM (in response to [Jongware])True, I could store the geometricBounds or visibleBounds, but these don't have the methods for top, bottom, right, left, width, height. I tried to make a class, but ExtendScript tells me I'm making "illegal use of reserved word 'class,'" so I haven't pursued that further yet.
I would like to write a generic "align" routine that would align two objects, but some items have top and height while others have top and bottom, so the procedure to align depends on which kind of object is passed. Putting a class wrapper around geometricBounds would do it since they all seem to have geometricBounds, but I haven't figured out how to do that either. I could also use "geometricBounds[0]" etc, but that makes the code big and obscure.
As you can tell, I'm new to javascript and this is my learning process. Extendscript seems to differ somewhat from conventional javascript, making the effort a bit more difficult.
-
7. Re: How to construct a Rectangle element
chris gebab May 23, 2011 9:34 AM (in response to Big RA)hi,
you cant use class, try something like that and search for javascript prototyping.
function Point(x,y){
this.x=x;
this.y=y
}
function MyRect(bounds){
this.width= bounds[?]-bounds[?];
and so on
dont forget:
this.center = new Point(a,b);
}
MyRect.prototype.doubleWidth=function(){
return this.width * 2
}
var rect= new MyRect( Item.someBounds);
happy scripting
chris
-
8. Re: How to construct a Rectangle element
[Jongware] May 23, 2011 1:32 PM (in response to chris gebab)Ah yes -- I didn't remember where I saw this before and had to ask Marc Autret first
Check this page of his: http://www.indiscripts.com/post/2010/05/operator-overloading-with-extendscript
-
9. Re: How to construct a Rectangle element
Big RA May 23, 2011 6:16 PM (in response to chris gebab)Thanks. I guess I'll have to try something like that.


