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

How to complete Image/Trap with javascript

Engaged ,
Jul 29, 2021 Jul 29, 2021

I work with CMYK images and I want to create script which will flatten layers and complete trapping 0,2mm. I tried with Script Listener and i got this code but result is slightly different when i do it manuly.

 

    var idFltI = charIDToTypeID( "FltI" );
    executeAction( idFltI, undefined, DialogModes.NO );
    // =======================================================
    var idTrap = charIDToTypeID( "Trap" );
    var desc6698 = new ActionDescriptor();
    var idWdth = charIDToTypeID( "Wdth" );
    var idRlt = charIDToTypeID( "#Rlt" );
    desc6698.putUnitDouble( idWdth, idRlt, 0.566895 );
    executeAction( idTrap, desc6698, DialogModes.NO );

 

 

TOPICS
Actions and scripting , macOS
2.1K
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

Community Expert , Jul 30, 2021 Jul 30, 2021

I would work in px and trap to the desired unit in px values.

 

// Save the current ruler units and set to pixels
var savedRuler = app.preferences.rulerUnits;        
app.preferences.rulerUnits = Units.PIXELS;

// Do your stuff...

// Restore the ruler units
app.preferences.rulerUnits = savedRuler;
Translate
Adobe
Community Expert ,
Jul 30, 2021 Jul 30, 2021

I would work in px and trap to the desired unit in px values.

 

// Save the current ruler units and set to pixels
var savedRuler = app.preferences.rulerUnits;        
app.preferences.rulerUnits = Units.PIXELS;

// Do your stuff...

// Restore the ruler units
app.preferences.rulerUnits = savedRuler;
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 30, 2021 Jul 30, 2021

So 

    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );

instead of 

    var idRlt = charIDToTypeID( "#Rlt" );

 

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
LEGEND ,
Jul 30, 2021 Jul 30, 2021

What is 'trapping' in Photoshop and how to do it manually?

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 30, 2021 Jul 30, 2021

»Trapping« is »choking« and »spreading« color areas (the lighter one into the darker one usually) against each other to mitigate the effect of misalignment in printing. 

 

It is available for CMYK images under 

Image > Trap 

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
LEGEND ,
Jul 30, 2021 Jul 30, 2021

That's right, the printers work in CMYK mode for better effect probably.

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 30, 2021 Jul 30, 2021

Image>Trap...

 

It only works in CMYK mode. If adjacent colors do not share ink components they need to be trapped in case the press is not in perfect register. 

 

Screen Shot.pngexpand imageScreen Shot 4.pngexpand image

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
LEGEND ,
Jul 30, 2021 Jul 30, 2021

So it's usefull to avoid side effect when there're no harmonious ink components in the printer.

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 30, 2021 Jul 30, 2021

The API also has a trap command, the parameter is the trap in pixels:

 

if (app.activeDocument.mode == DocumentMode.CMYK) {
	app.activeDocument.trap(4); 
}; 
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
LEGEND ,
Jul 30, 2021 Jul 30, 2021

I found it now in Image menu, but I never used it as I never work in CMYK. After changing the mode to this colour the Trap item was enabled. I tried it on an image with transparency and noticed some border effect going to inside of object in the layer. I still do not understand what is meant for and why it is only for CMYK. Can anyone explain to me what it should be used for?

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 30, 2021 Jul 30, 2021

See »Create a color trap« here: 

Print images to a commercial printing press

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 30, 2021 Jul 30, 2021

Trapping is normally handled at output by the RIP software, but if you are printing separations directly from Photoshop for something like screen printing you might need to apply traps to the image—trapping is also available for Spot channels.

 

InDesign and Acrobat have built in trap settings which can be applied when the Print>Output color is set to Separations.

 

Screen Shot 8.pngexpand image

 

If the press goes off register you could get this:

 

Screen Shot 7.pngexpand image

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
LEGEND ,
Jul 30, 2021 Jul 30, 2021

I created exaclty same image with same CMYK colours as yours and used 4px value for trap for cyan circle. Irrespectively a circle was under/over magenta layer the overlayed parts are blended. Will be the printed image same as now on your screenshot? If I did not use for this example trap before printing while 'adjacent colors do not share ink components' what would be printed? If possible I'd like to see it on another screenthos 😉

 

btw. how to use it for spot channels?

 

Edit: so the above image from previous post shows the side effect, and what's the right then?

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 30, 2021 Jul 30, 2021

btw. how to use it for spot channels?

 

Select the Spot Channels you want to trap:

 

Screen Shot 9.pngexpand image

 

 

You don’t need trapping for composite printing (i.e. inkjet), or for most continuous tone images. It’s only needed for a process like offset printing where the CMYK or spot channels are printing on separate plates, and the colors are CMYK builds—something like a line of red text (0|100|100|0) on a black field (0|0|0|100) would need a trap.

 

It would be unusual for the plates to stay in perfect register through out the press run. Here’s the red on a black only field with a 5 pixel trap on the right and no trap on the left. If the Black plate goes 2 pixels off register you would get this:

 

Screen Shot 10.pngexpand image

 

Also in my other examples I’m exagerrating the trap, typical offset printing would only need a 1 or 2 pixel trap when the res is 300ppi

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 30, 2021 Jul 30, 2021

Hi @milevic , the actual output size of the trap would change depending on resolution—using pixel units, a 600ppi image would need a larger trap amount than a 300ppi image.

 

So an alternate to setting your rulers to pixels might be this, where I’m getting the size of a document pixel in millimeters and converting the tmm variable into pixels for the .trap parameter, which needs to be a whole pixel amount:

 

//the desired trap amount in millimeters
var tmm = .2;

//a single pixel dimension as millimeters
var mm = (1/app.activeDocument.resolution)/.039370;

if (app.activeDocument.mode == DocumentMode.CMYK) {
    //the millimeter amount converted to pixels (needs to be the nearest whole number)
	app.activeDocument.trap(Math.round(tmm/mm)); 
}; 

 

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
Engaged ,
Aug 07, 2021 Aug 07, 2021

Hi @rob day  Thank you for your dedication, I like your solution but result of your script looks like 2mm trap, not 0.2mm.

Could you improve this? Also, is it possible to use (or to adapt) yours code for MULTICHANNEL mode?

Screenshot 2021-08-07 at 12.52.21.pngexpand image

 

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 ,
Aug 07, 2021 Aug 07, 2021

I noticed that the Trap Units setting is sticky, so my script won’t work if you run it after a trap has been created with the UI using Millimeters as the unit, but will if the last applied trap’s unit setting was Pixels.

 

There doesn’t seem to be a way to specifically set trap units before running the trap method with the API, and setting the ruler units doesn’t seem to matter. Here’s the method description—it should work so it seems like a bug:

 

Photoshop ExtendScript API Adobe Photoshop CC 2015.5 Object Library - Document

 

With the trap units set to the default pixels, I get this running the script:

 

Screen Shot 21.pngexpand image

 

But running after a manual trap using Millimeter trap units I get this:

 

Screen Shot 22.pngexpand image

 

 

Here’s the script as a function, and would work with Multichannel:

 

//run trap function with parameter as the amount in millimeters
trapMM(.2)


/**
* Sets a trap in millimeters    
*  trap amount as milimeters 
*  void 
* 
*/
function trapMM(t){
    try {
        var mm = (1/app.activeDocument.resolution)/.039370;
        app.activeDocument.trap(Math.round(t/mm)); 
    }catch(e) {
        alert("The document mode must be 8-bit CMYK or MultiChannel")
    }  
}

 

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

That's right. I tried it with Action Manager and it doesn't help to avoid this bug.

Similarly you can't change by script Pixels / Inch or Centimeter resolution kind.

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 ,
Aug 07, 2021 Aug 07, 2021

I tried recording a Millimeter trap and there is a mysterious "distanceUnit". Not sure what it means, but if I divide the desired MM trap by .35 it seems to work with any resolution:

 

 

trapMM(.2)

/**
* trap as Millimeters 
* @Param trap amount in Millimeters 
* @Return void 
* 
*/
function trapMM(ta){
    var mn = .35 
    try {
        var t = stringIDToTypeID( "trap" );
        var d = new ActionDescriptor();
        var w = stringIDToTypeID( "width" );
        var u = stringIDToTypeID( "distanceUnit" );
        d.putUnitDouble( w, u, ta/mn);
        executeAction( t, d, DialogModes.NO );
    }catch(e) {
        alert("The document mode must be 8-bit CMYK or MultiChannel")
    }        
}

 

 

 

 

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 ,
Aug 07, 2021 Aug 07, 2021

This is 600ppi:

 

Screen Shot 25.pngexpand image

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
LEGEND ,
Jan 06, 2022 Jan 06, 2022
LATEST

After 5 months I received a message from Adobe developers. They're not going to fix this bug.

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

I don't remember now the formula for distance unit, but I tried with Action Manager it as well and there is same bug for a trap if the user previously use other kind of  unit.

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 ,
Aug 07, 2021 Aug 07, 2021

Did you try my posted version where I’m dividing the desire trap dimension by .35? It seems to be working.

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
Engaged ,
Aug 07, 2021 Aug 07, 2021

I am on vacation without or wuth limit internet access. I will try and respond asap. Thank you once again.

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

That doesn't change the fact when like you noticed user set the unit manually and then use the code, the code still applies manually chosen unit than that specified in the script.

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