I've got a fairly long applescript that runs a program where it formats pictures in a folder then saves them to a new folder with the same slug and a number. I now want it to add a courtesy to that image. I have it replacing the text, but I need a script that will resize a layer named "bar" to fit the courtesy. Right now what happens is the text could be longer than the bar. Any Ideas? the layers names are "Bar" and "Text" and they are in a group called Courtesy. I've tried a few things but the bar always seems to become too long.
**I forgot to mention that the applescript sets the active layer to the layer "Text" before the javascript runs.
This is what I have so far: (it keeps throwing me an error at the resize saying it needs a number.)
Code: Select allvar layerBar = activeDocument.layerSets["Courtesy"].artLayers.getByName(" Bar");
var layerText = activeDocument.layerSets["Courtesy"].artLayers.getByName("Text");
var layerBarHeight = parseInt(layerBar.height);
var widthText = parseInt(layerText.width);
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
layerBar.resize(widthText,layerBarHeight,AnchorPosition.MIDDLELEFT);
app.preferences.rulerUnits = startRulerUnits;
Layer resize to the same dimensions as another layer
-
Mike Hale
Layer resize to the same dimensions as another layer
If I understand what you are trying to do and the text layer is a paragraph text you need to get the image layer's height from that layer's bounds. Only paragraph text layers have a width and height property.
Some thing like this...
var layerBarBounds = layerBarBounds[3].as('p')-layerBarBounds[1].as('px');
Some thing like this...
var layerBarBounds = layerBarBounds[3].as('p')-layerBarBounds[1].as('px');
-
danroch48
Layer resize to the same dimensions as another layer
getting closer, however now its resizing to insane proportions.
ex. the width of 'Text' layer will come out on the alert as 600px (which when I check afterwards is the correct width) then for some odd reason the 'Bar' will be resized to 12,000px. Any ideas?
Code: Select allvar layerBar = activeDocument.layerSets["Courtesy"].artLayers.getByName(" Bar");
var layerText = activeDocument.layerSets["Courtesy"].artLayers.getByName("Text");
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var widthText = layerText.bounds[2].value - layerText.bounds[0].value;
alert (widthText)
layerBar.resize(widthText,undefined,AnchorPosition.MIDDLELEFT);
app.preferences.rulerUnits = startRulerUnits;
** ok I know whats going on now.. I need it to resize by pixels not percent. Not sure how to do that if there is a way to do that.
ex. the width of 'Text' layer will come out on the alert as 600px (which when I check afterwards is the correct width) then for some odd reason the 'Bar' will be resized to 12,000px. Any ideas?
Code: Select allvar layerBar = activeDocument.layerSets["Courtesy"].artLayers.getByName(" Bar");
var layerText = activeDocument.layerSets["Courtesy"].artLayers.getByName("Text");
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var widthText = layerText.bounds[2].value - layerText.bounds[0].value;
alert (widthText)
layerBar.resize(widthText,undefined,AnchorPosition.MIDDLELEFT);
app.preferences.rulerUnits = startRulerUnits;
** ok I know whats going on now.. I need it to resize by pixels not percent. Not sure how to do that if there is a way to do that.
-
danroch48
Layer resize to the same dimensions as another layer
Close but still not working right.
1581px is the width of the bar before it gets resized.
Code: Select allvar layerBar = activeDocument.layerSets["Courtesy"].artLayers.getByName(" Bar");
var layerText = activeDocument.layerSets["Courtesy"].artLayers.getByName("Text");
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var widthText = layerText.bounds[2].as('px') - layerText.bounds[0].as('px');
var newWidthText = 100/widthText;
var finalWidth = newWidthText*1581;
alert (finalWidth)
layerBar.resize(finalWidth,undefined,AnchorPosition.MIDDLELEFT);
app.preferences.rulerUnits = startRulerUnits;
1581px is the width of the bar before it gets resized.
Code: Select allvar layerBar = activeDocument.layerSets["Courtesy"].artLayers.getByName(" Bar");
var layerText = activeDocument.layerSets["Courtesy"].artLayers.getByName("Text");
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var widthText = layerText.bounds[2].as('px') - layerText.bounds[0].as('px');
var newWidthText = 100/widthText;
var finalWidth = newWidthText*1581;
alert (finalWidth)
layerBar.resize(finalWidth,undefined,AnchorPosition.MIDDLELEFT);
app.preferences.rulerUnits = startRulerUnits;
-
Mike Hale
Layer resize to the same dimensions as another layer
You need to get the current size of both layer or at least the width and height of the photo.
Then you calculate the percent change needed to get one side to the desired size.
Then use that percent and the other side of the photo to get that new value
Then supply both to the resize method.
If you still need help post the current size of the layers and the desired new value for one side.
Then you calculate the percent change needed to get one side to the desired size.
Then use that percent and the other side of the photo to get that new value
Then supply both to the resize method.
If you still need help post the current size of the layers and the desired new value for one side.