Hi,
I am trying to create a UI using Javascript to open up some images in Photoshop and then to generate those images in a poster type layout.
I managed to develop the UI elements fairly easily and the images open up in photoshop perfectly but now I have reached a problem.
Each image opens up in its own document which is fine but I am unaware as to how to reference the images in their documents In Javascript.
I have been able to create the A4 poster and I am able to identify the first image and manipulate it in the script but when I try to reference the other images, It still selects the image in the first document ?.
Any help would be really appreciated.
Here is my code so far:
// script to make a poster
app.preferences.rulerUnits = Units.PIXELS;
// create a dialog window
var dig = new Window('dialog', 'choose 6 images', [270,40,950,1000]);
//create a panel for the image 1 compenents
dig.panel1 = dig.add('panel', [10,10,460,100], 'Image 1');
dig.panel1.label1 = dig.panel1.add('statictext' , [20,20,120,40],'Chose Image 1:');
dig.panel1.t1 = dig.panel1.add('edittext', [125,20,325,40], 'image1.jpg');
dig.panel1.bt1 = dig.panel1.add('button', [330,20,420,40], 'Open Image');
//create a panel for the image 2 components
dig.panel2 = dig.add('panel', [10,110,460,200], 'Image 2');
dig.panel2.label2 = dig.panel2.add('statictext' , [20,20,120,40],'Chose Image 2:');
dig.panel2.t2 = dig.panel2.add('edittext', [125,20,325,40], 'image2.jpg');
dig.panel2.bt2 = dig.panel2.add('button', [330,20,420,40], 'Open Image');
//create a panel for the image 3 components
dig.panel3 = dig.add('panel', [10,210,460,300], 'Image 3');
dig.panel3.label3 = dig.panel3.add('statictext' , [20,20,120,40],'Chose Image 3:');
dig.panel3.t3 = dig.panel3.add('edittext', [125,20,325,40], 'image3.jpg');
dig.panel3.bt3 = dig.panel3.add('button', [330,20,420,40], 'Open Image');
//create a panel for the image 4 components
dig.panel4 = dig.add('panel', [10,310,460,400], 'Image 4');
dig.panel4.label4 = dig.panel4.add('statictext' , [20,20,120,40],'Chose Image 4:');
dig.panel4.t4 = dig.panel4.add('edittext', [125,20,325,40], 'image4.jpg');
dig.panel4.bt4 = dig.panel4.add('button', [330,20,420,40], 'Open Image');
//create a panel for the image 5 components
dig.panel5 = dig.add('panel', [10,410,460,500], 'Image 5');
dig.panel5.label5 = dig.panel5.add('statictext' , [20,20,120,40],'Chose Image 5:');
dig.panel5.t5 = dig.panel5.add('edittext', [125,20,325,40], 'image5.jpg');
dig.panel5.bt5 = dig.panel5.add('button', [330,20,420,40], 'Open Image');
//create a panel for image 6 components
dig.panel6 = dig.add('panel', [10,510,460,600], 'Image 6');
dig.panel6.label6 = dig.panel6.add('statictext' , [20,20,120,40],'Chose Image 6:');
dig.panel6.t6 = dig.panel6.add('edittext', [125,20,325,40], 'image6.jpg');
dig.panel6.bt6 = dig.panel6.add('button', [330,20,420,40], 'Open Image');
//create the button to clear the textboxes
//dig.bt7=dig.add('button', [200,600,200,80], 'Clear');
//dig.bt7.onlclick = function ()
// deal with buttons event
//create the button generate poster
dig.bt=dig.add('button', [255,600,400,700], 'Generate Poster');
//deals with bt1 events
dig.panel1.bt1.onClick = function()
{
var name;
if ((name=File.openDialog("Open image 1","black.jpg", false))!=null){
app.load(name);
dig.panel1.t1.text = name.path+"Images/black.jpg"+name.name;
}
}
//deals with bt2 events
dig.panel2.bt2.onClick = function()
{
var name;
if ((name=File.openDialog("Open image 2","operahouse.jpg", false))!=null){
app.load(name);
dig.panel2.t2.text = name.path+"Images/operahouse.jpg"+name.name;
}
}
//deals with bt3 events
dig.panel3.bt3.onClick = function()
{
var name;
if ((name=File.openDialog("Open image 3","busker.jpg", false))!=null){
app.load(name);
dig.panel3.t3.text = name.path+"Images/busker.jpg"+name.name;
}
}
//deals with bt4 events
dig.panel4.bt4.onClick = function()
{
var name;
if ((name=File.openDialog("Open image 4","statue.jpg", false))!=null){
app.load(name);
dig.panel4.t4.text = name.path+"Images/statue.jpg"+name.name;
}
}
//deals with bt5 events
dig.panel5.bt5.onClick = function()
{
var name;
if ((name=File.openDialog("Open image 5","CorkJazz.jpg", false))!=null){
app.load(name);
dig.panel5.t5.text = name.path+"Images/CorkJazz.jpg"+name.name;
}
}
//deals with bt6 events
dig.panel6.bt6.onClick = function()
{
var name;
if ((name=File.openDialog("Open image 6","grafitti.jpg", false))!=null){
app.load(name);
dig.panel6.t6.text = name.path+"Images/grafitti.jpg"+name.name;
}
}
// deal with bt events
dig.bt.onClick=function()
{
dig.close();
}
// Show
dig.show ();
// make a reference to the images
var doc1=app.documents[0];
var doc2=app.documents[0];
// Open a new A4 document
var newDoc = app.documents.add(1500, 1000, 300.0, "My New Document");
// construct a solid color
var rgbColor=new RGBColor();
rgbColor.red=200;rgbColor.green=200;rgbColor.blue=200;
var solidColor=new SolidColor();
solidColor.model=ColorModel.RGB;
solidColor.rgb=rgbColor;
// fill the new document with a color
app.activeDocument=newDoc;
newDoc.selection.selectAll();
newDoc.selection.fill(solidColor);
// create a new art layer and bring in the first image
app.activeDocument=doc1;
doc1.resizeImage(842,595);
doc1.selection.selectAll();
doc1.selection.copy();
doc1.selection.deselect();
app.activeDocument=newDoc;
newDoc.artLayers.add();
newDoc.paste();
newDoc.activeLayer.translate(-700,-500);
// create a new art layer and bring in the second image
app.activeDocument=doc2;
doc2.resizeImage(842,595);
doc2.selection.selectAll();
doc2.selection.copy();
doc2.selection.deselect();
app.activeDocument=newDoc;
newDoc.artLayers.add();
newDoc.paste();
newDoc.activeLayer.translate(700,-500); |