How to Get SmartObject info?

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

Dimatokis
Posts: 11
Joined: Wed Aug 17, 2016 7:50 pm

How to Get SmartObject info?

Post by Dimatokis »

..
For example a list of attached smart filters (with indexes), and values?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: How to Get SmartObject info?

Post by Kukurykus »

Looping through smart layers with filters in smart object and getting laeyrs and filters names should't be problem, but all those values inside filter had to be long way throughtout Action Manager objects and then what even harder great number of properties.

I hope this time excellent coders like xbytor or Paul Riggott finally come and show us the magic!
User avatar
DavideBarranca
Posts: 16
Joined: Tue Jul 26, 2016 2:12 pm

Re: How to Get SmartObject info?

Post by DavideBarranca »

As an example, I've created a flatten file with a single Background layer; converted to Smart Object, and applied Gaussian Blur and Solarize Smart Filters.
The following code:

Code: Select all

var ref = new ActionReference ();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("smartObject"));
ref.putEnumerated (stringIDToTypeID ("layer"), stringIDToTypeID ("ordinal"), stringIDToTypeID ("targetEnum"));
var smartObjectDesc = executeActionGet (ref).getObjectValue (stringIDToTypeID ("smartObject"));
var filtersList = smartObjectDesc.getList(stringIDToTypeID ("filterFX"))

for (var i = 0, _len = filtersList.count; i < _len; i++) {
var smartFilter = filtersList.getObjectValue(i)
var filterName = smartFilter.getString(stringIDToTypeID ("name"));
$.writeln("Filter: " + filterName)
try {
var filterDesc = smartFilter.getObjectValue (stringIDToTypeID("filter"));
// E.g. for Gaussian Blur:
var radius = filterDesc.getUnitDoubleValue(stringIDToTypeID("radius"))
$.writeln("Radius: " + radius)
} catch(e) {}
}
Outputs in the console:

Code: Select all

Filter [0]: Gaussian Blur...
Radius: 5
Filter [1]: Solarize
It might not work under all circumstances but should give you a head start.

Regards,
Davide Barranca
Dimatokis
Posts: 11
Joined: Wed Aug 17, 2016 7:50 pm

Re: How to Get SmartObject info?

Post by Dimatokis »

Great! Thank you!
Say plz, can I find some property for identification smart-effects (like "id")? Becouse "name" is depends on the localization.
Dimatokis
Posts: 11
Joined: Wed Aug 17, 2016 7:50 pm

Re: How to Get SmartObject info?

Post by Dimatokis »

Another question
Now I can get the value of the radius (thanks Davide), and how to get the opacity and blending mode in a Smart-Filter?
Please, help :roll: