Skip to main content
smithcgl9043167
Inspiring
August 1, 2019
Answered

Slider help to adjust scale and rotation:

  • August 1, 2019
  • 2 replies
  • 1058 views

Hello everyone!

I don't understand why when I apply a value to the slider scala, then another value to the slider rotate the values are reset. Why don't my values apply when I switch between scale and rotate sliders? How can I resolve the error?

Thank you!

dialog = new Window("dialog");     dialog.text = "test";

group1 = dialog.add("group");

group1.orientation = "row";

group1.alignChildren = ["left","center"];

statictext1 = group1.add("statictext");  statictext1.text = "Scale:";

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 = "º";

button1 = dialog.add("button");  button1.text = "Done";

button1.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 ("scale", "scale()");

    app.refresh();

}   

ts.onChange= function () {   

    slider1.value  = Number(ts.text); 

    doc.activeHistoryState = currentStatus;  app.activeDocument.suspendHistory ("scale", "scale()");

    app.refresh();

   }

slider2.onChange= function () {   

    tr.text = Math.round(slider2.value ); 

    doc.activeHistoryState = currentStatus;  app.activeDocument.suspendHistory ("rotate", "rotate()");

    app.refresh();

   }   

tr.onChange= function () {   

    slider2.value  = Number(tr.text); 

    doc.activeHistoryState = currentStatus;  app.activeDocument.suspendHistory ("rotate", "rotate()");

    app.refresh();

   }

function scale(){ 

    activeDocument.activeLayer.resize(slider1.value, slider1.value, AnchorPosition.MIDDLECENTER);

}

function rotate(){ 

    with (activeDocument.activeLayer) {rotate(slider2.value)};

}

button1.onClick = function(){

    dialog.close()

    }

dialog.show();

This topic has been closed for replies.
Correct answer r-bin

Combine the rotate and scale functions into one or make them the same.

function scale(){   

    activeDocument.activeLayer.resize(slider1.value, slider1.value, 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)}; 


Or completely change the script algorithm. )

2 replies

JJMack
Community Expert
Community Expert
August 1, 2019

Off the top of my head a guess I think it may depend on the type layer. If its a destructive  edit like rotating a pixels layers as oppose  to rotating a Smart Object layer.  Even rotating vector layer like a text layer changes the layers bounds and it  becomes a different layer than it was.  For layers other that Smart a layer bounds  is what may be for rotation so once a layer is rotated it has a new bounds which is squared to the canvas its rotation is 0.  All Smart object layer have an associated transform other types of layers do so once rotated the layers rotation becomes not rotated is has become a different layer physically relative to the document canvas.

JJMack
r-binCorrect answer
Legend
August 1, 2019

Combine the rotate and scale functions into one or make them the same.

function scale(){   

    activeDocument.activeLayer.resize(slider1.value, slider1.value, 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)}; 


Or completely change the script algorithm. )

smithcgl9043167
Inspiring
August 1, 2019

Man, you were phenomenal! I spent a few days and nights roasting my brains trying to fix this ... I have a lot to learn. Thank you r-bin