ericsmeets
05-04-2005, 12:54 PM
Here's my script.
Please copy it and run it. A window appears. Click the first 'bladeren" button.
(It's dutch :grin: ) Select a file. And then what I want is the name and the path of the selected file is displayed in the edittext field next to the button.
After making other adjustments in the window the user presses ''bevestigen'' (=Confirm) and then the previously selected document is read.
I hope you understand it cause my english istn't that good.
Eric.
// JavaScript Document
// Copyright Eric Smeets 2005
var gParams = null;
//Originele meeteenheid en typeeenheid opslaan
var OriginalRulerUnit = app.preferences.rulerUnit;
var OriginalTypeUnit = app.preferences.typeUnit;
//Onzetten in CM.
app.preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.PIXELS;
//TESTEN
//alert( "Show me the money." );
//var yesOrNo = confirm( "Proceed?" );
//var answer = prompt( "Enter an amount:", 100 );
//var dataFile = File.openDialog("Selecteer achtergrondfoto", "Afbeeldingen:*.jpg;*.psd,All files:*");
//var Achtergrond = new File(datafile);
//open(Achtergrond);
BouwScherm();
/*
//Nieuw document 4x4 centimeter
var Document = app.documents.add( 4, 4, 300, "Testdocument" );
//Nieuwe laag voor tekst aanmaken
var Laag1 = Document.artLayers.add();
Laag1.kind = LayerKind.TEXT;
Laag1.name = "Tekstlaag"
//Vullen met tekst
var textItemRef = Laag1.textItem;
textItemRef.contents = "Hello, World!";
//Lettertype veranderen
Laag1.textItem.font = "ArialMT";
//Nog een nieuwe laag aanmaken
var Laag2 = Document.artLayers.add();
Laag2.kind = LayerKind.TEXT;
Laag2.name = "Laag2"
//laag selecteren
Document.activeLayer = Document.layers["Tekstlaag"];
*/
//Originele meeteenheid en typeenheid terugzetten
app.preferences.rulerUnit = OriginalRulerUnit;
app.preferences.typeUnit = OriginalTypeUnit;
//Variabelen leegmaken
docRef = null;
Laag1 = null;
textItemRef = null;
originalUnit = null;
////////////////////////////////////FUNCTIONS/////////////////////////////////////////////
function BouwScherm()
{
//Scherm
var dlg = new Window('dialog', 'Eric Smeets', [100,100,480,550]);
//Basisinformatie
dlg.Bspanel = dlg.add('panel', [25,15,355,130], 'Basisinformatie');
dlg.Bspanel.SchoolA = dlg.Bspanel.add('statictext', [15,18,105,43], 'Naam school:');
dlg.Bspanel.SchoolB = dlg.Bspanel.add('edittext', [115,15,315,35], '');
dlg.Bspanel.KlasA = dlg.Bspanel.add('statictext', [15,51,105,71], 'Groep:');
dlg.Bspanel.KlasB = dlg.Bspanel.add('edittext', [115,50,315,70], '');
dlg.Bspanel.SchooljaarA = dlg.Bspanel.add('statictext', [15,85,105,105], 'Schooljaar:');
dlg.Bspanel.SchooljaarB = dlg.Bspanel.add('edittext', [115,85,315,105], '');
//Selectiepaneel
dlg.SelPnl = dlg.add('panel', [25,135,355,275], 'Documenten');
dlg.SelPnl.Achterfoto = dlg.SelPnl.add('statictext', [15,15,200,35], 'Selecteer achtergrondfoto:');
dlg.SelPnl.BrwsBtn = dlg.SelPnl.add('button', [15,40,110,60], 'Bladeren');
dlg.SelPnl.BrwsBtn.onClick = btnBrowseOnClick;
dlg.SelPnl.BrwsDestination = dlg.SelPnl.add('edittext', [115,40,315,60], '');
dlg.SelPnl.Koppenmap = dlg.SelPnl.add('statictext', [15,75,200,95], 'Selecteer map met koppenfotos:');
dlg.SelPnl.BrwsBtn2 = dlg.SelPnl.add('button', [15,100,110,120], 'Bladeren');
dlg.SelPnl.BrwsBtn2.onClick = btnSelecteerMap;
dlg.SelPnl.BrwsDestination2 = dlg.SelPnl.add('edittext', [115,100,315,120], '');
//Add a checkbox to control the presence of buttons to dismiss the alert box
//dlg.hasBtnsCb = dlg.add('checkbox', [125,145,255,165], 'Has alert buttons?');
//Add panel to determine alignment of buttons on the alert box
//dlg.alertBtnsPnl = dlg.add('panel', [45,180,335,225], 'Button alignment');
//dlg.alertBtnsPnl.alignLeftRb = dlg.alertBtnsPnl.add('radiobutton', [15,15,95,35], 'Left');
//dlg.alertBtnsPnl.alignCenterRb = dlg.alertBtnsPnl.add('radiobutton', [105,15,185,35],'Center');
//dlg.alertBtnsPnl.alignRightRb = dlg.alertBtnsPnl.add('radiobutton', [195,15,275,35], 'Right');
//Afmetingen
dlg.sizePnl = dlg.add('panel', [25,285,355,390], 'Afmetingen uiteindelijke afbeelding');
dlg.sizePnl.widthSt = dlg.sizePnl.add('statictext', [15,20,65,40], 'Breedte:');
dlg.sizePnl.widthScrl = dlg.sizePnl.add('scrollbar', [75,20,195,40], 300, 300, 800);
dlg.sizePnl.widthEt = dlg.sizePnl.add('edittext', [205,20,245,40]);
dlg.sizePnl.heightSt = dlg.sizePnl.add('statictext', [15,45,65,65], 'Hoogte:');
dlg.sizePnl.heightScrl = dlg.sizePnl.add('scrollbar', [75,45,195,65], 200, 200, 600);
dlg.sizePnl.heightEt = dlg.sizePnl.add('edittext', [205,45,245,65]);
dlg.sizePnl.dpiSt = dlg.sizePnl.add('statictext', [15,80,75,100], 'Resolutie:');
dlg.sizePnl.dpiEt = dlg.sizePnl.add('edittext', [75,78,130,98]);
dlg.sizePnl.dpi2St = dlg.sizePnl.add('statictext', [140,80,225,100], 'pixels/inch');
//Knoppenpaneel
dlg.btnPnl = dlg.add('panel', [15,400,375,440], '');
dlg.btnPnl.okBtn = dlg.btnPnl.add('button', [40,10,160,30], 'Bevestigen', {name:'ok'});
dlg.btnPnl.okBtn.onClick = Okbutton;
dlg.btnPnl.cancelBtn = dlg.btnPnl.add('button', [180,10,300,30], 'Annuleren', {name:'cancel'});
dlg.btnPnl.cancelBtn.onClick = cancelbutton;
dlg.show();
}
/*function btnSelecteerBestand()
{
this.parent.SelPnl.BrwsDestination.text = selFile.toString();
var selFile = File.saveDialog("Selecteer de achtergrondfoto");
//if ( selFile != null ) {
dlg.close();
alert( "Show me the money." );
//}
return;
}
*/
function btnBrowseOnClick()
{
var selFile = File.openDialog("Selecteer achtergrondbestand");
//app.open (selFile);
alert ("hoi");
}
function btnSelecteerMap()
{
var inputFolder = Folder.selectDialog("Selecteer de map waar de koppenfoto's zich bevinden.");
for (i = 0; i < app.documents.length; ++i)
{
var myName = app.documents[i].name;
alert(myName);
}
//var fileList = inputFolder.getFiles
//dlg.close();
//this.parent.BrwsDestination2 = inputFolder.toString();
}
function Okbutton()
{
/*textColor = new SolidColor;
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
var docRef = activeDocument;
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
var textItemRef = artLayerRef.textItem;
textItemRef.contents = docRef.name;
textItemRef.color = textColor;
*/
app.open (selFile);
}
function cancelbutton()
{
alert ("goeiendag");
dlg.show();
}
Eric,
Unfortunately I don't have CS here, so I can't test any of this stuff.
But, I think that your are trying to use the file name here....
dlg.SelPnl.BrwsDestination = dlg.SelPnl.add('edittext', [115,40,315,60], '');after returning from the function btnBrowseOnClick() call, but you can't do that.
In the function BouwScherm() you are only setting up a dialog, and not executing anything. In other words you are saying what will be done when the button is pressed, but you are not actually doing it.
If you want to put the filename in the 'edittext' field then you must do it inside the function btnBrowseOnClick() with something like:
dlg.SelPnl.BrwsDestination = selFile.name
I may also be completely wrong as I have never done a dialog and I don't have CS - hope I didn't just make a complete fool of myself.
Hope I helped, good luck,
Rô