Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ce script premet d'activer les ombres dans le style d'objet du bloc sélectionné. Deactivate/Reactivate drop shadow in the style applied to the object selected.
/* Ce script premet d'activer les ombres dans le style d'objet du bloc sélectionné.
Deactivate/Reactivate drop shadow in the style applied to the object selected.
par Ben Cloutier
Pour révision des versions, voir au bas de ce document
*/
nomDuScript = "Ombres active-desactive"
dateRev = "1.0 (rev.1.05.2015)"
myId = "ben@bencloutier.com";
myDocument = app.documents.item(0);
myDocumentName = myDocument.name.toString();
myObjectStyles = myDocument.objectStyles.everyItem().name;
myShadowStyles = [];
myShadowCheck = 0;
function checkSelection(){
if(myDocument.selection.length == 1){
mySelection = myDocument.selection[0];
if(mySelection.label.match(/ombre:.+/g)){
myObjectStyle = mySelection.label.replace(/ombre: (.+)/,"$1");
myShadowStyles.push(myObjectStyle);
mySelection.label = "";
}else{
myObjectStyle = mySelection.appliedObjectStyle.name;
myCurrentStyle = myDocument.objectStyles.itemByName(myObjectStyle);
if(myCurrentStyle.transparencySettings.dropShadowSettings.mode == 2020623440){
if(mySelection.label == ""){
myShadowStyles.push(myObjectStyle);
mySelection.label = "ombre: " + myObjectStyle;
}else{
myMessage = "Le script a besoin d'utiliser les «Script Labels».\nL'élément sélectionné a l'information suivante:\n\n • " + mySelection.label + "\n\nPour utiliser ce script, le «Script Label» doit être vide.";
goOut(myMessage);
}
}else{
try{
if(mySelection.graphics[0].label.match(/ombre:.+/)){
myObjectStyle = mySelection.graphics[0].label.replace(/ombre: (.+)/,"$1");
myShadowStyles.push(myObjectStyle);
mySelection.graphics[0].label = "";
}else{
myObjectStyle = mySelection.graphics[0].appliedObjectStyle.name;
myCurrentStyle = myDocument.objectStyles.itemByName(myObjectStyle);
if(myCurrentStyle.transparencySettings.dropShadowSettings.mode == 2020623440){
if(mySelection.graphics[0].label == ""){
myShadowStyles.push(myObjectStyle);
mySelection.graphics[0].label = "ombre: " + myObjectStyle;
}else{
myMessage = "Le script a besoin d'utiliser les «Script Labels».\nL'élément sélectionné a l'information suivante:\n\n • " + mySelection.label + "\n\nPour utiliser ce script, le «Script Label» doit être vide.";
goOut(myMessage);
}
}
}
}catch(e){}
}
}
}
if(myShadowStyles.length < 1){
myMessage = "Aucune ombre trouvée dans le style d'objet!\nPour désactiver l'ombre d'un style, sélectionnez un bloc qui a l'ombre en question.";
goOut(myMessage);
}
}
function toggleShadows(){
for(var i=0; i<myShadowStyles.length; i++){
myCurrentStyle = myDocument.objectStyles.itemByName(myShadowStyles[i]);
// alert(myShadowStyles[i] + "\n" + myCurrentStyle.transparencySettings.dropShadowSettings.mode);
if(myCurrentStyle.transparencySettings.dropShadowSettings.mode == 2020623440){
myCurrentStyle.transparencySettings.dropShadowSettings.mode = 1852796517;
}else{
myCurrentStyle.transparencySettings.dropShadowSettings.mode = 2020623440;
}
}
}
function checkConsistence(){
if(myShadowStyles.length > 1){
for(var i=0; i<myShadowStyles.length; i++){
myCurrentStyle = myDocument.objectStyles.itemByName(myShadowStyles[i]);
if(i == 0){
myShadowStatus = myCurrentStyle.transparencySettings.dropShadowSettings.mode;
}else{
if(myCurrentStyle.transparencySettings.dropShadowSettings.mode != myShadowStatus){
myConfirm = confirm("Les styles avec ombre ne sont pas tous activé!\nVoulez-vous tous les activer?");
if(myConfirm){
for(var j=0; j<myShadowStyles.length; j++){
myCurrentStyle = myDocument.objectStyles.itemByName(myShadowStyles[j]);
myCurrentStyle.transparencySettings.dropShadowSettings.mode = 2020623440;
//myShadowStatus = myCurrentStyle.transparencySettings.dropShadowSettings.mode;
}
goOut();
}
}
}
}
}
}
function main(){
checkSelection();
checkConsistence();
toggleShadows();
goOut();
}
function goOut(myMessage){
if(myMessage != undefined){
alert(myMessage + "\n\n" + dateRev + "\n" + myId);
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
app.scriptPreferences.enableRedraw = 1;
exit();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment