Copy link to clipboard
Copied
I created new layer in my document, and then a new ellipse inside that layer.
I am trying to position the new ellipse at the top of the layer (vertically) and in the center of layer along the x axis (horizontally).
Nothing I have tried seems to move the object left of the layers starting x position (I can move it right just fine!?!).
I am confused because my top and height properties of the layer are negative numbers - but when I look at the ruler, all are above zero?
What am I doing wrong in terms of positioning the ellipse in the layer?
Here is a sample of my script:
var childLayer = currentLayer.layers
;
var xmin = childLayer.pageItems[0].geometricBounds[0].toFixed(2); // top
var ymin = childLayer.pageItems[0].geometricBounds[1].toFixed(2); // left
var xmax = childLayer.pageItems[0].geometricBounds[2].toFixed(2); // bottom
var ymax = childLayer.pageItems[0].geometricBounds[3].toFixed(2); // rightvar newBoneLayer = boneLayer.layers.add();
newBoneLayer.name = childLayer.name.replace(OBJECT_MARKER, "");var halfOfWidth = parseFloat(childLayer.pageItems[0].width/2).toFixed(2);
var boneGuideXPosition = parseFloat(xmin + halfOfWidth).toFixed(2);
var boneGuide = newBoneLayer.pathItems.ellipse(ymin,boneGuideXPosition, 10.0, 10.0, true, false);
boneGuide.stroked = true;
boneGuide.filled = true;
boneGuide.opacity = 40.0; // set to 40% opacity
var newRGBColor = new RGBColor();
newRGBColor.red = 204;
newRGBColor.green = 255;
newRGBColor.blue = 255;
boneGuide.fillColor = newRGBColor;
Sorry my bad.
even in my script it should be...
var x = AB[0]+((AB[2]-AB[0])/2);
Copy link to clipboard
Copied
Its not the layer your positioning to.
You want to position to the artboard.
var doc = app.activeDocument;
var TOmm = 2.83466796875;
var AB = doc.artboards[0].artboardRect;
var x = AB[0]+(AB[2]/2);
var y = AB[1];
var w = 100*TOmm // ellipse Width
var h = 100*TOmm // ellipse Hight
var newEllipse = doc.pathItems.ellipse(0,x-(w/2), w, h, true, true);
Copy link to clipboard
Copied
I think my description of my problem wasn't very good.
I do not want to center the ellipses in the whole page (art board).
Picture 1 shows you what your code results in (all my red circles centered at top of whole page / art board).
Picture 2 shows you what I'm trying to do (a red circle at the top, center of each individual layer).
Copy link to clipboard
Copied
For example if I change your code to this I'm closer, but the circles end up on the far right hand corner of each layer (not centered):
var TOmm = 2.83466796875;
var AB = childLayer.pageItems[0].geometricBounds; //var AB = _doc.artboards[0].artboardRect;
var x = AB[0]+(AB[2]/2);
var y = AB[1];
var w = 3*TOmm // ellipse Width
var h = 3*TOmm // ellipse Height
var boneGuide = newBoneLayer.pathItems.ellipse(y,x-(w/2), w, h, true, true);
It results in this:
Copy link to clipboard
Copied
Sorry my bad.
even in my script it should be...
var x = AB[0]+((AB[2]-AB[0])/2);
Copy link to clipboard
Copied
That totally did it!
Thanks for your help, I have spent 5 hours trying to figure out the weird coordinate system.
Copy link to clipboard
Copied
just for future...
for bounds etc.
0=left,
1=top,
2=right,
3=bottom,
Glad I could help you out
Copy link to clipboard
Copied
Even knowing that didn't help, because top and height were negative numbers!?!
Copy link to clipboard
Copied
its a bit strange.
my trick is to keep it all relative not fixed.
Copy link to clipboard
Copied
And I noticed you fixed the "y" where I just had "0"