Copy link to clipboard
Copied
Hi all,
I have working script which replaces smart objects with the new image, and it is working as expected.
function someFunction(){
//some code
changeSOContent();
}
function changeSOContent(){
var myDocument = currentDocument;
// some code
var imageGroup = myDocument.layerSets.getByName('images-group');
var imageSmartObj = imageGroup.artLayers.getByName('image-so');
var imageFiles = Folder(imgDirPath).getFiles(/\.(jpg|psd|png)$/i);
for (var i = 0; i < imageFiles.length; i++) {
imageSmartObj = replaceContents(imageFiles, imageSmartObj);
myDocument.saveAs((new File(destinationFolder + "/" + theName + ".jpg")), jpgopts, true);
}
}
function replaceContents(newFile, theSO) {
app.activeDocument.activeLayer = theSO;
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc3.putPath(idnull, new File(newFile));
var idPgNm = charIDToTypeID("PgNm");
desc3.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
return app.activeDocument.activeLayer;
}
But I want to add progress bar while script is doing the job. So I try like this
function someFunction(){
app.doForcedProgress("Progress bar start.", "changeSOContent()");
}
function changeSOContent(){
var myDocument = currentDocument;
//some code
var imageGroup = myDocument.layerSets.getByName('images-group');
var imageSmartObj = imageGroup.artLayers.getByName('image-so');
for (var i = 0; i < imageFiles.length; i++) {
var canContinue = app.doProgressSubTask(i, imageFiles.length, "updateProgress()");
if (!canContinue) return;
function updateProgress(){
app.changeProgressText("Current image: " + i + "");
}
imageSmartObj = replaceContents(imageFiles, imageSmartObj);
myDocument.saveAs((new File(destinationFolder + "/" + theName + ".jpg")), jpgopts, true);
}
}
function replaceContents(newFile, theSO) {
app.activeDocument.activeLayer = theSO;
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc3.putPath(idnull, new File(newFile));
var idPgNm = charIDToTypeID("PgNm");
desc3.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
return app.activeDocument.activeLayer;
}
But I've got error that said
General Photoshop error Occured. This functionality may not be available in this version of Photoshop.
for the executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
Somehow, when I call function which contains executeAction() script breaks whit this error. When I comment out everything in replaceContents(), everything goes smoothly. Of course, smart object hasn't being replaced, but rest of the code runs without error
I've try to figure it out for days, but with no success, because there is no enough search results for doProgress().
Photoshop version is CC 2017
I've also tried solution with Window palette with win.update(); but I've got flickering and is not working as expected.
Can anybody help me about this?
Thanks
Copy link to clipboard
Copied
When you get that message look at the layers palette. Is the current targeted layer a smart object layer. The message is a common message you get when some dependency the command has currently does not exist so the command is unavailable for use. The command may well be in your version of Photoshop but it is currently grayed out and unavailable for use.
Copy link to clipboard
Copied
Adobe messed-up progressbar. It's not compatible with 30 % actions. You should do your own progressbar. You can check my own: Magic scripts for Photoshop (Transform with style script.)
Copy link to clipboard
Copied
JJMack I look up for the layer by getByName(); so smart objects are selected
Jarda Bereza I've tried your progress bar and it's working, kind of. It shows up, but it is white panel. I've tried several solutions with Window palette, and they all end up with white panel. That's why I've tried with doProgress() (which I saw in your scripts btw, before that I didn't know that doProgress() even exists)
Copy link to clipboard
Copied
So are you saying that progressbar in my script is white dialog all the time? It may happen if Photoshop is too bussy and don't pay attention about rerendering scriptUI.
In Font Remaping script I had Issue with UI rendering. And increasing dialog width by 1px forcing Photoshop redraw dialogUI. So I toogle dialog width 😄
Next idea is use $.sleep(1) or app.refresh(). I am not sure If this will work.
Copy link to clipboard
Copied
I will try with redrawing dialog.
In your scripts, only Font Remaping is protected, so I couldn't see the code and how you handled redrawing
Copy link to clipboard
Copied
Next Idea is: how often do you update progress dialog? Maybe you update dialog so often that redrawing is never completed because there is new redraw request while redrawing. One update per second or two should be enough for user.
Copy link to clipboard
Copied
I've tried all solutions mentioned on the forum and all act the same, palette is white while progress is working
app.refresh() resolve white panel, but drop the performance. It's not ideal solution, but will work for now.
I will mark as resolved, but if someone find a better solution (without app.refresh()), or how to doProgress() work with executeAction(), write a comment, please