Внёс я некоторые исправления и доработки в такие вот скрипты:
1) Распределение объектов с Clipping Mask, действующее и внутри групп (в том числе разных). Отрегулирована некоторая некорректность в работе с группами.
2) Замена объектов одним, с подстройкой размера. (теперь скрипт работает с учётом Clipping Mask)
3) Замена вставленного растра линкованным. (теперь глубина вложенности в группе не имеет значения)
Итак, вот они:
//Распределение объектов с Clipping Mask по горизонтали
mySelection = activeDocument.selection;
function defWidth(obj){
if(obj.typename=='GroupItem'){
width=0;
if(obj.clipped){
width=obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
width=rightSide(obj)-leftSide(obj);
}else{
width=obj.width;
}
}else{
width=obj.width;
}
return width;
}
function rightSide(obj){
if(obj.typename=='GroupItem'){
right=obj.position[0];
if(obj.clipped){
right=obj.pageItems[0].position[0]+obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
ri=objIn.pageItems[0].position[0]+objIn.pageItems[0].width;
}else{
ri=rightSide(objIn)
}
if(ri>right){
right=ri
}
}
}else{
right=obj.position[0]+obj.width;
}
}else{
right=obj.position[0]+obj.width;
}
return right;
}
function leftSide(obj){
if(obj.typename=='GroupItem'){
left=obj.position[0]+obj.width;
if(obj.clipped){
left=obj.pageItems[0].position[0];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
le=objIn.pageItems[0].position[0];
}else{
le=leftSide(objIn);
}
if(le<left){
left=le
}
}
}else{
left=obj.position[0];
}
}else{
left=obj.position[0];
}
return left;
}
function positionLeft(a,b){
return leftSide(a)-leftSide(b);
}
function positionRight(a,b){
return rightSide(b)-rightSide(a);
}
if (mySelection.length>0){
if (mySelection instanceof Array){
ObjArr=new Array();
ObjArr=mySelection;
ObjArr.sort(positionRight);
second=ObjArr[0];
ObjArr.sort(positionLeft);
first=ObjArr[0];
len=leftSide(second)-rightSide(first);
SumWidths=0;
for(i=0;i<ObjArr.length;i++){
if((ObjArr!=first)&&(ObjArr!=second)){
SumWidths+=defWidth(ObjArr);
}
}
otr=(len-SumWidths)/(ObjArr.length-1);
for(i=1;i<(ObjArr.length);i++){
if((ObjArr!=first)&&(ObjArr!=second)){
difr=leftSide(ObjArr)-ObjArr.position[0];
q=i
if(ObjArr[i-1]==second){
q--;
}
ObjArr.position=Array((rightSide(ObjArr[q-1])+(otr-difr)),(ObjArr.position[1]));
}
}
}
}
//Распределение объектов с Clipping Mask по вертикали
mySelection = activeDocument.selection;
function defHeight(obj){
if(obj.typename=='GroupItem'){
height=0;
if(obj.clipped){
height=obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
height=topSide(obj)-bottomSide(obj);
}else{
height=obj.height;
}
}else{
height=obj.height;
}
return height;
}
function bottomSide(obj){
if(obj.typename=='GroupItem'){
bottom=obj.position[1];
if(obj.clipped){
bottom=obj.pageItems[0].position[1]-obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
bot=objIn.pageItems[0].position[1]-objIn.pageItems[0].height;
}else{
bot=bottomSide(objIn)
}
if(bot<bottom){
bottom=bot
}
}
}else{
bottom=obj.position[1]-obj.height;
}
}else{
bottom=obj.position[1]-obj.height;
}
return bottom;
}
function topSide(obj){
if(obj.typename=='GroupItem'){
top=obj.position[1]-obj.height;
if(obj.clipped){
top=obj.pageItems[0].position[1];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
t=objIn.pageItems[0].position[1];
}else{
t=topSide(objIn)
}
if(t>top){
top=t
}
}
}else{
top=obj.position[1];
}
}else{
top=obj.position[1];
}
return top;
}
function positionTop(a,b){
return topSide(b)-topSide(a);
}
function positionBottom(a,b){
return bottomSide(a)-bottomSide(b);
}
if (mySelection.length>0){
if (mySelection instanceof Array){
ObjArr=new Array();
ObjArr=mySelection;
ObjArr.sort(positionBottom);
second=ObjArr[0];
ObjArr.sort(positionTop);
first=ObjArr[0];
len=bottomSide(first)-topSide(second);
SumHeights=0;
for(i=0;i<ObjArr.length;i++){
if((ObjArr!=first)&&(ObjArr!=second)){
SumHeights+=defHeight(ObjArr);
}
}
otr=(len-SumHeights)/(ObjArr.length-1);
for(i=1;i<(ObjArr.length);i++){
if((ObjArr!=first)&&(ObjArr!=second)){
difr=ObjArr.position[1]-topSide(ObjArr);
q=i;
if(ObjArr[i-1]==second){
q--;
}
ObjArr.position=Array((ObjArr.position[0]),(bottomSide(ObjArr[q-1])-(otr-difr)));
}
}
}
}
//Замена объектов одним, с подстройкой размера
function defWidth(obj){
if(obj.typename=='GroupItem'){
width=0;
if(obj.clipped){
width=obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
width=rightSide(obj)-leftSide(obj);
}else{
width=obj.width;
}
}else{
width=obj.width;
}
return width;
}
function rightSide(obj){
if(obj.typename=='GroupItem'){
right=obj.position[0];
if(obj.clipped){
right=obj.pageItems[0].position[0]+obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
ri=objIn.pageItems[0].position[0]+objIn.pageItems[0].width;
}else{
ri=rightSide(objIn)
}
if(ri>right){
right=ri
}
}
}else{
right=obj.position[0]+obj.width;
}
}else{
right=obj.position[0]+obj.width;
}
return right;
}
function leftSide(obj){
if(obj.typename=='GroupItem'){
left=obj.position[0]+obj.width;
if(obj.clipped){
left=obj.pageItems[0].position[0];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
le=objIn.pageItems[0].position[0];
}else{
le=leftSide(objIn);
}
if(le<left){
left=le
}
}
}else{
left=obj.position[0];
}
}else{
left=obj.position[0];
}
return left;
}
function defHeight(obj){
if(obj.typename=='GroupItem'){
height=0;
if(obj.clipped){
height=obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
height=topSide(obj)-bottomSide(obj);
}else{
height=obj.height;
}
}else{
height=obj.height;
}
return height;
}
function bottomSide(obj){
if(obj.typename=='GroupItem'){
bottom=obj.position[1];
if(obj.clipped){
bottom=obj.pageItems[0].position[1]-obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
bot=objIn.pageItems[0].position[1]-objIn.pageItems[0].height;
}else{
bot=bottomSide(objIn)
}
if(bot<bottom){
bottom=bot
}
}
}else{
bottom=obj.position[1]-obj.height;
}
}else{
bottom=obj.position[1]-obj.height;
}
return bottom;
}
function topSide(obj){
if(obj.typename=='GroupItem'){
top=obj.position[1]-obj.height;
if(obj.clipped){
top=obj.pageItems[0].position[1];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
t=objIn.pageItems[0].position[1];
}else{
t=topSide(objIn)
}
if(t>top){
top=t
}
}
}else{
top=obj.position[1];
}
}else{
top=obj.position[1];
}
return top;
}
mySelection = activeDocument.selection;
if (mySelection.length>0){
if (mySelection instanceof Array){
goal=mySelection[0];
goalLeft=leftSide(goal);
goalWidth=defWidth(goal);
goalTop=topSide(goal);
goalHeight=defHeight(goal);
for (i=1; i<(mySelection.length); i++){
currItem=mySelection;
currLeft=leftSide(currItem);
currWidth=defWidth(currItem);
currTop=topSide(currItem);
currHeight=defHeight(currItem);
centerPoint=currLeft+(currWidth/2);
centerPointVert=currTop-(currHeight/2);
ratio=100/(goalWidth/currWidth);
ratioV=100/(goalHeight/currHeight);
newItem=goal.duplicate();
difrLeft=goalLeft-newItem.position[0];
difrTop=goalTop-newItem.position[1];
if(ratio<ratioV){
newItem.resize(ratio,ratio,true,true,true,true,ratio)
}else{
newItem.resize(ratioV,ratioV,true,true,true,true,ratioV)
};
difrLeft=leftSide(newItem)-newItem.position[0];
difrTop=newItem.position[1]-topSide(newItem);
newItem.position=Array(((centerPoint-difrLeft)-(defWidth(newItem)/2)),((centerPointVert+difrTop)+(defHeight(newItem)/2)));
newItem.artworkKnockout=currItem.artworkKnockout;
newItem.clipping=currItem.clipping;
newItem.isIsolated=currItem.isIsolated;
newItem.evenodd=currItem.evenodd;
if(currItem.polarity){
newItem.polarity=currItem.polarity
}
newItem.moveBefore(currItem);
currItem.remove()
}
}
}else{}
//Замена вставленного растра линкованным
mySelection = activeDocument.selection;
function deembed(obj){
if(obj.typename=="GroupItem"){
if(obj.groupItems.length>0){
for(q=0;q<obj.groupItems.length;q++){
deembed(obj.groupItems[q])
}
}else{
for(q=0;q<obj.rasterItems.length;q++){
deembed(obj.rasterItems[q])
}
}
}else if(obj.typename=="RasterItem"){
try{
if(obj.file.exists){
obj.embedded = false
}
}catch(exc){}
}
}
if (mySelection.length>0){
for(i=0;i<(mySelection.length);i++){
deembed(mySelection)
}
}else{}
1) Распределение объектов с Clipping Mask, действующее и внутри групп (в том числе разных). Отрегулирована некоторая некорректность в работе с группами.
2) Замена объектов одним, с подстройкой размера. (теперь скрипт работает с учётом Clipping Mask)
3) Замена вставленного растра линкованным. (теперь глубина вложенности в группе не имеет значения)
Итак, вот они:
//Распределение объектов с Clipping Mask по горизонтали
mySelection = activeDocument.selection;
function defWidth(obj){
if(obj.typename=='GroupItem'){
width=0;
if(obj.clipped){
width=obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
width=rightSide(obj)-leftSide(obj);
}else{
width=obj.width;
}
}else{
width=obj.width;
}
return width;
}
function rightSide(obj){
if(obj.typename=='GroupItem'){
right=obj.position[0];
if(obj.clipped){
right=obj.pageItems[0].position[0]+obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
ri=objIn.pageItems[0].position[0]+objIn.pageItems[0].width;
}else{
ri=rightSide(objIn)
}
if(ri>right){
right=ri
}
}
}else{
right=obj.position[0]+obj.width;
}
}else{
right=obj.position[0]+obj.width;
}
return right;
}
function leftSide(obj){
if(obj.typename=='GroupItem'){
left=obj.position[0]+obj.width;
if(obj.clipped){
left=obj.pageItems[0].position[0];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
le=objIn.pageItems[0].position[0];
}else{
le=leftSide(objIn);
}
if(le<left){
left=le
}
}
}else{
left=obj.position[0];
}
}else{
left=obj.position[0];
}
return left;
}
function positionLeft(a,b){
return leftSide(a)-leftSide(b);
}
function positionRight(a,b){
return rightSide(b)-rightSide(a);
}
if (mySelection.length>0){
if (mySelection instanceof Array){
ObjArr=new Array();
ObjArr=mySelection;
ObjArr.sort(positionRight);
second=ObjArr[0];
ObjArr.sort(positionLeft);
first=ObjArr[0];
len=leftSide(second)-rightSide(first);
SumWidths=0;
for(i=0;i<ObjArr.length;i++){
if((ObjArr!=first)&&(ObjArr!=second)){
SumWidths+=defWidth(ObjArr);
}
}
otr=(len-SumWidths)/(ObjArr.length-1);
for(i=1;i<(ObjArr.length);i++){
if((ObjArr!=first)&&(ObjArr!=second)){
difr=leftSide(ObjArr)-ObjArr.position[0];
q=i
if(ObjArr[i-1]==second){
q--;
}
ObjArr.position=Array((rightSide(ObjArr[q-1])+(otr-difr)),(ObjArr.position[1]));
}
}
}
}
//Распределение объектов с Clipping Mask по вертикали
mySelection = activeDocument.selection;
function defHeight(obj){
if(obj.typename=='GroupItem'){
height=0;
if(obj.clipped){
height=obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
height=topSide(obj)-bottomSide(obj);
}else{
height=obj.height;
}
}else{
height=obj.height;
}
return height;
}
function bottomSide(obj){
if(obj.typename=='GroupItem'){
bottom=obj.position[1];
if(obj.clipped){
bottom=obj.pageItems[0].position[1]-obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
bot=objIn.pageItems[0].position[1]-objIn.pageItems[0].height;
}else{
bot=bottomSide(objIn)
}
if(bot<bottom){
bottom=bot
}
}
}else{
bottom=obj.position[1]-obj.height;
}
}else{
bottom=obj.position[1]-obj.height;
}
return bottom;
}
function topSide(obj){
if(obj.typename=='GroupItem'){
top=obj.position[1]-obj.height;
if(obj.clipped){
top=obj.pageItems[0].position[1];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
t=objIn.pageItems[0].position[1];
}else{
t=topSide(objIn)
}
if(t>top){
top=t
}
}
}else{
top=obj.position[1];
}
}else{
top=obj.position[1];
}
return top;
}
function positionTop(a,b){
return topSide(b)-topSide(a);
}
function positionBottom(a,b){
return bottomSide(a)-bottomSide(b);
}
if (mySelection.length>0){
if (mySelection instanceof Array){
ObjArr=new Array();
ObjArr=mySelection;
ObjArr.sort(positionBottom);
second=ObjArr[0];
ObjArr.sort(positionTop);
first=ObjArr[0];
len=bottomSide(first)-topSide(second);
SumHeights=0;
for(i=0;i<ObjArr.length;i++){
if((ObjArr!=first)&&(ObjArr!=second)){
SumHeights+=defHeight(ObjArr);
}
}
otr=(len-SumHeights)/(ObjArr.length-1);
for(i=1;i<(ObjArr.length);i++){
if((ObjArr!=first)&&(ObjArr!=second)){
difr=ObjArr.position[1]-topSide(ObjArr);
q=i;
if(ObjArr[i-1]==second){
q--;
}
ObjArr.position=Array((ObjArr.position[0]),(bottomSide(ObjArr[q-1])-(otr-difr)));
}
}
}
}
//Замена объектов одним, с подстройкой размера
function defWidth(obj){
if(obj.typename=='GroupItem'){
width=0;
if(obj.clipped){
width=obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
width=rightSide(obj)-leftSide(obj);
}else{
width=obj.width;
}
}else{
width=obj.width;
}
return width;
}
function rightSide(obj){
if(obj.typename=='GroupItem'){
right=obj.position[0];
if(obj.clipped){
right=obj.pageItems[0].position[0]+obj.pageItems[0].width;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
ri=objIn.pageItems[0].position[0]+objIn.pageItems[0].width;
}else{
ri=rightSide(objIn)
}
if(ri>right){
right=ri
}
}
}else{
right=obj.position[0]+obj.width;
}
}else{
right=obj.position[0]+obj.width;
}
return right;
}
function leftSide(obj){
if(obj.typename=='GroupItem'){
left=obj.position[0]+obj.width;
if(obj.clipped){
left=obj.pageItems[0].position[0];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
le=objIn.pageItems[0].position[0];
}else{
le=leftSide(objIn);
}
if(le<left){
left=le
}
}
}else{
left=obj.position[0];
}
}else{
left=obj.position[0];
}
return left;
}
function defHeight(obj){
if(obj.typename=='GroupItem'){
height=0;
if(obj.clipped){
height=obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
height=topSide(obj)-bottomSide(obj);
}else{
height=obj.height;
}
}else{
height=obj.height;
}
return height;
}
function bottomSide(obj){
if(obj.typename=='GroupItem'){
bottom=obj.position[1];
if(obj.clipped){
bottom=obj.pageItems[0].position[1]-obj.pageItems[0].height;
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
bot=objIn.pageItems[0].position[1]-objIn.pageItems[0].height;
}else{
bot=bottomSide(objIn)
}
if(bot<bottom){
bottom=bot
}
}
}else{
bottom=obj.position[1]-obj.height;
}
}else{
bottom=obj.position[1]-obj.height;
}
return bottom;
}
function topSide(obj){
if(obj.typename=='GroupItem'){
top=obj.position[1]-obj.height;
if(obj.clipped){
top=obj.pageItems[0].position[1];
}else if(obj.groupItems.length>0){
for(a=0;a<obj.groupItems.length;a++){
objIn=obj.groupItems[a];
if(objIn.clipped){
t=objIn.pageItems[0].position[1];
}else{
t=topSide(objIn)
}
if(t>top){
top=t
}
}
}else{
top=obj.position[1];
}
}else{
top=obj.position[1];
}
return top;
}
mySelection = activeDocument.selection;
if (mySelection.length>0){
if (mySelection instanceof Array){
goal=mySelection[0];
goalLeft=leftSide(goal);
goalWidth=defWidth(goal);
goalTop=topSide(goal);
goalHeight=defHeight(goal);
for (i=1; i<(mySelection.length); i++){
currItem=mySelection;
currLeft=leftSide(currItem);
currWidth=defWidth(currItem);
currTop=topSide(currItem);
currHeight=defHeight(currItem);
centerPoint=currLeft+(currWidth/2);
centerPointVert=currTop-(currHeight/2);
ratio=100/(goalWidth/currWidth);
ratioV=100/(goalHeight/currHeight);
newItem=goal.duplicate();
difrLeft=goalLeft-newItem.position[0];
difrTop=goalTop-newItem.position[1];
if(ratio<ratioV){
newItem.resize(ratio,ratio,true,true,true,true,ratio)
}else{
newItem.resize(ratioV,ratioV,true,true,true,true,ratioV)
};
difrLeft=leftSide(newItem)-newItem.position[0];
difrTop=newItem.position[1]-topSide(newItem);
newItem.position=Array(((centerPoint-difrLeft)-(defWidth(newItem)/2)),((centerPointVert+difrTop)+(defHeight(newItem)/2)));
newItem.artworkKnockout=currItem.artworkKnockout;
newItem.clipping=currItem.clipping;
newItem.isIsolated=currItem.isIsolated;
newItem.evenodd=currItem.evenodd;
if(currItem.polarity){
newItem.polarity=currItem.polarity
}
newItem.moveBefore(currItem);
currItem.remove()
}
}
}else{}
//Замена вставленного растра линкованным
mySelection = activeDocument.selection;
function deembed(obj){
if(obj.typename=="GroupItem"){
if(obj.groupItems.length>0){
for(q=0;q<obj.groupItems.length;q++){
deembed(obj.groupItems[q])
}
}else{
for(q=0;q<obj.rasterItems.length;q++){
deembed(obj.rasterItems[q])
}
}
}else if(obj.typename=="RasterItem"){
try{
if(obj.file.exists){
obj.embedded = false
}
}catch(exc){}
}
}
if (mySelection.length>0){
for(i=0;i<(mySelection.length);i++){
deembed(mySelection)
}
}else{}