hi guys! thx for the answers. I took the time to debug the code properly. All these scripts to convert to smart object work just fine. My script loops through selected layers and convert each selection to one Smart Object.
The problem was with the activeLayer property ... passing a layer to this property seems not to work in some situations, so the command "Convert to Smart Object" was not being able to execute without a layer selected.
For example, this code, that should select the first layer:
var docRef = app.activeDocument;
docRef.activeLayer = docRef.layers[0];
It works when:
- One or more layers are selected, but not the first layer.
It doesn't work when:
- No layer is selected
- Some layers are selected, including the first
This is specific to trying to select the first layer. If you change '0' for other index, it works fine.
I did a workaround to fix this. Sorry about the confusion and thanks for the support.