Copy link to clipboard
Copied
It looks like the object from the library is being opened asynchronously and we can't keep track of it in the normal way.
Alternatively, we can abort the script, wait for the library element to open, and then continue (i'm using alert for notification since $.writeln doesn't work fine when fired from an event):
var s2t = stringIDToTypeID,
evt;
// check run mode: normal or from event
try { evt = arguments[1]; } catch (e) { }
if (!evt) {
// if no event
(r = new ActionReference()).p...
Copy link to clipboard
Copied
You must wait for @r-bin @Kukurykus @jazz-y @c.pfaffenbichler @Stephen Marsh
Copy link to clipboard
Copied
Hi @Gili5E4B! For some tasks, it's better to use the Action Manager code (not DOM).
However, without code, the essence of your problem is not fully understood.
Copy link to clipboard
Copied
Could you provide a Script to demonstrate?
Copy link to clipboard
Copied
You can cheat a bit using a try-catch-finally block, or by using $.sleep(500); after editing the document.
try{
//editing the smart object
} catch(e){
$.writeln("error: "+e);
} finally{
//continue your code
}The try-catch forces the code inside the try part to be finished completely before starting on the finally part.
Alternatively... $.sleep(milliseconds) suspends the calling thread for the given number of milliseconds allowing Photoshop time to update the app.activeDocument object.
Hope it helps 😉
Copy link to clipboard
Copied
A script example:
if (curLayer.kind == 'LayerKind.SMARTOBJECT') {
app.activeDocument.activeLayer = curLayer;
app.displayDialogs = DialogModes.NO;
$.writeln("Identified a smart object at " + app.activeDocument.activeLayer.name);
try {
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
} catch(e) {
$.writeln("error: "+e);
} finally {
$.writeln("Stepped into smartobject " + curLayer.name);
$.writeln("app.documents 1: " + app.documents.length);
$.sleep(2000);
$.writeln("app.documents 2: " + app.documents.length);
}
Logging Result:
Copy link to clipboard
Copied
The problem appers to be connected to the smart object being a linked library object.
When I try the same on regular linked smart object the issue is not happening. Is there anyway to use callback or event that the file is opened/loaded?
Copy link to clipboard
Copied
I see you posted since and with a Library object it is different here, too.
But it seems that the opening occurs after the lines have been written (see gif).
Copy link to clipboard
Copied
I added the creation of a new document after
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
and even that was created before the SO opened.
I seems like the Script is progressing just fine before the library actually »sends« the image to Photoshop.
Copy link to clipboard
Copied
I cannot reproduce the issue with a plain SO.
Copy link to clipboard
Copied
It looks like the object from the library is being opened asynchronously and we can't keep track of it in the normal way.
Alternatively, we can abort the script, wait for the library element to open, and then continue (i'm using alert for notification since $.writeln doesn't work fine when fired from an event):
var s2t = stringIDToTypeID,
evt;
// check run mode: normal or from event
try { evt = arguments[1]; } catch (e) { }
if (!evt) {
// if no event
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('smartObject'));
r.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
// check SO Type
if (executeActionGet(r).getObjectValue(p).hasKey(s2t('link')) && executeActionGet(r).getObjectValue(p).getType(s2t('link')) == DescValueType.OBJECTTYPE) {
// if library item, then add eventListener and send open command
app.notifiersEnabled = true
clearListener()
app.notifiers.add('Opn ', File($.fileName));
executeAction(s2t('placedLayerEditContents'), undefined, DialogModes.NO);
} else {
// if not library item, then open it
executeAction(s2t('placedLayerEditContents'), undefined, DialogModes.NO);
processSO()
}
} else {
// if from event
clearListener()
processSO()
}
function clearListener() {
var f = File($.fileName),
del;
for (var i = 0; i < app.notifiers.length; i++) {
var ntf = app.notifiers[i]
if (ntf.eventFile.name == f.name) { ntf.remove(); i--; del = true }
}
}
// process opened smart
function processSO() {
alert(documents.length)
}
Copy link to clipboard
Copied
The direction is great using notifiers, but the script isn't working.
executeActionGet(r).getObjectValue(p)
Is returning "General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- <no additional information available>" Is there another way to assert if a smartobject is from a cloud library?
Copy link to clipboard
Copied
Did you select the smart object layer before running the script?
If so, send output of this script:
#target photoshop
s2t = stringIDToTypeID;
(r = new ActionReference());
r.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor()).putObject(s2t('object'), s2t('object'), executeActionGet(r));
$.writeln(executeAction(s2t('convertJSONdescriptor'), d).getString(s2t('json')));
Copy link to clipboard
Copied
Sorry I didn't select the SmartObject. After selecting it works.
I will try to incorporate into my own script. Thanks for the help!
Copy link to clipboard
Copied
to jazz-y
После placedLayerEditContents подождать в бесконечном цикле (с учётом таймаута конечно) пока documents.length не изменится.
Не ? : )
Copy link to clipboard
Copied
Это было первое, что я попробовал 🙂 Не прокатило. Такое ощущение, что движок фотошопа после запроса на открытие неспеша грузит файл из библиотеки в фоне, затем ждет когда закончится весь скрипт и только после этого открывает его. Уведомление об 'Opn ' после завершения скрипта срабатывает всегда, даже если раздуть скрипт левыми функциями или затормозить его циклом, а в библиотеку запихать файл 1х1 px
¯\_(ツ)_/¯
Copy link to clipboard
Copied
Ясно. Такая же фигня как с генератором, когда пытаешься сделать новомодный экспорт слоя\файла. Фактический экспорт выполнится только по завершению всего скрипта инициировавшего команду.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more