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

how to assess blend if-settings with javascript

Community Expert ,
Jul 03, 2009 Jul 03, 2009

Some time ago someone in the MacIntosh-forum declared their wish to use a layer’s Layer Style Blend If-setting’s result as a mask (for whatever reasons).

The »This Layer’s« effect is easily enough converted to a mask by grouping and flattening the layer and using the resulting transparency.

But the »Underlying Layer«-setting seems more difficult (naturally as they depend on other layers’ content).

Is there a way to get the current (for an RGB-file 32) numbers of a layer’s Blend If-settings with JavaScript?

Or is there a way to reset the This Layer-Blend If-settings, but leave the Underlying Layer-settings unchanged?

Any help appreciated.

TOPICS
Actions and scripting
3.0K
Translate
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

Advisor , Jul 03, 2009 Jul 03, 2009
It seems that I was wrong. The blending options are not part of the layerEffects descriptor. At least not in CS4. There was a time when you had to use a script by Xbytor named Styles.js to get the layerEffects descriptor. I tried that as well and it also doesn't return any blend settings.

The Blending Options are stored as part of the Style when you save the Style as a preset and/or save it to disk as a .asl file. Take a peek with a hex editor.

That information was not being read in (via Styles.js

...
Translate
Adobe
Guru ,
Jul 03, 2009 Jul 03, 2009

The blend if settings are part of the layer's effects descriptor. You can get the current setting from a layer and/or change those settings using the Action Manager API.

I don't fully understand what you are trying to do. Although you can get the Underlying Layer numbers they still depend on the other layer and I think would be hard to set with a script.

If you need help with the scriptlistner code to get and set those values let me know.

Translate
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 ,
Jul 03, 2009 Jul 03, 2009

Oh, I absolutely need help with those … thanks for Your indulgence!

What I’m after (and mainly for the challenge, not because I have an actual need for it at the moment) is getting the the same effect as the applied Blend If-settings through masks on a non-blend-if-layer (and I’m aware that they are then no longer »live« so to speak).

Anyway, I was operating under the assumption that one could produce an identical result when resetting the formerly top-layer and putting it below the other one and applying the inversed Underlying-settings as This Layer-settings to the newly top-layer.

blendif.jpg

Unfortunately that seems to apply only for the Gray-settings, but when the other channels are modified it doesn’t hold true.

So, even if it might not be any help here, I would like to know how I can get the values in a layer’s current settings.

Because when recording an edit with Scripting Listener I get something like:

var idsetd = charIDToTypeID( "setd" );

    var desc58 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref51 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref51.putEnumerated( idLyr, idOrdn, idTrgt );

    desc58.putReference( idnull, ref51 );

    var idT = charIDToTypeID( "T   " );

        var desc59 = new ActionDescriptor();

        var idBlnd = charIDToTypeID( "Blnd" );

            var list20 = new ActionList();

                var desc60 = new ActionDescriptor();

                var idChnl = charIDToTypeID( "Chnl" );

                    var ref52 = new ActionReference();

                    var idChnl = charIDToTypeID( "Chnl" );

                    var idChnl = charIDToTypeID( "Chnl" );

                    var idGry = charIDToTypeID( "Gry " );

                    ref52.putEnumerated( idChnl, idChnl, idGry );

                desc60.putReference( idChnl, ref52 );

                var idSrcB = charIDToTypeID( "SrcB" );

                desc60.putInteger( idSrcB, 0 );

                var idSrcl = charIDToTypeID( "Srcl" );

                desc60.putInteger( idSrcl, 0 );

                var idSrcW = charIDToTypeID( "SrcW" );

                desc60.putInteger( idSrcW, 255 );

                var idSrcm = charIDToTypeID( "Srcm" );

                desc60.putInteger( idSrcm, 255 );

etc.

with the values for all the handles.

But how can I access those numbers from within a Script, for example to apply only certain ones of them to another layer?

Translate
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
Guru ,
Jul 03, 2009 Jul 03, 2009

It seems that I was wrong. The blending options are not part of the layerEffects descriptor. At least not in CS4. There was a time when you had to use a script by Xbytor named Styles.js to get the layerEffects descriptor. I tried that as well and it also doesn't return any blend settings.

Translate
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 ,
Jul 03, 2009 Jul 03, 2009

Thanks!

As I work with CS4 I suppose I’ll have to do without that then, but I’ll have a look at xbytor’s Script anyway.

Have a nice weekend

Pfaffenbichler

Translate
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
Advisor ,
Jul 03, 2009 Jul 03, 2009
It seems that I was wrong. The blending options are not part of the layerEffects descriptor. At least not in CS4. There was a time when you had to use a script by Xbytor named Styles.js to get the layerEffects descriptor. I tried that as well and it also doesn't return any blend settings.

The Blending Options are stored as part of the Style when you save the Style as a preset and/or save it to disk as a .asl file. Take a peek with a hex editor.

That information was not being read in (via Styles.js) as a part of the Style Descriptor. I've updated Styles.js so that you can now get the Blend Options descriptor:


http://ps-scripts.com/bb/viewtopic.php?t=2759

-X

Translate
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
Guru ,
Jul 03, 2009 Jul 03, 2009

Thanks to Xbytor's update of the script here is the code you need to get the blend if values from a layer. Note you will also need Styles-1_14.jsx for this to work.

#include "/C/Program Files/Adobe/xtools/xlib/Styles-1_14.jsx"
var blendIf = {};
var doc = activeDocument;
var layer = doc.activeLayer;
var desc = Styles.getLayerStyleDescriptor(doc, layer, true).getObjectValue(stringIDToTypeID('blendOptions')).getList(stringIDToTypeID('blendRange')).getObjectValue(0);

blendIf.channel = typeIDToStringID(desc.getReference( stringIDToTypeID('channel')).getEnumeratedValue());
blendIf.srcBlackMin = desc.getInteger(stringIDToTypeID('srcBlackMin'));// 'This Layer' in dialog
blendIf.srcBlackMax  = desc.getInteger(stringIDToTypeID('srcBlackMax'));
blendIf.srcWhiteMin  = desc.getInteger(stringIDToTypeID('srcWhiteMin'));
blendIf.srcWhiteMax  = desc.getInteger(stringIDToTypeID('srcWhiteMax'));
blendIf.destBlackMin  = desc.getInteger(stringIDToTypeID('destBlackMin'));// 'Underlaying Layer' in dialog
blendIf.destBlackMax  = desc.getInteger(stringIDToTypeID('destBlackMax'));
blendIf.destWhiteMin  = desc.getInteger(stringIDToTypeID('destWhiteMin'));
blendIf.destWhiteMax = desc.getInteger(stringIDToTypeID('desaturate'));

Translate
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 ,
Jul 04, 2009 Jul 04, 2009

Wow, thanks a lot!

If it weren’t for You guys (and of course a couple more of the regulars on these Scripting-fora) I guess I would get about nothing done Scripting-wise …

Translate
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 ,
Jul 04, 2009 Jul 04, 2009

If I may be so immodest I’d like to follow up with another question:

How can I address the Red-, Green- and Blue-channels of the Blend If-settings?

Translate
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
Guru ,
Jul 04, 2009 Jul 04, 2009

Let me explain the code and the structure of the descriptor as it is not straightforward. Note in my first post I had getting the channel's ranges in one line. This time will we use several lines to make the code more readable and robust.

var desc = Styles.getLayerStyleDescriptor(doc, layer, true)  returns the main descriptor you need. From that you want the blendOptions descriptor. You will want to add a test here to make sure that the layer has blendOptions set or you will get an error when you try to get the options. So add an if statement that test for desc.hasKey(stringIDToTypeID('blendOptions')). If it's true you can then get the options.

var blendOptionsDesc = desc.getObjectValue(stringIDToTypeID('blendOptions'))  from the options you need the list of blendRanges

var blendChannelList = blendOptionsDesc.getList(stringIDToTypeID('blendRange'))  now it gets tricky. The list will have between one and four items. each item is a descriptor for a given channel. blendChannelList.count will let you know how many channels you will need to deal with. There may be only one channel and it could be any of the channels. if the layer only has green blendOptions the first and only item in the list will be the descriptor for the green channel options. The key is you can not count on the channels being in a set order.

var channelBlendRanges = blendChannelList.getObjectValue(0)  will get the first descriptor. you can now check the channel with typeIDToStringID(channelBlendRanges.getReference( stringIDToTypeID('channel')).getEnumeratedValue()) change the 0 to get the other list tiems

From this point you know how many channels you need to deal with, how to determine the channel in the list, and how to get the blend values from my other post. That could be a lot of data if all 4 channels have settings. I will let you handle how best to store the data.

Translate
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 ,
Jul 05, 2009 Jul 05, 2009
LATEST

Thank You for Your taking the time to explain the matter at such length!

Translate
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