Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Élargi le bloc pour inclure l'ombre portée | Bloc fitting include drop shadow
/* Ce script élargi le bloc pour inclure l'ombre portée
***Ne fonctionne pas si le bloc a une rotation***
par Benoit Cloutier
ben@bencloutier.com
*/
nomDuScript = "Bloc fit ombre";
dateRev = "rev.01.06.2016";
myId = "ben@bencloutier.com";
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
app.scriptPreferences.enableRedraw = 1;
myOldXUnits = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
myOldYUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits;
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
try{
myDocument = app.documents.item(0);
myElements = app.activeDocument.selection;//Sélection faites
if(myElements.length > 0){
//Progress Bar
myProgressBarStep = 1
myProgressBarMax = myElements.length;
myProgressPanel = progressBarCreate(100, 400);
myProgressPanel.show();
for(s=0;s<myElements.length;s++){
myElement = myElements[s];
myProgressMessage = "Ajustement en cours ";
progressBarUpdate(myProgressMessage);
myRotation = 0;
try{
myContent = myElements[s].graphics[0];
if(myContent.rotationAngle != 0){
app.layoutWindows[0].transformReferencePoint = AnchorPoint.CENTER_ANCHOR;
myRotation = myContent.rotationAngle;
myContent.rotationAngle = 0;
}
}catch(gg){
myContent = myElements[s];
if(!myElement.constructor.name.match(/text/i)){
myElement = myElements[s].parent;
}
}
myElement.fit(FitOptions.FRAME_TO_CONTENT);
getShadowSize();
var Bound = myContent.geometricBounds;
var myWidthModif = 0;
var myHeightModif = 0;
if(myRotation != 0){
myWidthModif = (Bound[3] - Bound[1])/5;
myHeightModif = (Bound[2] - Bound[0])/5;
}
if((myLeft + myRight + myBottom + myTop) != 0 || myRotation != 0){
myElement.geometricBounds = [((Bound[0] - myHeightModif) + (myTop - mySize) + "in"), ((Bound[1] - myWidthModif) + (myLeft - mySize) + "in"), ((Bound[2] + myHeightModif) + (myBottom + mySize) + "in"), (Bound[3] + ((myRight + myWidthModif) + mySize) + "in")];
var myWidth = myElement.geometricBounds[3] - myElement.geometricBounds[1];
var myHeight = myElement.geometricBounds[2] - myElement.geometricBounds[0];
try{myContent.rotationAngle = myRotation;}catch(rr){}
}
}
}
}catch(e){
myAlert(e);
goOut();
}
/* PROGRESS BAR*/
function progressBarCreate(myMaxProgressValue, myProgressBarWidth){
myProgressPanel = new Window("window", nomDuScript);
with (myProgressPanel){
myProgressPanel.myProgressBar = add("progressbar", [12, 12, myProgressBarWidth, 24], 0, myMaxProgressValue);
myProgressPanelTxt = myProgressPanel.add("statictext", undefined, nomDuScript + " " + dateRev);
}
return myProgressPanel;
}
function progressBarUpdate(myProgressMessage){
myProgressBarStep++;
myProgressPanel.myProgressBar.value = (100/myProgressBarMax)*myProgressBarStep;
if(myProgressMessage == ""){
myProgressPanelTxt.text = String("...");
}else{
myProgressPanelTxt.text = String(myProgressMessage);
}
try{myProgressPanel.update();}catch(upd){}
}
function getShadowSize(){
myShadowSize = 0;
myBlocShadowSize = 0;
myContentShadowSize = 0;
myTop = 0;
myRight = 0;
myBottom = 0;
myLeft = 0;
mySize = 0;
try{
if(myContent.transparencySettings.dropShadowSettings.mode == 2020623440/* || myContent.transparencySettings.dropShadowSettings.mode == 1852796517*/){
mySize = myContent.transparencySettings.dropShadowSettings.size;
if(myContent.transparencySettings.dropShadowSettings.xOffset > 0){
myRight = myContent.transparencySettings.dropShadowSettings.xOffset ;
}else{
myLeft = myContent.transparencySettings.dropShadowSettings.xOffset;
}
if(myContent.transparencySettings.dropShadowSettings.yOffset > 0){
myBottom = myContent.transparencySettings.dropShadowSettings.yOffset;
}else{
myTop = myContent.transparencySettings.dropShadowSettings.yOffset;
}
}
}catch(rr){
myAlert("rr\n" + rr);
}
return myTop, myRight, myBottom, myLeft, mySize;
}
function goOut(exitMessage){
try{
if(exitMessage){
alert(exitMessage + "\n\n" + dateRev + "\n" + myId);
}
}catch(e){}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
app.scriptPreferences.enableRedraw = 1;
exit();
}
function myAlert(myAlertMessage){
var myScriptPath = (File(app.activeScript.fullName).parent.fsName).toString();
if(myScriptPath.match(/Benoit/)){
myConfirm = confirm(myAlertMessage + "\n\nMode déboguage");
if(!myConfirm){goOut("Débogage\nArrêt par l'utilisateur.");}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment