This works with the sample image. if(app.documents.length>0){ var white = new SolidColor(); white.rgb.hexValue = 'FFFFFF'; var doc = app.activeDocument; var defaultRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var docWidth = doc.width.value; var docHeight = doc.height.value; doc.activeLayer = doc.layers[0]; loadLayerTransparencyToSelection(); doc.selection.select([[0,docHeight/2],[docWidth,docHeight/2],[docWidth,docHeight],[0,docHeight]],SelectionType.INTERSECT); var necklaceWidth = doc.selection.bounds[2]-doc.selection.bounds[0]; doc.selection.deselect(); doc.activeLayer.translate(Math.abs(docWidth-necklaceWidth),0); doc.revealAll(); selectLayerBelow(); doc.selection.selectAll(); doc.selection.fill(white); doc.selection.deselect(); app.preferences.rulerUnits = defaultRulerUnits; } function loadLayerTransparencyToSelection() { var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') ); desc.putReference( charIDToTypeID('null'), ref ); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') ); desc.putReference( charIDToTypeID('T '), ref ); executeAction( charIDToTypeID('setd'), desc, DialogModes.NO ); }; function selectLayerBelow(){ var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) ); desc.putReference( charIDToTypeID( "null" ), ref ); desc.putBoolean( charIDToTypeID( "MkVs" ), false ); executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO ); }
... View more