0

Trying to figure out how to add drop shadow to all selected items on page within InDesign CC. Here is what I have but it says "Undefined is not an object."

myDS = app.select(SelectAll.ALL);
myDS.dropShadowSettings.mode = ShadowMode.drop;
myDS.dropShadowSettings.angle = .0083;
myDS.dropShadowSettings.xOffset = 0.08;
myDS.dropShadowSettings.yOffset = 0.08;
myDS.dropShadowSettings.size = 0.6;
James
  • 561
  • 2
  • 7
  • 19

2 Answers2

2

Then that would be this (although I would prefer check if item has an applied object style and if so edit the object style itself. Then I would look if item has a style already processed to gain performance. But to be brief:

var allPageItems  = doc.allPageItems;
var n = allPageItems.length;
while ( n-- ) process ( allPageItems[n] );
function process ( item) {
 if ( !item.properties.transparencySettings ) return;
 item.transparencySettings.dropShadowSettings.mode = ShadowMode.NONE;
}
Loic
  • 2,173
  • 10
  • 13
  • As I understand it, I would agree; but this did the trick and works. It did answer the question posted here. Thanks again!! – James Apr 19 '17 at 17:43
1

By using "select all", the returned object is a classical array where dropShadowSettings isn't a valid property hence the error. Instead of setting the props straightforwardly, I would recommend applying an object style. That way, you will be able to edit the style manually and see the previous concerned objects being updated.

var doc = app.activeDocument;
var os = doc.objectStyles.itemByName ( "myDropShadow" );
!os.isValid && os = doc.objectStyles.add ( {
 name:"myDropShadow",
 transparencySettings:{
  dropShadowSettings:{
   mode:ShadowMode.drop,
   angle : .0083,
   xOffset : 0.08,
   yOffset : 0.08,
   size : 0.6,
  }
 }
});
app.activeDocument.pageItems.everyItem().appliedObjectStyle = os;

By the way it's better not to use UI commands such as copy/paste/select as they are time consuming and there is always an alternative within the dom itself.

Loic
  • 2,173
  • 10
  • 13
  • Thanks. This does work, but it strips all the other effects and styles of all the objects. Like text and box fills. My original goal is to remove all drop shadows from document when this script is triggered. I thought I could do that by seeing if I can edit the drop shadow using a script. The goal of this script is changing the document from one print purpose to another. Ex.: Like a full-colored document to a one-color smaller document. So all I am after is removing the drop shadows from all objects without affecting their other effects and styles. Thanks again! – James Apr 19 '17 at 14:28