Copy link to clipboard
Copied
My understanding is indesign dropshadow effect needs to be updated for the option: size within the dropshadow panel to be able to accept 0 - 1000 points for scripts. You can input higher numbers within the size by doing it manually but not with scripts for whatever reason. It will only accepts 0-144 point or 2 inches within the code.
I have a script to automatically apply dropshadows and we have a formula where we take the height of the image and multiply that by 5% which gets placed in the Distance and Size. This works for smaller images but when there are larger images the number it puts into the distance works but the size seems to be limited to 2 inches. But if I do it manually it can go up to 13.8889″
for the size
I get this error: ERROR in applyDropShadow: Error: Invalid value for set property ‘size’. Expected Unit (0 - 144 points), but received “5.0 in”. 13.8889 in = 1000 points
//@target "indesign"
//@targetengine "session"
function isValidObject(obj) {
try {
return obj && obj.isValid;
} catch (e) {
return false;
}
}
function applyDropShadowByHeightInInches(obj) {
if (!isValidObject(obj)) return;
var doc = app.activeDocument;
var originalH = doc.viewPreferences.horizontalMeasurementUnits;
var originalV = doc.viewPreferences.verticalMeasurementUnits;
try {
// Switch the document to inches.
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
// geometricBounds => [y1, x1, y2, x2] in INCHES now.
var bounds = obj.geometricBounds;
var heightInches = Math.abs(bounds[2] - bounds[0]); // bottom - top
// 5% of height in inches
var dropShadowInches = heightInches * 0.05;
// Apply the drop shadow
var ds = obj.transparencySettings.dropShadowSettings;
ds.mode = ShadowMode.DROP;
ds.angle = 120; // Static angle
ds.distance = dropShadowInches; // in inches
ds.size = dropShadowInches; // same as distance
ds.opacity = 35; // example opacity
ds.noise = 2.5; // example noise %
ds.xOffset = 0;
ds.yOffset = 0;
ds.spread = 0;
} catch (e) {
$.writeln("Error applying shadow: " + e);
} finally {
// Restore original measurement units
doc.viewPreferences.horizontalMeasurementUnits = originalH;
doc.viewPreferences.verticalMeasurementUnits = originalV;
}
}
function main() {
if (app.documents.length === 0) {
alert("No open documents.");
return;
}
var doc = app.activeDocument;
if (!isValidObject(doc)) {
alert("Active document not valid.");
return;
}
if (app.selection.length === 0) {
alert("No objects selected.");
return;
}
var count = 0;
for (var i = 0; i < app.selection.length; i++) {
var obj = app.selection[i];
if (isValidObject(obj)) {
applyDropShadowByHeightInInches(obj);
count++;
}
}
alert("Drop shadow applied to " + count + " object(s).");
}
main();
Copy link to clipboard
Copied
Hi @donovang64683985, yes there seems to be an arbitrary limit to the size property of the dropShadowSetting.
From the documentation:
> The radius (in pixels) of the blur applied to the drop shadow. (Range depends on the unit type. For points: 0 to 144; for picas: 0p0 to 12p0; for inches: 0 to 2; for mm: 0 to 50.08; for cm: 0 to 5.08; for ciceros: 0c0 to 11c3.128.)
When I tested it seemed to simply ignore values greater than 144 (pts), using this code:
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument,
item = doc.selection[0];
item.transparencySettings.dropShadowSettings.properties = {
mode: ShadowMode.DROP,
angle: 120,
distance: 1000,
size: 1000, // this is out-of-bounds apparently
opacity: 35,
noise: 0,
xOffset: 0,
yOffset: 0,
spread: 0,
};
That doesn't help much I know, but at least it agrees with your observation.
- Mark
Copy link to clipboard
Copied
Do you know if this is something that would be fixed any time soon? I know you're just a community memeber btw
Copy link to clipboard
Copied
Unfortunately it is extremely unlikely to be fixed anytime soon. There are many more-urgent bugs also waiting many years. I have not even looked to see if there is a bug report for this particular issue.
Perhaps there is a workaround? What happens if you apply the dropshadow to the scaled-down object and then scale it up (using transform method?) ... does it scale up the "effects" and if so, you might be able to achieve the desired drop shadow settings?
Sorry I'm not much help on this one.
- Mark
Copy link to clipboard
Copied
I think I potentially came up with a work around that I'm going to try to implement tomorrow. I came up with exactly what you said. Scaled the image down. Applied the dropshadow and then scaled it up with the transform scale and it works!
// This script scales down an image and its frame by 25% proportionally using the center reference point and adds a drop shadow.
(function () {
if (app.documents.length === 0) {
alert("No documents are open. Please open a document and select an image.");
return;
}
var doc = app.activeDocument;
var selection = app.selection;
if (selection.length === 0 || !(selection[0] instanceof Rectangle) || !selection[0].images.length) {
alert("Please select a rectangle containing an image.");
return;
}
var imageFrame = selection[0];
var image = imageFrame.images[0];
// Get the original dimensions of the frame
var originalWidth = imageFrame.geometricBounds[3] - imageFrame.geometricBounds[1];
var originalHeight = imageFrame.geometricBounds[2] - imageFrame.geometricBounds[0];
// Calculate new dimensions (25% of original size)
var newWidth = originalWidth * 0.25;
var newHeight = originalHeight * 0.25;
// Get the center point of the frame
var centerX = (imageFrame.geometricBounds[1] + imageFrame.geometricBounds[3]) / 2;
var centerY = (imageFrame.geometricBounds[0] + imageFrame.geometricBounds[2]) / 2;
// Set new bounds for the frame, keeping it centered
imageFrame.geometricBounds = [
centerY - newHeight / 2,
centerX - newWidth / 2,
centerY + newHeight / 2,
centerX + newWidth / 2
];
// Fit the image proportionally within the resized frame
imageFrame.fit(FitOptions.FILL_PROPORTIONALLY);
// Add drop shadow using new height
var shadowDistance = newHeight * 0.05; // 5% of the new height
var shadowSize = shadowDistance; // Same as distance
try {
// Ensure the 'Black' swatch exists or create it if missing
var blackSwatch;
try {
blackSwatch = doc.swatches.item("Black");
blackSwatch.name; // Force error if the swatch doesn't exist
} catch (e) {
blackSwatch = doc.colors.add({
name: "Black",
colorValue: [0, 0, 0, 100]
});
}
// Apply the drop shadow using live scaling (transform effects)
imageFrame.transparencySettings.dropShadowSettings.properties = {
mode: ShadowMode.DROP,
distance: shadowDistance,
size: shadowSize,
angle: 120,
opacity: 35,
blendMode: BlendMode.MULTIPLY
};
} catch (e) {
alert("Error applying drop shadow: " + e.message);
}
// Use transformation to scale the frame and content back to the original size
var transformationMatrix = app.transformationMatrices.add({
horizontalScaleFactor: 4,
verticalScaleFactor: 4
});
imageFrame.transform(
CoordinateSpaces.PASTEBOARD_COORDINATES,
AnchorPoint.CENTER_ANCHOR,
transformationMatrix
);
alert("Frame and image scaled down by 25%, drop shadow added, and scaled back to original size using transformation successfully!");
})();
Copy link to clipboard
Copied
Nice! Well done. 🙂