Align shape objects and text to shapes
Hi folks,
I am very new to Illustrator but have been using Photoshop for the last 22 years. I have been scripting Photoshop (with help at times from the good people in communities like this) for about 8 years. I attempting to learn illustrator as means to an end but what I am doing involves everything to be handled by a script. I have most of the process already done but need to figure out how to align objects (shapes?) with objects and text with objects. Please excuse my ignorance when it comes to the exact vocabulary used to describe the componants of illustrator.
Below I have a visual representation of what I am trying to achieve. I have done some research and found a script that I hoped would work. However, the script throws an error. I'm not sure if it is due to the newer version of Illustrator or if I am doing something wrong. The original script by Peter Kahrel appears to no longer be available (broken link) but it is posted, Peter Kahrel's code by jarosławz53072541 in Adobe's InDesign forum.

Breaking it down: I have 3 objects; a box, rectangle shape (A) that adjusts in length horizontally according to data being input and another shape above it (B). Above that is text, a number.
As the lower box (A) changes length, I would like the shape above it (B) to center align with right edge of the lower box. I then would like the text above to center align to the center of shape B.
In the event that the lower box expands near the max width I need to align the right edge of the text with the right edge of the upper shape (B). This prevents the text going beyond the edge of the artboard which is a set width and can't be changed.
So, to summize; I need to be able to
1) Horizontally center align a shape object with the right edge of another shape object.
2) Horizontally center align text with the right edge of a shape object.
3) Align the right edge of text with the left edge of a shape object.
I will be inserting the code into an existing script so any help with this in a clean and usable format that I, as a rookie can handle, would be greatfully appreciated.
Sincerely,
Limey
