简体   繁体   中英

Add Drop Shadow to All Selected Items in InDesign using Javascript

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;

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; } 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM