Copy link to clipboard
Copied
Hello everyone! Guys, I'm modifying a script as the goal of adding some functionality in a dialog box to assist me in automating Layout for photo book covers. The main feature is to add a space (varies by the total amount of pages) between two vertical guides in the center of the document.
I made a short video to make it easier to understand my question:
In the end it would have to look like the illustration:
This is my script:
var dial = new Window ("dialog", "My Dialog", undefined);
dial.orientation = "column";
dial.alignChildren = "fill";
dial.margins = 20;
var dPanel = dial.add ("panel", undefined, "Document Finished Size");
dPanel.orientation = "column";
dPanel.alignChildren = "left";
dPanel.margins = 15;
var aLevels = dPanel.add ("checkbox", undefined, "Add Finished Size");
var dGroup = dial.add ("group", undefined);
dGroup.orientation = "row";
dGroup.alignChildren = "left";
var st = dGroup.add ("statictext", undefined, "Add Center Guides:");
var nField = dGroup.add ("edittext", undefined, "1");
nField.characters = 4;
var un = dGroup.add ("statictext", undefined, "Centimeters");
var gButtons = dial.add ("group", undefined);
gButtons.orientation = "row";
gButtons.alignChildren = ["right", "right"];
var canc = gButtons.add ("button", undefined, "Cancel", {name:"cancel"});
var exe = gButtons.add ("button", undefined, "To Apply", {name:"ok"});
dial.show();
Could someone give me strength in this project ?? Thank you
In the UK we use a full stop instead of a comma.
The code will now accept either comma or a fullstop.
...#target photoshop;
app.bringToFront();
var dial = new Window ("dialog", "My Dialog", undefined);
dial.orientation = "column";
dial.alignChildren = "fill";
dial.margins = 20;
var dPanel = dial.add ("panel", undefined, "Document Finished Size");
dPanel.orientation = "column";
dPanel.alignChildren = "left";
dPanel.margins = 15;
var aLevels = dPanel.add ("checkbox", undefined, "Add Finished Size
Copy link to clipboard
Copied
#target photoshop;
app.bringToFront();
var dial = new Window ("dialog", "My Dialog", undefined);
dial.orientation = "column";
dial.alignChildren = "fill";
dial.margins = 20;
var dPanel = dial.add ("panel", undefined, "Document Finished Size");
dPanel.orientation = "column";
dPanel.alignChildren = "left";
dPanel.margins = 15;
var aLevels = dPanel.add ("checkbox", undefined, "Add Finished Size");
var dGroup = dial.add ("group", undefined);
dGroup.orientation = "row";
dGroup.alignChildren = "left";
var st = dGroup.add ("statictext", undefined, "Add Center Guides:");
var nField = dGroup.add ("edittext", undefined, "1");
nField.characters = 4;
var un = dGroup.add ("statictext", undefined, "Centimeters");
var gButtons = dial.add ("group", undefined);
gButtons.orientation = "row";
gButtons.alignChildren = ["right", "right"];
var canc = gButtons.add ("button", undefined, "Cancel", {name:"cancel"});
var exe = gButtons.add ("button", undefined, "To Apply", {name:"ok"});
exe.onClick = function(){
dial.close(0);
var doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var Res = doc.resolution;
if(aLevels.value){
//code goes here for "Add Finished Size"
//No idea what you mean.
}
var cm = Res/2.54;
var Width = doc.width;
var leftGuide = (Width/2) - (cm * Number( nField.text)/2);
var rightGuide = (Width/2) + (cm * Number( nField.text)/2);
guideLine(leftGuide,'Vrtc','#Pxl');
guideLine(rightGuide,'Vrtc','#Pxl');
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
}
if(documents.length) dial.show();
function guideLine(position, type,unit) {
//unit '#Pxl' pixel '#Rlt' =Relative to 72PPI '#Prc' = percent
// types: 'Vrtc' & 'Hrzn'
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);
desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );
desc.putObject( charIDToTypeID('Nw '), charIDToTypeID('Gd '), desc2 );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
Copy link to clipboard
Copied
Congratulations SuperMerlin! How wonderful to see my ideas come to life. SuperMerlin you are one of the largest and one of the top Photoshop script programmers I have ever seen in the world. Like a few lines you solved the question.
I made several tests here and actually the script works fine, however I noticed only a small error: When I add a value of "1,5 cm," or any number after the comma, the script has an error in "line 62". If this is something that you can adjust I will be very grateful if not, I'm happy the same way. Sheltered my friend.
Copy link to clipboard
Copied
In the UK we use a full stop instead of a comma.
The code will now accept either comma or a fullstop.
#target photoshop;
app.bringToFront();
var dial = new Window ("dialog", "My Dialog", undefined);
dial.orientation = "column";
dial.alignChildren = "fill";
dial.margins = 20;
var dPanel = dial.add ("panel", undefined, "Document Finished Size");
dPanel.orientation = "column";
dPanel.alignChildren = "left";
dPanel.margins = 15;
var aLevels = dPanel.add ("checkbox", undefined, "Add Finished Size");
var dGroup = dial.add ("group", undefined);
dGroup.orientation = "row";
dGroup.alignChildren = "left";
var st = dGroup.add ("statictext", undefined, "Add Center Guides:");
var nField = dGroup.add ("edittext", undefined, "1");
nField.characters = 4;
var un = dGroup.add ("statictext", undefined, "Centimeters");
var gButtons = dial.add ("group", undefined);
gButtons.orientation = "row";
gButtons.alignChildren = ["right", "right"];
var canc = gButtons.add ("button", undefined, "Cancel", {name:"cancel"});
var exe = gButtons.add ("button", undefined, "To Apply", {name:"ok"});
exe.onClick = function(){
dial.close(0);
var doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var Res = doc.resolution;
if(aLevels.value){
//code goes here for "Add Finished Size"
//No idea what you mean.
}
var cm = Res/2.54;
var Width = doc.width;
var selectedCM = Number( nField.text.toString().replace(/,/g,'.'));
var leftGuide = (Width/2) - (cm * selectedCM/2);
var rightGuide = (Width/2) + (cm * selectedCM/2);
guideLine(leftGuide,'Vrtc','#Pxl');
guideLine(rightGuide,'Vrtc','#Pxl');
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
}
if(documents.length) dial.show();
function guideLine(position, type,unit) {
//unit '#Pxl' pixel '#Rlt' =Relative to 72PPI '#Prc' = percent
// types: 'Vrtc' & 'Hrzn'
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);
desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );
desc.putObject( charIDToTypeID('Nw '), charIDToTypeID('Gd '), desc2 );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
Copy link to clipboard
Copied
SuperMerlin, now it worked divinely well! Very happy with the result. Thank you one more time! I have some ideas here in mind and soon I am realizing thanks to you and the other programmers. Thank you my friend. What nationality in the United Kingdom are you? A strong embrace of the people here in Brazil.
Copy link to clipboard
Copied
Hi smithcgl9043167​,
for "Add Finished Size"
try do replace this lines of code in SuperMerlins script
var Res = doc.resolution;
if(aLevels.value){
//code goes here for "Add Finished Size"
//No idea what you mean.
}
var cm = Res/2.54;
var Width = doc.width;
var selectedCM = Number( nField.text.toString().replace(/,/g,'.'));
var leftGuide = (Width/2) - (cm * selectedCM/2);
var rightGuide = (Width/2) + (cm * selectedCM/2);
guideLine(leftGuide,'Vrtc','#Pxl');
guideLine(rightGuide,'Vrtc','#Pxl');
with this lines
var Res = doc.resolution;
var cm = Res/2.54;
var Width = doc.width;
var selectedCM = Number( nField.text.toString().replace(/,/g,'.'));
var leftGuide = (Width/2) - (cm * selectedCM/2);
var rightGuide = (Width/2) + (cm * selectedCM/2);
guideLine(leftGuide,'Vrtc','#Pxl');
guideLine(rightGuide,'Vrtc','#Pxl');
if(aLevels.value){
//code goes here for "Add Finished Size"
//No idea what you mean.
var desc3 = new ActionDescriptor();
desc3.putBoolean( charIDToTypeID('Rltv'), true );
desc3.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Rlt'), cm * selectedCM );
desc3.putEnumerated( charIDToTypeID('Hrzn'), charIDToTypeID('HrzL'), charIDToTypeID('Cntr') );
desc3.putEnumerated( stringIDToTypeID('canvasExtensionColorType'), stringIDToTypeID('canvasExtensionColorType'), charIDToTypeID('Wht ') );
executeAction( charIDToTypeID('CnvS'), desc3, DialogModes.NO );
};
Have fun
Copy link to clipboard
Copied
https://forums.adobe.com/people/pixxxel+schubser escreveu
Hi smithcgl9043167 ,
for "Add Finished Size"
try do replace this lines of code in SuperMerlin s script
var Res = doc.resolution; if(aLevels.value){ //code goes here for "Add Finished Size" //No idea what you mean. } var cm = Res/2.54; var Width = doc.width; var selectedCM = Number( nField.text.toString().replace(/,/g,'.')); var leftGuide = (Width/2) - (cm * selectedCM/2); var rightGuide = (Width/2) + (cm * selectedCM/2); guideLine(leftGuide,'Vrtc','#Pxl'); guideLine(rightGuide,'Vrtc','#Pxl');
with this lines
var Res = doc.resolution; var cm = Res/2.54; var Width = doc.width; var selectedCM = Number( nField.text.toString().replace(/,/g,'.')); var leftGuide = (Width/2) - (cm * selectedCM/2); var rightGuide = (Width/2) + (cm * selectedCM/2); guideLine(leftGuide,'Vrtc','#Pxl'); guideLine(rightGuide,'Vrtc','#Pxl'); if(aLevels.value){ //code goes here for "Add Finished Size" //No idea what you mean. var desc3 = new ActionDescriptor(); desc3.putBoolean( charIDToTypeID('Rltv'), true ); desc3.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Rlt'), cm * selectedCM ); desc3.putEnumerated( charIDToTypeID('Hrzn'), charIDToTypeID('HrzL'), charIDToTypeID('Cntr') ); desc3.putEnumerated( stringIDToTypeID('canvasExtensionColorType'), stringIDToTypeID('canvasExtensionColorType'), charIDToTypeID('Wht ') ); executeAction( charIDToTypeID('CnvS'), desc3, DialogModes.NO ); };
Have fun
Thank you pixxxel schubser. SuperMerlin had already been fixed previously! It is already working perfectly.
You are great programmers!
Copy link to clipboard
Copied
It's ok.
I thought @SuperMerlin fixed only the "floating point numbers problem" for you. Because of his lines:
//code goes here for "Add Finished Size"
//No idea what you mean.
I saw no one other code which fixed your "Add Finished Size problem".
That was the reason for my answer. Can you show me his solution in conclusion, please (only to see if I also was on the right way)
Have fun
Copy link to clipboard
Copied
Hi pixxxel schubser! It was simple, I just added the "checkbox" script ... Nothing more than just an "action converted to jsx" that resizes the final area of the document. I do not know if I understood your question well, but I made a point of making a short video so that you can understand better. It's working fine with me here.
This was the final script:
https://pastebin.com/raw/1xtBDbM4
A hug.
Copy link to clipboard
Copied
This question is more than approved for me. I realized my friends here are inspired and we can go much further than that. There arose a new challenge based on this idea. Soon the night, I will create a new discourse denominated as the second part.
Copy link to clipboard
Copied
smithcgl9043167 schrieb
This was the final script …
Not bad for a beginner.
But there are too many steps inside. Enough stuff for optimizing later.
Copy link to clipboard
Copied
I was born in West Yorkshire, England.
It looks as if you have sent some nice weather a its 25 degrees at the moment.
All the best in Brazil.
Geoff.