function with if then else and opacity

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Mike Hale

function with if then else and opacity

Post by Mike Hale »

I may have some time after the holiday.

To use suspendHistory you put your code that you don't want recorded in history in a function. You then call that function with suspendHistory.

Code: Select allapp.activeDocument.suspendHistory('String to place in history to undo the entire function','changeBlendMode()');

Where changeBlendmode is a function that does the work you want to hide.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

getInteger

function with if then else and opacity

Post by getInteger »

Thanks for the after holiday help
about the suspendhistory i was able to have only one action ("blabla") in the history with this code:

But what i want is a script that is totally invisible in the history, no undo possible on it, is this possible ?

Code: Select allvar curentLayer = app.activeDocument.activeLayer;
var curentParent = curentLayer.parent;
var currentIndex = getLayerIndex( curentParent, curentLayer );

app.activeDocument.suspendHistory('blabla','tatam()');




function tatam(){
if(curentParent.artLayers[currentIndex+1].opacity==100){
   curentParent.artLayers[currentIndex+1].opacity=0;
   if(curentParent.artLayers[currentIndex].opacity!=100){
   curentParent.artLayers[currentIndex].opacity=100;
   }
}

else{
   if(curentParent.artLayers[currentIndex].opacity!=0){
   curentParent.artLayers[currentIndex].opacity=0;
   }
   curentParent.artLayers[currentIndex+1].opacity=100;
}
}

function getLayerIndex( parent, layer ){
    for(var i=0;i<parent.artLayers.length;i++){
        if(parent.artLayers==layer) return i;
    }
};
Mike Hale

function with if then else and opacity

Post by Mike Hale »

You can not make a script 'undo-able'. The best you can do is wrap the entire script in a function and call that main function with suspendHistory().
getInteger

function with if then else and opacity

Post by getInteger »

Actually some scripts are not seen in the history if they don't use functions which appears in the history.
For example if i do a script that change the brush size it will never appear in the history when i use it.

The problem here is that all the ways i know to change layer opacity creates stuff in history ("Blending Options" or "Master Opacity Change")
I searched a bit on the forum, you were talking about some way to change visibility without any history:

bb/viewtopic.php?f=9&t=1354&p=5278&hili ... oofy#p5278

Is there a way, "cheating", to have my script not creating any history when used?
Paul MR

function with if then else and opacity

Post by Paul MR »

You could always purge the history..
Code: Select allapp.purge(PurgeTarget.HISTORYCACHES);
getInteger

function with if then else and opacity

Post by getInteger »

I will try to explain what i want more correctly.
The opacity script should be seen the same way you're using the F button in Photoshop, or space to move into the document, like a kind of viewer tool,this way there is no history.
I need the history to undo bad paint moves etc.
I just need 0 script action in the history because it's very confusing, imagine each time you're zooming in in or out if there was an history event about it between your paint moves, it's so annoying, i can't believe this is not possible to do even with cheating