• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Convert to Smart Object script command not working anymore

Participant ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

hi guys,
With this last update (23.0.0), I realize that my script that convert layers to smart objects is throwing an error now. The error is attached below.
I try to route again the 'convert to smart object' command, with ScriptListener plugin, but the code output is still the same.
Any insights about this error?

TOPICS
Actions and scripting , Windows

Views

790

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 18, 2021 Nov 18, 2021

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:

va
...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

What is the layer content?

 

I obviously don't know what code you are currently using as you didn't post it, but try this (presuming at least one selected layers):

 

executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);

 

or

 

newPlacedLayer();
function newPlacedLayer() {
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        executeAction(s2t("newPlacedLayer"), undefined, DialogModes.NO);
}

 

or

runMenuItem(stringIDToTypeID('newPlacedLayer'));

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

hi Stephen! thanks for the reply.

my bad, I thought of posting my code, but I forgot.
It's the same as your first solution:

var idnewPlacedLayer = stringIDToTypeID( "newPlacedLayer" );
executeAction( idnewPlacedLayer, undefined, DialogModes.NO );

It's been working for years, but it's throwing this error now. I'll try your other methods / functions and come back here tomorrow.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

Using runMenuItem method did the job. For some reason, 'newPlacedLayer' is not available anymore, as a command.
Thanks again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

Strange, I have seen the opposite with other operations in older versions, the run menu item didn't work but the AM code did.

 

Just curious, I converted the recorded command into an action and converted it into a script via xtools, does this work?

 

#target photoshop
//
// Action29.jsx
//
//
// Generated Thu Nov 18 2021 07:25:21 GMT+1100
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== Action 29 ==============
//
function Action29() {
  // Convert to Smart Object
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('newPlacedLayer'), undefined, dialogMode);
  };
  step1();      // Convert to Smart Object
};
//=========================================
//                    Action29.main
//=========================================
//
Action29.main = function () {
  Action29();
};
Action29.main();
// EOF
"Action29.jsx"
// EOF

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

var idnewPlacedLayer = stringIDToTypeID( "newPlacedLayer" );
executeAction( idnewPlacedLayer, undefined, DialogModes.NO );

This code seems to run fine for me on a single layer as well as multiple layers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

quote

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.


By @Tilles

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/targeting-a-layer-when-none-is-select...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

LATEST

Hi r-bin, thx for your reply.
I was looking for something like this, a layer ID or something, but the official guide doesn't say anything about it.
In fact, scripting for Photoshop is so cumbersome ...
Anyway, your code really worked, thanks. I'm surprised that you have to do some workaround to select a layer that should be selected with the actual code. And it's been 3 years ... I guess no one cares for PS scripting evolution

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines