Copy link to clipboard
Copied
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 );
1 Correct answer
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;
Explore related tutorials & articles
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
So
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
instead of
var idRlt = charIDToTypeID( "#Rlt" );
Copy link to clipboard
Copied
What is 'trapping' in Photoshop and how to do it manually?
Copy link to clipboard
Copied
»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
Copy link to clipboard
Copied
That's right, the printers work in CMYK mode for better effect probably.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
So it's usefull to avoid side effect when there're no harmonious ink components in the printer.
Copy link to clipboard
Copied
The API also has a trap command, the parameter is the trap in pixels:
if (app.activeDocument.mode == DocumentMode.CMYK) {
app.activeDocument.trap(4);
};
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
See »Create a color trap« here:
Copy link to clipboard
Copied
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.
If the press goes off register you could get this:
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
btw. how to use it for spot channels?
Select the Spot Channels you want to trap:
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:
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
Copy link to clipboard
Copied
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));
};
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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:
But running after a manual trap using Millimeter trap units I get this:
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")
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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")
}
}
Copy link to clipboard
Copied
This is 600ppi:
Copy link to clipboard
Copied
After 5 months I received a message from Adobe developers. They're not going to fix this bug.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Did you try my posted version where I’m dividing the desire trap dimension by .35? It seems to be working.
Copy link to clipboard
Copied
I am on vacation without or wuth limit internet access. I will try and respond asap. Thank you once again.
Copy link to clipboard
Copied
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.


-
- 1
- 2