Skip to main content
mimozemská hůl
Inspiring
October 25, 2020
Answered

Trying to delete history state with a dialog button

  • October 25, 2020
  • 2 replies
  • 1457 views

Hi,

according to the script at the link below:

https://community.adobe.com/t5/photoshop/slider-help-to-adjust-scale-and-rotation/td-p/10581897?page=1

 

In addition to the script found at the link above I have added a Cancel button where it has to delete the history state upon closing the dialog:

buttonCancel = dialog.add("button"); buttonCancel.text = "Cancel";
buttonCancel.preferredSize.width = 80;

buttonCancel.onClick = function(){
//Select current history state
ref1 = new ActionReference();
desc1 = new ActionDescriptor();
ref1.putProperty(cTID('HstS'), cTID('CrnH'));
desc1.putReference(cTID('null'), ref1);
executeAction(cTID('slct'), desc1, DialogModes.NO);

//Delete selected history state
ref2 = new ActionReference();
desc2 = new ActionDescriptor();
ref2.putProperty(cTID('HstS'), cTID('CrnH'));
desc2.putReference(cTID('null'), ref2);
executeAction(cTID('Dlt '), desc2, DialogModes.NO);

dialog.close();
}

 

The code simply does nothing except closing the dialog box.

 

In addition, I would like to know how to create a condition for what histrory state to be deleted upon closing the dialog box.

 

Thanks,

Damian

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

You may try with your example by moving the 'scale' slider and see what I mean. In other words, when moving the slider to, let's say, 120% and after that returning it to 100%, it does not reset the image to its original scale, i.e. the 120% becomes its original scale. Try to scale it to 0% and than return it to 100%, it does not return it as 0% becomes its original scale.

 

Same goes with the rotation slider, rotate the image to 20deg and then return it to 0deg you will see it does not return to its original 0deg rotation.

 

I hope you can now understand the problem I've tried to  describe.

 

Thanks for your prescious time explaining.


Yes, I realized that I messed up the functionality of your script.
Sorry.

What do you want to happen on the OK and Cancel buttons?

I noticed that the scale() and rotate() functions are exactly the same, but you create a step for them in history with different names.
Use the same name for the history step and then it will almost solve your problem with your original code. Don't use my code.
 

2 replies

Legend
October 25, 2020
Wrap the code in the onClick function with
try { ... } catch (e) {alert (e); }

If there is an alert, what does it say?
 
mimozemská hůl
Inspiring
October 26, 2020

I've wrapped the code but getting no alert at all.

Legend
October 26, 2020
So everything works. Insert some alerts before and after the "delete" command. What is happening in the history panel at this time? After all, something is deleted, and without errors.

You post only script fragments. It is not known what is going on there in your version of the code.
 
 
mimozemská hůl
Inspiring
October 25, 2020

I have even tried:

buttonCancel = dialog.add("button");  buttonCancel.text = "Cancel";
buttonCancel.preferredSize.width = 80;

doc = app.activeDocument;
currentStatus = doc.activeHistoryState;

buttonCancel.onClick = function(){
	currentStatus = doc.historyStates['rotate'];

	ref1 = new ActionReference();
	desc1 = new ActionDescriptor();
	ref1.putProperty(cTID('HstS'), cTID('CrnH'));
	desc1.putReference(cTID('null'), ref1);
	executeAction(cTID('Dlt '), desc1, DialogModes.NO);
	
	dialog.close();
}

to select a history state by name, delete it and then close the dialog box. No chances I am getting any result, as it does not want to listen at all.

mimozemská hůl
Inspiring
October 25, 2020

I have obviously made a mistake in a part of the code, instead:

currentStatus = doc.historyStates['rotate'];

I have to replace it with:

doc.activeHistoryState = doc.historyStates['rotate'];

and it selects the first 'rotate' state, and it does not execute the deleting process.

 

What I clearly want to achieve is the cancel button to delete the last history state made by the sliders upon closing the dialog box.

mimozemská hůl
Inspiring
October 25, 2020

I have found the solution to delete the history state after canceling the slider preview and here it is:

 

buttonOK.onClick = function(){
	ref1 = new ActionReference();
	desc1 = new ActionDescriptor();
	doc.activeHistoryState = doc.historyStates['rotate'];
	ref1.putProperty(charIDToTypeID('HstS'), charIDToTypeID('CrnH'));
	desc1.putReference(charIDToTypeID('null'), ref1);
	executeAction(charIDToTypeID('Dlt '), desc1, DialogModes.NO);

	app.activeDocument.suspendHistory ("rotated", "rotate()"); // it changes the history name to rotated upon OK

	dialog.close();
}

buttonCancel.onClick = function(){
	doc.activeHistoryState = doc.historyStates['rotate']; // it deletes only the history name found created while moving the sliders

	ref1 = new ActionReference();
	desc1 = new ActionDescriptor();
	ref1.putProperty(charIDToTypeID('HstS'), charIDToTypeID('CrnH'));
	desc1.putReference(charIDToTypeID('null'), ref1);
	executeAction(charIDToTypeID('Dlt '), desc1, DialogModes.NO);

	dialog.close();
}

Now, the only thing I need is to create a condition to delete either 'rotate' or 'scale' history name.