wishlist - Move Selected Layer in PS

Anyone, especially newbies, asking for help with photoshop scripting and photoshop automation - as opposed to those contributing to discussion about an aspect of photoshop scripting

Moderators: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators

wishlist - Move Selected Layer in PS

Postby JokerMartini » Sat Jul 31, 2010 4:16 pm

Hello everyone. I'm new to PS Scripting. I do a lot of Maxscripting for 3ds max but in connection with 3d I use photoshop frequently. I was hoping that I could get some help here in making this rather simple script for PS. I've attached an image of what the script would be. It's rather self explanatory. It simply just moves the selected layer with the desired settings.
Let me know what you think. Thanks

Image

JokerMartini
http://www.JokerMartini.com
JokerMartini
 
Posts: 1
Joined: Thu Jul 29, 2010 6:17 pm

Re: wishlist - Move Selected Layer in PS

Postby Paul MR » Sat Jul 31, 2010 7:05 pm

You could give this a try...
Code: Select all
#target photoshop
main();
function main(){
if(!documents.length){
   alert("You need to have a document open!");
   return;
   }
if(activeDocument.layers.length == 1){
   if(activeDocument.activeLayer.isBackgroundLayer){
      alert("You can not move the background layer!");
      return;
      }
   }
if(activeDocument.activeLayer.isBackgroundLayer){
      alert("You can not move the background layer!");
      return;
}
//Add more checks for layer kind here
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,420,250],"+
"p1:Panel{bounds:[10,10,310,140] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"p2:Panel{bounds:[10,10,110,115] , text:'Direction' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"UpperLeft:RadioButton{bounds:[10,10,30,30] , text:'' },"+
"Up:RadioButton{bounds:[40,10,60,30] , text:'' },"+
"UpperRight:RadioButton{bounds:[70,10,90,30] , text:'' },"+
"Left:RadioButton{bounds:[10,40,30,60] , text:'' },"+
"notUsed:RadioButton{bounds:[40,40,60,60] , text:'' },"+
"Right:RadioButton{bounds:[70,40,90,60] , text:'' },"+
"LowerLeft:RadioButton{bounds:[10,70,30,90] , text:'' },"+
"Down:RadioButton{bounds:[40,70,60,90] , text:'' },"+
"LowerRight:RadioButton{bounds:[70,70,90,90] , text:'' }},"+
"statictext1:StaticText{bounds:[120,20,180,37] , text:'Amount' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Amount:EditText{bounds:[120,40,180,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"dd1:DropDownList{bounds:[190,40,290,60]},"+
"MoveLayer:Button{bounds:[115,80,200,100] , text:'Move Layer' },"+
"button1:Button{bounds:[210,80,290,101] , text:'Cancel' }}};"
var win = new Window(dlg,'Move Layer');
win.p1.p2.notUsed.enabled=false;
var Type = ["Pixels","Inches","CM"];
for(var a in Type){
   win.p1.dd1.add('item',Type[a]);
   }
win.p1.dd1.selection=0;
win.p1.Amount.onChanging = function() {
  if (this.text.match(/[^\-\.\d]/)) {
    this.text = this.text.replace(/[^\-\.\d]/g, '');
  }
}
win.p1.MoveLayer.onClick = function(){
var test = false;
if(win.p1.p2.UpperLeft.value) test=true;
if(win.p1.p2.Up.value) test=true;
if(win.p1.p2.UpperRight.value) test=true;
if(win.p1.p2.Left.value) test=true;
if(win.p1.p2.Right.value) test=true;
if(win.p1.p2.LowerLeft.value) test=true;
if(win.p1.p2.Down.value) test=true;
if(win.p1.p2.LowerRight.value) test=true;
if(!test){
   alert("No direction has been selected!");
   return;
   }
if(win.p1.Amount.text == ''){
   alert("No Amount has been entered!");
   return;
   }
win.close(1);
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var cm = activeDocument.resolution/2.54;
var inch = activeDocument.resolution;
var XY = 0;
switch(Number(win.p1.dd1.selection.index)){
   case 0 : XY = Number(win.p1.Amount.text); break;
   case 1 : XY = Number(win.p1.Amount.text) * inch; break;
   case 2 : XY = Number(win.p1.Amount.text) * cm; break;
   default : break;
   }
if(win.p1.p2.UpperLeft.value) activeDocument.activeLayer.translate(-XY,-XY);
if(win.p1.p2.Up.value) activeDocument.activeLayer.translate(-XY,0);
if(win.p1.p2.UpperRight.value) activeDocument.activeLayer.translate(-XY,XY);
if(win.p1.p2.Left.value) activeDocument.activeLayer.translate(-XY,0);
if(win.p1.p2.Right.value) activeDocument.activeLayer.translate(XY,0);
if(win.p1.p2.LowerLeft.value) activeDocument.activeLayer.translate(-XY,-XY);
if(win.p1.p2.Down.value) activeDocument.activeLayer.translate(0,XY);
if(win.p1.p2.LowerRight.value) activeDocument.activeLayer.translate(XY,XY);
app.preferences.rulerUnits = startRulerUnits;
}

win.center();
win.show();
}
Paul MR
 
Posts: 724
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Re: wishlist - Move Selected Layer in PS

Postby Mike Hale » Sat Jul 31, 2010 9:28 pm

Paul, it looks to me like your translate values need work. Up moves left, UpperLeft and LowerLeft both move up and left, etc.
Mike Hale
Site Admin
 
Posts: 2797
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: wishlist - Move Selected Layer in PS

Postby Paul MR » Sat Jul 31, 2010 9:50 pm

You are right, it's getting late here Mike :oops:
Code: Select all
#target photoshop
main();
function main(){
if(!documents.length){
   alert("You need to have a document open!");
   return;
   }
if(activeDocument.layers.length == 1){
   if(activeDocument.activeLayer.isBackgroundLayer){
      alert("You can not move the background layer!");
      return;
      }
   }
if(activeDocument.activeLayer.isBackgroundLayer){
      alert("You can not move the background layer!");
      return;
}
//Add more checks for layer kind here
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,420,250],"+
"p1:Panel{bounds:[10,10,310,140] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"p2:Panel{bounds:[10,10,110,115] , text:'Direction' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"UpperLeft:RadioButton{bounds:[10,10,30,30] , text:'' },"+
"Up:RadioButton{bounds:[40,10,60,30] , text:'' },"+
"UpperRight:RadioButton{bounds:[70,10,90,30] , text:'' },"+
"Left:RadioButton{bounds:[10,40,30,60] , text:'' },"+
"notUsed:RadioButton{bounds:[40,40,60,60] , text:'' },"+
"Right:RadioButton{bounds:[70,40,90,60] , text:'' },"+
"LowerLeft:RadioButton{bounds:[10,70,30,90] , text:'' },"+
"Down:RadioButton{bounds:[40,70,60,90] , text:'' },"+
"LowerRight:RadioButton{bounds:[70,70,90,90] , text:'' }},"+
"statictext1:StaticText{bounds:[120,20,180,37] , text:'Amount' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Amount:EditText{bounds:[120,40,180,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"dd1:DropDownList{bounds:[190,40,290,60]},"+
"MoveLayer:Button{bounds:[115,80,200,100] , text:'Move Layer' },"+
"button1:Button{bounds:[210,80,290,101] , text:'Cancel' }}};"
var win = new Window(dlg,'Move Layer');
win.p1.p2.notUsed.enabled=false;
var Type = ["Pixels","Inches","CM"];
for(var a in Type){
   win.p1.dd1.add('item',Type[a]);
   }
win.p1.dd1.selection=0;
win.p1.Amount.onChanging = function() {
  if (this.text.match(/[^\-\.\d]/)) {
    this.text = this.text.replace(/[^\-\.\d]/g, '');
  }
}
win.p1.MoveLayer.onClick = function(){
var test = false;
if(win.p1.p2.UpperLeft.value) test=true;
if(win.p1.p2.Up.value) test=true;
if(win.p1.p2.UpperRight.value) test=true;
if(win.p1.p2.Left.value) test=true;
if(win.p1.p2.Right.value) test=true;
if(win.p1.p2.LowerLeft.value) test=true;
if(win.p1.p2.Down.value) test=true;
if(win.p1.p2.LowerRight.value) test=true;
if(!test){
   alert("No direction has been selected!");
   return;
   }
if(win.p1.Amount.text == ''){
   alert("No Amount has been entered!");
   return;
   }
win.close(1);
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var cm = activeDocument.resolution/2.54;
var inch = activeDocument.resolution;
var XY = 0;
switch(Number(win.p1.dd1.selection.index)){
   case 0 : XY = Number(win.p1.Amount.text); break;
   case 1 : XY = Number(win.p1.Amount.text) * inch; break;
   case 2 : XY = Number(win.p1.Amount.text) * cm; break;
   default : break;
   }
if(win.p1.p2.UpperLeft.value) activeDocument.activeLayer.translate(-XY,-XY);
if(win.p1.p2.Up.value) activeDocument.activeLayer.translate(0,-XY);
if(win.p1.p2.UpperRight.value) activeDocument.activeLayer.translate(XY,-XY);
if(win.p1.p2.Left.value) activeDocument.activeLayer.translate(-XY,0);
if(win.p1.p2.Right.value) activeDocument.activeLayer.translate(XY,0);
if(win.p1.p2.LowerLeft.value) activeDocument.activeLayer.translate(-XY,XY);
if(win.p1.p2.Down.value) activeDocument.activeLayer.translate(0,XY);
if(win.p1.p2.LowerRight.value) activeDocument.activeLayer.translate(XY,XY);
app.preferences.rulerUnits = startRulerUnits;
}

win.center();
win.show();
}

Haven't tested this :?
Paul MR
 
Posts: 724
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK


Return to Help Me

Who is online

Users browsing this forum: Google [Bot] and 0 guests