How to scale an object horizontally without dependency after its rotation is applied
Hello,
I am trying to find a way on how to scale an object horizontally without dependency after its rotation is done. For example, if the object is square and apply horizontal scale without rotation it will become a rectangle, and after applying rotation on the rectangle by 90°, the horizontal scaling now will become a vertical one and will continue to scale up or down the same sides of the rectangles independently from the rotation applied before. This is the same as when creating a shape and using the transform properties to change the width or height of that object, and no matter how the object is rotated, the x or y coordinate for scaling is the same.
Here is the code where the scaling and rotation is applied:
dialog = new Window("dialog");
dialog.text = "test";
group1 = dialog.add("group");
group1.orientation = "row";
group1.alignChildren = ["left","center"];
statictext1 = group1.add("statictext"); statictext1.text = "ScaleH:";
slider1 = group1.add("slider {minvalue: 0, maxvalue: 300, value: 100}");
slider1.preferredSize.width = 200;
ts = group1.add("edittext"); ts.text = "100";
ts.preferredSize.width = 40;
statictext2 = group1.add("statictext");statictext2.text = "%";
group2 = dialog.add("group");
statictext3 = group2.add("statictext"); statictext3.text = "Rotate:";
slider2 = group2.add("slider {minvalue: -180, maxvalue: 180, value: 0}");
slider2.preferredSize.width = 200;
tr = group2.add("edittext"); tr.text = "0";
tr.preferredSize.width = 40;
statictext4 = group2.add("statictext"); statictext4.text = "º";
buttonOK = dialog.add("button"); buttonOK.text = "Done";
buttonOK.preferredSize.width = 80;
buttonCancel = dialog.add("button"); buttonCancel.text = "Cancel";
buttonCancel.preferredSize.width = 80;
var doc = app.activeDocument;
var currentStatus = doc.activeHistoryState;
slider1.onChange = function () {
ts.text = Math.round(slider1.value );
doc.activeHistoryState = currentStatus;
app.activeDocument.suspendHistory ("scaled", "scaleH()");
app.refresh();
}
ts.onChange = function () {
slider1.value = Number(ts.text);
doc.activeHistoryState = currentStatus;
app.activeDocument.suspendHistory ("scaled", "scaleH()");
app.refresh();
}
slider2.onChange = function () {
tr.text = Math.round(slider2.value );
doc.activeHistoryState = currentStatus;
app.activeDocument.suspendHistory ("rotated", "rotate()");
app.refresh();
}
tr.onChange = function () {
slider2.value = Number(tr.text);
doc.activeHistoryState = currentStatus;
app.activeDocument.suspendHistory ("rotated", "rotate()");
app.refresh();
}
function scaleH(){
activeDocument.activeLayer.resize(slider1.value, undefined, AnchorPosition.MIDDLECENTER);
with (activeDocument.activeLayer) {rotate(slider2.value)};
}
function rotate(){
activeDocument.activeLayer.resize(slider1.value, slider1.value, AnchorPosition.MIDDLECENTER);
with (activeDocument.activeLayer) {rotate(slider2.value)};
}
buttonOK.onClick = function(){
doc.activeHistoryState = doc.historyStates['rotate'];
(ref1 = new ActionReference()).putProperty(charIDToTypeID('HstS'), charIDToTypeID('CrnH'));
(desc1 = new ActionDescriptor()).putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('Dlt '), desc1, DialogModes.NO);
app.activeDocument.suspendHistory ("rotated", "rotate()");
dialog.close();
}
buttonCancel.onClick = function(){
doc.activeHistoryState = doc.historyStates['rotate'];
(ref1 = new ActionReference()).putProperty(charIDToTypeID('HstS'), charIDToTypeID('CrnH'));
(desc1 = new ActionDescriptor()).putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('Dlt '), desc1, DialogModes.NO);
dialog.close();
}
dialog.show();
Thank you.
