K
Kelly********
First I like to mention I know this isnt a excel script, but Ive search for
the answer elswhere whit no luck. So once again I turn to the forum that
helps everyone and doesnt just blow off the tough ones.
I want to change a file name and then save that file to my documents
in the fallowing script at about line 149 it saves by over righting the file
then closes.
I want to save as the company name then save to another folder. if anyone
can help it would be great.
// The program first opens the insert and the cd face files.
// Next, a window appears asking for the text content for both files needed
for delivery.
// This is for CJ Deliveries.
// **********************************
// Localize the script
$.localize = true;
// Declare load variables
var InsertFilePath = "/c/Delivery%20Insert/CD-INSERT-BRAVO-ENCORE2006.tif";
var InsertFileName = "CD-INSERT-BRAVO-ENCORE2006.tif";
var SurfaceFilePath =
"/c/Delivery%20CD%20Faces/CD-SURFACE-BRAVOENCORE2006.tif";
var SurfaceFileName = "CD-SURFACE-BRAVOENCORE2006.tif";
var ModelLayerName = Array("BRAVO","ENCORE","ENCORE+");
var CLayerName = "COMPANY";
var SLayerName = "SERIAL";
//Declare user input variables
var CompanyValue;
var SerialValue;
var i = 0;
var t = 0;
// Sets the switch for debug capabilities
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
var debug = false;
// Save User Preferrences
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
// Set Adobe Photoshop to use pixels and display no dialogs
app.preferences.rulerUnits = Units.INCHES;
app.preferences.typeUnits = TypeUnits.POINTS;
//Close all the open documents
while(app.documents.length)
{
activeDocument.close();
}
//Open the documents and assign document variables
var InsertDoc = open(File(InsertFilePath));
var InsertCLayer = InsertDoc.artLayers[CLayerName];
if (debug) { alert("Here is " + InsertDoc.name + "'s name and kind: " +
InsertCLayer.name + " , " + InsertCLayer.kind) };
var InsertSLayer = InsertDoc.artLayers[SLayerName];
if (debug) { alert("Here is " + InsertDoc.name + "'s name and kind: " +
InsertSLayer.name + " , " + InsertSLayer.kind) };
var SurfaceDoc = open(File(SurfaceFilePath));
var SurfaceCLayer = SurfaceDoc.artLayers[CLayerName];
if (debug) { alert("Here is " + SurfaceDoc.name + "'s name and kind: " +
SurfaceCLayer.name + " , " + SurfaceCLayer.kind) };
var SurfaceSLayer = SurfaceDoc.artLayers[SLayerName];
if (debug) { alert("Here is " + SurfaceDoc.name + "'s name and kind: " +
SurfaceSLayer.name + " , " + SurfaceSLayer.kind) };
//Create a user input form
var textchange = new Window('dialog');
textchange.text = "TextChange v1.0";
textchange.frameLocation = [300,300];
textchange.panel = textchange.add('panel');
textchange.panel.text = "User Input";
textchange.alignment = 'fill';
textchange.panel.model = textchange.panel.add('group');
textchange.panel.model.modelst = textchange.panel.model.add('statictext');
textchange.panel.model.modelst.text = "Model:";
textchange.panel.model.modeldrop =
textchange.panel.model.add('dropdownlist', undefined, ModelLayerName);
textchange.panel.model.modeldrop.items = ModelLayerName;
textchange.panel.model.modeldrop.preferredSize = [100,20];
//EVENT onChange modeldrop
textchange.panel.model.modeldrop.onChange = function ()
{
if (debug){ alert("Here is the length of items: " +
textchange.panel.model.modeldrop.items.length) };
for (i=0; i < textchange.panel.model.modeldrop.items.length; i++)
{
if (debug){ alert("Here is the current item: " +
textchange.panel.model.modeldrop.items.toString()) };
if (debug){ alert("Here is the selected item: " +
textchange.panel.model.modeldrop.items.selected) };
if (textchange.panel.model.modeldrop.items.selected)
{
app.activeDocument = InsertDoc
InsertDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = true;
app.activeDocument = SurfaceDoc;
SurfaceDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = true;
}
else
{
app.activeDocument = InsertDoc;
InsertDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = false;
app.activeDocument = SurfaceDoc;
SurfaceDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = false;
}
}
};
textchange.panel.company = textchange.panel.add('group');
textchange.panel.company.companyst =
textchange.panel.company.add('statictext');
textchange.panel.company.companyst.text = "Company:";
textchange.panel.company.companyet =
textchange.panel.company.add('edittext');
textchange.panel.company.companyet.text = "";
textchange.panel.company.companyet.preferredSize = [100,20];
textchange.panel.serial = textchange.panel.add('group');
textchange.panel.serial.serialst =
textchange.panel.serial.add('statictext');
textchange.panel.serial.serialst.text = "Serial:";
textchange.panel.serial.serialet =
textchange.panel.serial.add('edittext');
textchange.panel.serial.serialet.text = "";
textchange.panel.serial.serialet.preferredSize = [100,20];
textchange.panel.buttons = textchange.panel.add('group');
textchange.panel.buttons.okbtn = textchange.panel.buttons.add('button');
textchange.panel.buttons.okbtn.text = "OK";
textchange.panel.buttons.okbtn.properties =
{
name:"ok"
};
// EVENT onClick okbtn
textchange.panel.buttons.okbtn.onClick = function ()
{
// Gets the values from the user form
CompanyValue = textchange.panel.company.companyet.text;
if (debug) { alert("Here is the CompanyValue: " + CompanyValue) };
SerialValue = textchange.panel.serial.serialet.text;
if (debug) { alert("Here is the SerialValue: " + SerialValue) };
// Sets the textinfo content of each text artlayer of each document to
the above values
app.activeDocument = InsertDoc;
CreateTextLayer(InsertDoc, CLayerName, CompanyValue);
CreateTextLayer(InsertDoc, SLayerName, SerialValue);
app.activeDocument = SurfaceDoc;
CreateTextLayer(SurfaceDoc, CLayerName, CompanyValue);
CreateTextLayer(SurfaceDoc, SLayerName, SerialValue);
//Close and save the surface file
SurfaceDoc.close(SaveOptions.SAVECHANGES);
save(File(InsertFilePath));
textchange.close();
ReturnPref();
};
textchange.panel.buttons.cancelbtn =
textchange.panel.buttons.add('button');
textchange.panel.buttons.cancelbtn.text = "Cancel";
textchange.panel.buttons.cancelbtn.properties =
{
name:"cancel"
};
// EVENT onClick cancelbtn
textchange.panel.buttons.cancelbtn.onClick = function ()
{
textchange.hide();
textchange.close();
ReturnPref();
};
textchange.show();
/****************************************************************************************
**USER DEFINED
FUNCTIONS*****************************************************************
****************************************************************************************/
function ReturnPref ()
{
// Return preferences to normal
if (debug) { alert("Hey the function call worked!!!") };
ModelLayerName = null;
textchange = null;
InsertDoc = null;
InsertCLayer = null;
InsertSLayer = null;
SurfaceDoc = null;
SurfaceCLayer = null;
SurfaceSLayer = null;
textlayer = null;
preferences.rulerUnits = startRulerUnits;
preferences.typeUnits = startTypeUnits;
}
function CreateTextLayer( doc, LayerName, Content )
{
var docArtLayer = doc.artLayers[LayerName];
if (debug) { alert("docArtLayer.name = " + docArtLayer.name) };
if (debug) { alert("docArtLayer.textItem.kind = " +
docArtLayer.textItem.kind) };
if (debug) { alert("docArtLayer.textItem.useAutoLeading = " +
docArtLayer.textItem.useAutoLeading) };
if (debug) { alert("docArtLayer.textItem.justification = " +
docArtLayer.textItem.justification) };
var textlayer =
docArtLayer.duplicate(docArtLayer,ElementPlacement.PLACEBEFORE);
textlayer.textItem.contents = Content;
doc.artLayers[LayerName].remove();
textlayer.name = LayerName;
}
the answer elswhere whit no luck. So once again I turn to the forum that
helps everyone and doesnt just blow off the tough ones.
I want to change a file name and then save that file to my documents
in the fallowing script at about line 149 it saves by over righting the file
then closes.
I want to save as the company name then save to another folder. if anyone
can help it would be great.
// The program first opens the insert and the cd face files.
// Next, a window appears asking for the text content for both files needed
for delivery.
// This is for CJ Deliveries.
// **********************************
// Localize the script
$.localize = true;
// Declare load variables
var InsertFilePath = "/c/Delivery%20Insert/CD-INSERT-BRAVO-ENCORE2006.tif";
var InsertFileName = "CD-INSERT-BRAVO-ENCORE2006.tif";
var SurfaceFilePath =
"/c/Delivery%20CD%20Faces/CD-SURFACE-BRAVOENCORE2006.tif";
var SurfaceFileName = "CD-SURFACE-BRAVOENCORE2006.tif";
var ModelLayerName = Array("BRAVO","ENCORE","ENCORE+");
var CLayerName = "COMPANY";
var SLayerName = "SERIAL";
//Declare user input variables
var CompanyValue;
var SerialValue;
var i = 0;
var t = 0;
// Sets the switch for debug capabilities
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
var debug = false;
// Save User Preferrences
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
// Set Adobe Photoshop to use pixels and display no dialogs
app.preferences.rulerUnits = Units.INCHES;
app.preferences.typeUnits = TypeUnits.POINTS;
//Close all the open documents
while(app.documents.length)
{
activeDocument.close();
}
//Open the documents and assign document variables
var InsertDoc = open(File(InsertFilePath));
var InsertCLayer = InsertDoc.artLayers[CLayerName];
if (debug) { alert("Here is " + InsertDoc.name + "'s name and kind: " +
InsertCLayer.name + " , " + InsertCLayer.kind) };
var InsertSLayer = InsertDoc.artLayers[SLayerName];
if (debug) { alert("Here is " + InsertDoc.name + "'s name and kind: " +
InsertSLayer.name + " , " + InsertSLayer.kind) };
var SurfaceDoc = open(File(SurfaceFilePath));
var SurfaceCLayer = SurfaceDoc.artLayers[CLayerName];
if (debug) { alert("Here is " + SurfaceDoc.name + "'s name and kind: " +
SurfaceCLayer.name + " , " + SurfaceCLayer.kind) };
var SurfaceSLayer = SurfaceDoc.artLayers[SLayerName];
if (debug) { alert("Here is " + SurfaceDoc.name + "'s name and kind: " +
SurfaceSLayer.name + " , " + SurfaceSLayer.kind) };
//Create a user input form
var textchange = new Window('dialog');
textchange.text = "TextChange v1.0";
textchange.frameLocation = [300,300];
textchange.panel = textchange.add('panel');
textchange.panel.text = "User Input";
textchange.alignment = 'fill';
textchange.panel.model = textchange.panel.add('group');
textchange.panel.model.modelst = textchange.panel.model.add('statictext');
textchange.panel.model.modelst.text = "Model:";
textchange.panel.model.modeldrop =
textchange.panel.model.add('dropdownlist', undefined, ModelLayerName);
textchange.panel.model.modeldrop.items = ModelLayerName;
textchange.panel.model.modeldrop.preferredSize = [100,20];
//EVENT onChange modeldrop
textchange.panel.model.modeldrop.onChange = function ()
{
if (debug){ alert("Here is the length of items: " +
textchange.panel.model.modeldrop.items.length) };
for (i=0; i < textchange.panel.model.modeldrop.items.length; i++)
{
if (debug){ alert("Here is the current item: " +
textchange.panel.model.modeldrop.items.toString()) };
if (debug){ alert("Here is the selected item: " +
textchange.panel.model.modeldrop.items.selected) };
if (textchange.panel.model.modeldrop.items.selected)
{
app.activeDocument = InsertDoc
InsertDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = true;
app.activeDocument = SurfaceDoc;
SurfaceDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = true;
}
else
{
app.activeDocument = InsertDoc;
InsertDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = false;
app.activeDocument = SurfaceDoc;
SurfaceDoc.artLayers[textchange.panel.model.modeldrop.items.toString()].visible = false;
}
}
};
textchange.panel.company = textchange.panel.add('group');
textchange.panel.company.companyst =
textchange.panel.company.add('statictext');
textchange.panel.company.companyst.text = "Company:";
textchange.panel.company.companyet =
textchange.panel.company.add('edittext');
textchange.panel.company.companyet.text = "";
textchange.panel.company.companyet.preferredSize = [100,20];
textchange.panel.serial = textchange.panel.add('group');
textchange.panel.serial.serialst =
textchange.panel.serial.add('statictext');
textchange.panel.serial.serialst.text = "Serial:";
textchange.panel.serial.serialet =
textchange.panel.serial.add('edittext');
textchange.panel.serial.serialet.text = "";
textchange.panel.serial.serialet.preferredSize = [100,20];
textchange.panel.buttons = textchange.panel.add('group');
textchange.panel.buttons.okbtn = textchange.panel.buttons.add('button');
textchange.panel.buttons.okbtn.text = "OK";
textchange.panel.buttons.okbtn.properties =
{
name:"ok"
};
// EVENT onClick okbtn
textchange.panel.buttons.okbtn.onClick = function ()
{
// Gets the values from the user form
CompanyValue = textchange.panel.company.companyet.text;
if (debug) { alert("Here is the CompanyValue: " + CompanyValue) };
SerialValue = textchange.panel.serial.serialet.text;
if (debug) { alert("Here is the SerialValue: " + SerialValue) };
// Sets the textinfo content of each text artlayer of each document to
the above values
app.activeDocument = InsertDoc;
CreateTextLayer(InsertDoc, CLayerName, CompanyValue);
CreateTextLayer(InsertDoc, SLayerName, SerialValue);
app.activeDocument = SurfaceDoc;
CreateTextLayer(SurfaceDoc, CLayerName, CompanyValue);
CreateTextLayer(SurfaceDoc, SLayerName, SerialValue);
//Close and save the surface file
SurfaceDoc.close(SaveOptions.SAVECHANGES);
save(File(InsertFilePath));
textchange.close();
ReturnPref();
};
textchange.panel.buttons.cancelbtn =
textchange.panel.buttons.add('button');
textchange.panel.buttons.cancelbtn.text = "Cancel";
textchange.panel.buttons.cancelbtn.properties =
{
name:"cancel"
};
// EVENT onClick cancelbtn
textchange.panel.buttons.cancelbtn.onClick = function ()
{
textchange.hide();
textchange.close();
ReturnPref();
};
textchange.show();
/****************************************************************************************
**USER DEFINED
FUNCTIONS*****************************************************************
****************************************************************************************/
function ReturnPref ()
{
// Return preferences to normal
if (debug) { alert("Hey the function call worked!!!") };
ModelLayerName = null;
textchange = null;
InsertDoc = null;
InsertCLayer = null;
InsertSLayer = null;
SurfaceDoc = null;
SurfaceCLayer = null;
SurfaceSLayer = null;
textlayer = null;
preferences.rulerUnits = startRulerUnits;
preferences.typeUnits = startTypeUnits;
}
function CreateTextLayer( doc, LayerName, Content )
{
var docArtLayer = doc.artLayers[LayerName];
if (debug) { alert("docArtLayer.name = " + docArtLayer.name) };
if (debug) { alert("docArtLayer.textItem.kind = " +
docArtLayer.textItem.kind) };
if (debug) { alert("docArtLayer.textItem.useAutoLeading = " +
docArtLayer.textItem.useAutoLeading) };
if (debug) { alert("docArtLayer.textItem.justification = " +
docArtLayer.textItem.justification) };
var textlayer =
docArtLayer.duplicate(docArtLayer,ElementPlacement.PLACEBEFORE);
textlayer.textItem.contents = Content;
doc.artLayers[LayerName].remove();
textlayer.name = LayerName;
}