Copy link to clipboard
Copied
First, let me make it clear that I do not know Photoshop scripting. But I have found two scripts (written by someone else) that do exactly what I want if I run them one after the other.
Guide Maker.jsx
Guide Stroker.jsx
I'd prefer to run a single script, rather than two. Based on what I've found by searching, I created a new script called Grid Maker.jsx with the following contents:
$.evalFile("C:\Program Files\Adobe\Adobe Photoshop 2023\Presets\Scripts\Guide Maker.jsx");
$.evalFile("C:\Program Files\Adobe\Adobe Photoshop 2023\Presets\Scripts\Guide Stroker.jsx");
However when I execute it,
Photoshop > File -> Scripts > Grid Maker
nothing happens. What am I doing wrong?
The Windows paths to the scripts are not escaped. Change all single back-slashes \ to double back-slashes \\
Or use a single cross-platform forward-slash / instead.
P.S. Please share the links to the original scripts, just in case they are of use to another reader.
You can also just paste the two scripts together, in one script, and forget the script to eval the scripts.
Copy link to clipboard
Copied
The Windows paths to the scripts are not escaped. Change all single back-slashes \ to double back-slashes \\
Or use a single cross-platform forward-slash / instead.
P.S. Please share the links to the original scripts, just in case they are of use to another reader.
Copy link to clipboard
Copied
Thank you. Using forward slashes solved part of the problem. Now the first script runs just fine, but the second script appears to do nothing. I'm attaching the three scripts (I'm attaching them as .txt files because jsx file attachments aren't allowed).. They're short, so I hope you'll take a look and tell me what I'm doing wrong.
Copy link to clipboard
Copied
I replace the slashes as Stephen suggested and it worked fine. Your Grid Maker that you posted doesn't have the right type of slashes. It needs the double slashes.
$.evalFile("C://Program Files//Adobe//Adobe Photoshop 2023//Presets//Scripts//Guide Maker.jsx");
$.evalFile("C://Program Files//Adobe//Adobe Photoshop 2023//Presets//Scripts//Guide Stroker.jsx");
Or:
$.evalFile("C\Program Files\Adobe\Adobe Photoshop 2023\Presets\Scripts\Guide Maker.jsx");
$.evalFile("C\Program Files\Adobe\Adobe Photoshop 2023\Presets\Scripts\Guide Stroker.jsx");
Copy link to clipboard
Copied
You can also just paste the two scripts together, in one script, and forget the script to eval the scripts.
Copy link to clipboard
Copied
@Chuck Uebele Pasting the two files together works. By the way, I am using single slashes for the pathnames without any problems (no need to escape anything). I will mark your answer as correct. Thank you.
Copy link to clipboard
Copied
JavaScript uses a single forward slash. Backslash must use escape double.
Copy link to clipboard
Copied
Rather than combining these two, just try my script. It offers a lot of functionality. I made it for a friend that wanted a progressive gride for some test that he was doing for a book. It also lets you save presets for different grids.
Here is a sample of what the script does. I combined to images into the one. The bottom blue has a additive progressive gride along the width. You can change the line spacing and size. You can also include guides.
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
<javascriptresource>
<name>Grid Creator with Guides V1.3.0</name>
<about>Written by Chuck Uebele - Copyright 2014 - All rights reserved</about>
<category>GridCreator</category>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRINGd3
*/
//Use at your own risk
#target photoshop
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 1;
// debugger; // launch debugger on next line
var uiPref = new File(app.preferencesFolder +'/uebGridPref.xml');
var uiX = new XML()
var presetList = new Array()
var startNodes = new XML('<root><presets><preset presetName ="Current Default"/></presets></root>');
var gridMinHor = 30;
var gridMinVert = 30;
var gridMaxHor = 60;
var gridMaxVert = 60;
var gridWidthHor = 40;
var gridWidthVert = 40;
var gridAdvHor = 1;
var gridAdvVert = 1;
var lineWidthHor;
var lineWidthVert;
var lineMinHor = 1;
var lineMinVert = 1;
var lineMaxHor =20;
var lineMaxVert =20;
var lineAdvHor = 1;
var lineAdvVert = 1;
var lineRange;
var gridRange;
var idx;
var cR = foregroundColor.rgb.red;
var cG = foregroundColor.rgb.green;
var cB = foregroundColor.rgb.blue;
var unitArray = ['pixels','inches','cm','percent']
var gridRaster = ['Merge Grid with background color','Rasterize grid shape','Keep grid as shape layer','Make Guides Only'];
var guideList = ['No Guides','Horizontal & Vertical Guides','Horizontal Guides','Vertical Guides']
var gridTypeHorArray = ['Fixed Horizontal grid','Random Horizontal Grid','Progressive Horizontal Grid (Additive)','Progressive Horizontal Grid (Mult)'];
var gridTypeVertArray = ['Fixed Vertical grid','Random Vertical Grid','Progressive Vertical Grid (Additive)','Progressive Vertical Grid (Mult)'];
var lineTypeHorArray = ['Fixed Horizontal Line','Random Horizontal Line','Progressive Horizontal Line (Additive)','Progressive Horizontal Line (Mult)'];
var lineTypeVertArray = ['Fixed Vertical Line','Random Vertical Line','Progressive Vertical Line (Additive)','Progressive Vertical Line (Mult)'];
var presetList = new Array('Current Default');
var saveName;
var unitsAdj = 1;
var fillLayer;
var gridLayerHor;
var gridLayerVert;
var doc;
var gridScale = 1;
var lineScale = 1;
if(app.documents.length>0){
var oldPref = app.preferences.rulerUnits;
if(uiPref.exists){uiX = new XML(readXMLFile(uiPref))};
var dlg = new Window('dialog','Create Grid');
dlg.alignChildren = ['left','top'];
dlg.gridUnitsGp = dlg.add('group')
var gUnitsLst = dlg.gridUnitsGp.add('dropdownlist',undefined,unitArray);gUnitsLst.name = 'gUnitsLst';
gUnitsLst.title = 'Grid Units:'
gUnitsLst.selection = 0
dlg.gridUnitsGp.btn = dlg.gridUnitsGp.add('button',undefined,'Make Grid Vertical settings the same as Grid Horizontal settings')
dlg.gridUnitsGp.btn.onClick = function(){
setGridSame ()
}
dlg.gridGpHor = dlg.add('group');
var gHorType = dlg.gridGpHor.add('dropdownlist',undefined,gridTypeHorArray);gHorType.name = 'gHorType';
gHorType.selection = 0
dlg.gridGpHor.gMinStxt = dlg.gridGpHor.add('statictext',undefined,'Min Horizontal Grid Size');
var gHorMinEtxt = dlg.gridGpHor.add('edittext',undefined,gridMinHor);gHorMinEtxt.name = 'gHorMinEtxt';
gHorMinEtxt.size = [60,18];
gHorMinEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.gridGpHor.gMaxStxt = dlg.gridGpHor.add('statictext',undefined,'Max Horizontal Grid Size');
var gHorMaxEtxt = dlg.gridGpHor.add('edittext',undefined,gridMaxHor);gHorMaxEtxt.name = 'gHorMaxEtxt';
gHorMaxEtxt.size = [60,18];
gHorMaxEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.gridGpHor.gIntStxt = dlg.gridGpHor.add('statictext',undefined,'Interval spacing between Min and Max');
var gHorIntEtxt = dlg.gridGpHor.add('edittext',undefined,gridAdvHor);gHorIntEtxt.name = 'gHorIntEtxt';
gHorIntEtxt.size = [60,18];
gHorIntEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
if(Number(gHorType.selection) ==0){dlg.gridGpHor.gMaxStxt.visible = gHorMaxEtxt.visible = dlg.gridGpHor.gIntStxt.visible = gHorIntEtxt.visible = false}
gHorType.onChange = function(){
switch(Number(gHorType.selection)){
case 0:
dlg.gridGpHor.gMaxStxt.visible = gHorMaxEtxt.visible = dlg.gridGpHor.gIntStxt.visible = gHorIntEtxt.visible = false;
dlg.gridGpHor.gMinStxt.text = 'Horizontal Grid Size'
break;
case 1:
dlg.gridGpHor.gMaxStxt.visible = gHorMaxEtxt.visible = dlg.gridGpHor.gIntStxt.visible = gHorIntEtxt.visible = true;
dlg.gridGpHor.gMinStxt.text = 'Min Horizontal Grid Size'
dlg.gridGpHor.gMaxStxt.text = 'Max Horizontal Grid Size'
break;
case 2:
dlg.gridGpHor.gMaxStxt.visible = gHorMaxEtxt.visible = true ;
dlg.gridGpHor.gIntStxt.visible = gHorIntEtxt.visible = false;
dlg.gridGpHor.gMaxStxt.text = 'Progression Factor'
dlg.gridGpHor.gMinStxt.text = 'Min Horizontal Grid Size'
break;
case 3:
dlg.gridGpHor.gMaxStxt.visible = gHorMaxEtxt.visible = true ;
dlg.gridGpHor.gIntStxt.visible = gHorIntEtxt.visible = false;
dlg.gridGpHor.gMaxStxt.text = 'Progression Factor'
dlg.gridGpHor.gMinStxt.text = 'Min Horizontal Grid Size'
break;
}//end switch
}
//==========================================================
dlg.gridGpVert = dlg.add('group');
dlg.gridGpVert = dlg.add('group');
var gVertType = dlg.gridGpVert.add('dropdownlist',undefined,gridTypeVertArray);gVertType.name = 'gVertType';
gVertType.selection = 0
dlg.gridGpVert.gMinStxt = dlg.gridGpVert.add('statictext',undefined,'Min Vertical Grid Size');
var gVertMinEtxt = dlg.gridGpVert.add('edittext',undefined,gridMinVert);gVertMinEtxt.name = 'gVertMinEtxt';
gVertMinEtxt.size = [60,18];
gVertMinEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.gridGpVert.gMaxStxt = dlg.gridGpVert.add('statictext',undefined,'Max Vertical Grid Size');
var gVertMaxEtxt = dlg.gridGpVert.add('edittext',undefined,gridMaxVert);gVertMaxEtxt.name='gVertMaxEtxt';
gVertMaxEtxt.size = [60,18];
gVertMaxEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.gridGpVert.gIntStxt = dlg.gridGpVert.add('statictext',undefined,'Interval spacing between Min and Max');
var gVertIntEtxt = dlg.gridGpVert.add('edittext',undefined,gridAdvVert);gVertIntEtxt.name = 'gVertIntEtxt';
gVertIntEtxt.size = [60,18];
gVertIntEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
if(Number(gVertType.selection)==0){dlg.gridGpVert.gMaxStxt.visible = gVertMaxEtxt.visible = dlg.gridGpVert.gIntStxt.visible = gVertIntEtxt.visible = false}
gVertType.onChange = function(){
switch(Number(gVertType.selection)){
case 0:
dlg.gridGpVert.gMaxStxt.visible = gVertMaxEtxt.visible = dlg.gridGpVert.gIntStxt.visible = gVertIntEtxt.visible = false;
dlg.gridGpVert.gMinStxt.text = 'Vertical Grid Size'
break;
case 1:
dlg.gridGpVert.gMaxStxt.visible = gVertMaxEtxt.visible = dlg.gridGpVert.gIntStxt.visible = gVertIntEtxt.visible = true;
dlg.gridGpVert.gMinStxt.text = 'Min Vertical Grid Size'
dlg.gridGpVert.gMaxStxt.text = 'Max Vertical Grid Size'
break;
case 2:
dlg.gridGpVert.gMaxStxt.visible = gVertMaxEtxt.visible = true ;
dlg.gridGpVert.gIntStxt.visible = gVertIntEtxt.visible = false;
dlg.gridGpVert.gMaxStxt.text = 'Progression Factor'
dlg.gridGpVert.gMinStxt.text = 'Min Vertical Grid Size'
break;
case 3:
dlg.gridGpVert.gMaxStxt.visible = gVertMaxEtxt.visible = true ;
dlg.gridGpVert.gIntStxt.visible = gVertIntEtxt.visible = false;
dlg.gridGpVert.gMaxStxt.text = 'Progression Factor'
dlg.gridGpVert.gMinStxt.text = 'Min Vertical Grid Size'
break;
}//end switch
}
//=================================================================================
dlg.lineUnitsGp = dlg.add('group')
var lUnitsLst = dlg.lineUnitsGp.add('dropdownlist',undefined,unitArray);lUnitsLst.name = 'lUnitsLst';
lUnitsLst.title = 'Line Units:'
lUnitsLst.selection = 0
dlg.lineUnitsGp.btn = dlg.lineUnitsGp.add('button',undefined,'Make Line Vertical settings the same as Line Horizontal settings')
dlg.lineUnitsGp.btn.onClick = function(){
setLineSame ()
}
dlg.lineGpHor = dlg.add('group');
var lHorType = dlg.lineGpHor.add('dropdownlist',undefined,lineTypeHorArray);lHorType.name = 'lHorType';
lHorType.selection = 0
dlg.lineGpHor.gMinStxt = dlg.lineGpHor.add('statictext',undefined,'Min Horizontal Line Size');
var lHorMinEtxt = dlg.lineGpHor.add('edittext',undefined,lineMinHor);lHorMinEtxt.name = 'lHorMinEtxt';
lHorMinEtxt.size = [60,18];
lHorMinEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.lineGpHor.gMaxStxt = dlg.lineGpHor.add('statictext',undefined,'Max Horizontal Line Size');
var lHorMaxEtxt = dlg.lineGpHor.add('edittext',undefined,lineMaxHor);lHorMaxEtxt.name = 'lHorMaxEtxt';
lHorMaxEtxt.size = [60,18];
lHorMaxEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.lineGpHor.gIntStxt = dlg.lineGpHor.add('statictext',undefined,'Interval spacing between Min and Max');
var lHorIntEtxt = dlg.lineGpHor.add('edittext',undefined,lineAdvHor);lHorIntEtxt.name = 'lHorIntEtxt';
lHorIntEtxt.size = [60,18];
lHorIntEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
if(Number(lHorType.selection) ==0){dlg.lineGpHor.gMaxStxt.visible = lHorMaxEtxt.visible = dlg.lineGpHor.gIntStxt.visible = lHorIntEtxt.visible = false}
lHorType.onChange = function(){
switch(Number(lHorType.selection)){
case 0:
dlg.lineGpHor.gMaxStxt.visible = lHorMaxEtxt.visible = dlg.lineGpHor.gIntStxt.visible = lHorIntEtxt.visible = false;
dlg.lineGpHor.gMinStxt.text = 'Horizontal Line Size'
break;
case 1:
dlg.lineGpHor.gMaxStxt.visible = lHorMaxEtxt.visible = dlg.lineGpHor.gIntStxt.visible = lHorIntEtxt.visible = true;
dlg.lineGpHor.gMinStxt.text = 'Min Horizontal Line Size'
dlg.lineGpHor.gMaxStxt.text = 'Max Horizontal Line Size'
break;
case 2:
dlg.lineGpHor.gMaxStxt.visible = lHorMaxEtxt.visible = true ;
dlg.lineGpHor.gIntStxt.visible = lHorIntEtxt.visible = false;
dlg.lineGpHor.gMaxStxt.text = 'Progression Factor'
dlg.lineGpHor.gMinStxt.text = 'Min Horizontal Line Size'
break;
case 3:
dlg.lineGpHor.gMaxStxt.visible = lHorMaxEtxt.visible = true ;
dlg.lineGpHor.gIntStxt.visible = lHorIntEtxt.visible = false;
dlg.lineGpHor.gMaxStxt.text = 'Progression Factor'
dlg.lineGpHor.gMinStxt.text = 'Min Horizontal Line Size'
break;
}//end switch
}
//=======================================================
dlg.lineGpVert = dlg.add('group');
var lVertType = dlg.lineGpVert.add('dropdownlist',undefined,lineTypeVertArray);lVertType.name = 'lVertType';
lVertType.selection = 0
dlg.lineGpVert.gMinStxt = dlg.lineGpVert.add('statictext',undefined,'Min Vertical Line Size');
var lVertMinEtxt = dlg.lineGpVert.add('edittext',undefined,lineMinVert);lVertMinEtxt.name = 'lVertMinEtxt';
lVertMinEtxt.size = [60,18];
lVertMinEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.lineGpVert.gMaxStxt = dlg.lineGpVert.add('statictext',undefined,'Max Vertical Line Size');
var lVertMaxEtxt = dlg.lineGpVert.add('edittext',undefined,lineMaxVert);lVertMaxEtxt.name = 'lVertMaxEtxt'
lVertMaxEtxt.size = [60,18];
lVertMaxEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
dlg.lineGpVert.gIntStxt = dlg.lineGpVert.add('statictext',undefined,'Interval spacing between Min and Max');
var lVertIntEtxt = dlg.lineGpVert.add('edittext',undefined,lineAdvVert);lVertIntEtxt.name = 'lVertIntEtxt';
lVertIntEtxt.size = [60,18];
lVertIntEtxt.onChange = function(){textToNum(.0001,3000,this,'float')}
if(Number(lVertType.selection) ==0){dlg.lineGpVert.gMaxStxt.visible = lVertMaxEtxt.visible = dlg.lineGpVert.gIntStxt.visible = lVertIntEtxt.visible = false}
lVertType.onChange = function(){
switch(Number(lVertType.selection)){
case 0:
dlg.lineGpVert.gMaxStxt.visible = lVertMaxEtxt.visible = dlg.lineGpVert.gIntStxt.visible = lVertIntEtxt.visible = false;
dlg.lineGpVert.gMinStxt.text = 'Vertical Line Size'
break;
case 1:
dlg.lineGpVert.gMaxStxt.visible = lVertMaxEtxt.visible = dlg.lineGpVert.gIntStxt.visible = lVertIntEtxt.visible = true;
dlg.lineGpVert.gMinStxt.text = 'Min Vertical Line Size'
dlg.lineGpVert.gMaxStxt.text = 'Max Vertical Line Size'
break;
case 2:
dlg.lineGpVert.gMaxStxt.visible = lVertMaxEtxt.visible = true ;
dlg.lineGpVert.gIntStxt.visible = lVertIntEtxt.visible = false;
dlg.lineGpVert.gMaxStxt.text = 'Progression Factor'
dlg.lineGpVert.gMinStxt.text = 'Min Vertical Line Size'
break;
case 3:
dlg.lineGpVert.gMaxStxt.visible = lVertMaxEtxt.visible = true ;
dlg.lineGpVert.gIntStxt.visible = lVertIntEtxt.visible = false;
dlg.lineGpVert.gMaxStxt.text = 'Progression Factor'
dlg.lineGpVert.gMinStxt.text = 'Min Vertical Line Size'
break;
}//end switch
}
//===========================================================
var flatLst = dlg.add('dropdownlist',undefined,gridRaster);flatLst.name = 'flatLst';
flatLst.selection = 0
dlg.guideGp = dlg.add('group');
var guides = dlg.guideGp.add('dropdownlist',undefined,guideList);guides.name = 'guides';
guides.selection = 0;
var guideCenter = dlg.guideGp.add('radiobutton',undefined,'Guides centered on lines');guideCenter.name = 'guideCenter';
guideCenter.value = true;
var guideEdge = dlg.guideGp.add('radiobutton',undefined,'Guides on edges of lines');guideEdge.name = 'guideEdge';
dlg.preGp = dlg.add('group');
dlg.preGp.preLst = dlg.preGp.add('dropdownlist',undefined,presetList);
dlg.preGp.preLst.selection = 0;
dlg.preGp.preLst.size = [350,20];
dlg.preGp.save = dlg.preGp.add('button',undefined,'Save Preset');
dlg.preGp.del = dlg.preGp.add('button',undefined,'Delete Current Preset');
dlg.preGp.preLst.onChange = function(){
if(uiX.children().length()>0){//loads presets into UI
setUIvar(uiX,parseInt(dlg.preGp.preLst.selection),dlg);
};
};//end list function
dlg.preGp.save.onClick = function(){
saveName = prompt ('Enter a name for the preset', '', 'Preset Save')
if(saveName){storePrefs('a')}
dlg.preGp.preLst.selection = dlg.preGp.preLst.items.length -1
}
dlg.preGp.del .onClick = function(){
if(!parseInt(dlg.preGp.preLst.selection)){alert("You can't delete the current default preset")}
else{
var delPre = confirm ('Do you want to delete the preset "' + dlg.preGp.preLst.selection.text +'"?', 'Yes', 'Delete Preset')
if(delPre){
delete uiX.presets.preset[parseInt(dlg.preGp.preLst.selection)];
setPresetList();
writeXMLFile(uiPref,uiX);
dlg.preGp.preLst.selection = 0
}//end if--
};//end else
}
//============================================
dlg.btnGp = dlg.add('group')
dlg.btnGp.ok = dlg.btnGp.add('button',undefined,'Okay');
dlg.btnGp.cancel = dlg.btnGp.add('button',undefined,'Cancel');
dlg.btnGp.ok.onClick = function(){
if(isNaN (Number(gHorMinEtxt.text))&&isNaN (Number(gHorMaxEtxt.text))&&isNaN (Number(gHorIntEtxt.text))&&isNaN (Number(lHorMinEtxt.text))&&isNaN (Number(lHorMaxEtxt.text))&&isNaN (Number(lHorIntEtxt.text))){
}
else{
dlg.close()
storePrefs('r')
run()
}
}
dlg.btnGp.cancel.onClick = function(){
dlg.close()}
if(uiX.children().length()>0){//loads presets into UI
setPresetList()
setUIvar(uiX,0,dlg)
dlg.preGp.preLst.selection = 0
};
dlg.show()
};//end if to see if there are open docs
else{alert('There are no open files')}
function run(){
app.preferences.rulerUnits = Units.PIXELS;
doc = activeDocument
switch(Number(gUnitsLst.selection)){
case 0:
gridScale = 1
break;
case 1:
gridScale = doc.resolution
break;
case 2:
gridScale = doc.resolution/2.54
break;
case 3:
gridScale = doc.width/100
break;
}
switch(Number(lUnitsLst.selection)){
case 0:
lineScale = 1
break;
case 1:
lineScale = doc.resolution
break;
case 2:
lineScale = doc.resolution/2.54
break;
case 3:
lineScale = doc.width/100
break;
}
gridMinHor = Number(gHorMinEtxt.text)*gridScale;
gridMaxHor = Number(gHorMaxEtxt.text)*gridScale;
gridAdvHor = Number(gHorIntEtxt.text)*gridScale;
gridMinVert = Number(gVertMinEtxt.text)*gridScale;
gridMaxVert = Number(gVertMaxEtxt.text)*gridScale;
gridAdvVert = Number(gVertIntEtxt.text)*gridScale;
lineMinHor = Number(lHorMinEtxt.text)*lineScale;
lineMaxHor = Number(lHorMaxEtxt.text)*lineScale;
lineAdvHor = Number(lHorIntEtxt.text)*lineScale;
lineMinVert = Number(lVertMinEtxt.text)*lineScale;
lineMaxVert = Number(lVertMaxEtxt.text)*lineScale;
lineAdvVert = Number(lVertIntEtxt.text)*lineScale;
if(Number(flatLst.selection) == 0){mergeBG ()};
//gHorType = fixed
if(gHorType.selection==0){gridWidthHor = gridMinHor};
if(gVertType.selection==0){gridWidthVert = gridMinVert};
if(lHorType.selection==0 || lHorType.selection==2 || lHorType.selection==3){lineWidthHor = lineMinHor};
if(lVertType.selection==0 || lVertType.selection==2 || lVertType.selection==3){lineWidthVert = lineMinVert};
//gHorType = random
if(lHorType.selection ==1){lineRange = fillRange (lineMinHor,lineMaxHor,lineAdvHor)}
if(lVertType.selection ==1){lineRange = fillRange (lineMinVert,lineMaxVert,lineAdvVert)}
if(gHorType.selection ==1){gridRange = fillRange (gridMinHor,gridMaxHor,gridAdvHor)}
if(gVertType.selection ==1){gridRange = fillRange (gridMinVert,gridMaxVert,gridAdvVert)}
for(var i=0;i<doc.width;i+=gridWidthHor){
if(Number(lHorType.selection) ==1){
idx = Math.floor(Math.random()*lineRange.length)
lineWidthHor = lineRange[idx]
lineArrayAdj (idx)
}
if(Number(gHorType.selection) ==1){
idx = Math.floor(Math.random()*gridRange.length)
gridWidthHor = gridRange[idx]
gridArrayAdj (idx)
}
if(i==0){
if(Number(flatLst.selection)!=3){
makeFirstLine (i, 0, lineWidthHor, doc.height);
gridLayerHor = doc.activeLayer;
}
if(Number(guides.selection)==1||Number(guides.selection)==3){
if(guideCenter.value){vertG (i+lineWidthHor/2)}
else{
vertG (i)
vertG (i+lineWidthHor)
}
}//end if for making guides
}//end if for first line i==0
else{
if(Number(flatLst.selection)!=3){
makeLine (i, 0, i+lineWidthHor, doc.height);
}
if(Number(guides.selection)==1||Number(guides.selection)==3){
if(guideCenter.value){vertG (i+lineWidthHor/2)}
else{
vertG (i)
vertG (i+ lineWidthHor)
}
}//end if for making guides
};//end else for making second lines
if(Number(gHorType.selection ==2)){gridWidthHor += gridMaxHor}
if(Number(gHorType.selection ==3)){gridWidthHor *= gridMaxHor}
if(Number(lHorType.selection ==2)){lineWidthHor += lineMaxHor}
if(Number(lHorType.selection ==3)){lineWidthHor *= lineMaxHor}
}//end for loop width
if(Number(gUnitsLst.selection==3)){gridScale = doc.height/100}
if(Number(lUnitsLst.selection==3)){lineScale = doc.height/100}
for(var i=0;i<doc.height;i+=gridWidthVert){
if(Number(lHorType.selection ==1)){
idx = Math.floor(Math.random()*lineRange.length)
lineWidthVert = lineRange[idx]
lineArrayAdj (idx)
}
if(Number(gHorType.selection ==1)){
idx = Math.floor(Math.random()*gridRange.length)
gridWidthVert = gridRange[idx]
gridArrayAdj (idx)
}
if(i==0){
if(Number(flatLst.selection)!=3){
makeFirstLine (0, i, doc.width, i+lineWidthVert)
gridLayerVert = doc.activeLayer
}
if(Number(guides.selection)==1||Number(guides.selection)==2){
if(guideCenter.value){horG (i+lineWidthVert/2)}
else{
horG (i)
horG (i+lineWidthVert)
}
}//end if for making guides
}//end if for first line
else{
if(Number(flatLst.selection)!=3){
makeLine (0, i, doc.width, i+lineWidthVert);
}
if(Number(guides.selection)==1||Number(guides.selection)==2){
if(guideCenter.value){horG (i+lineWidthVert/2)}
else{
horG (i)
horG (i+lineWidthVert)
}
}//end if for making guides
} ;//end else for making second lines
if(Number(gVertType.selection ==2)){gridWidthVert += gridMaxVert}
if(Number(gVertType.selection ==3)){gridWidthVert *= gridMaxVert}
if(Number(lVertType.selection ==2)){lineWidthVert += lineMaxVert}
if(Number(lVertType.selection ==3)){lineWidthVert *= lineMaxVert}
}//end for loop height
switch(Number(flatLst.selection)){
case 0:
doc.activeLayer.rasterize (RasterizeType.SHAPE);
doc.activeLayer = gridLayerHor
doc.activeLayer.rasterize (RasterizeType.SHAPE)
doc.activeLayer.merge()
doc.activeLayer = gridLayerVert
doc.activeLayer.merge()
break;
case 1:
doc.activeLayer.rasterize (RasterizeType.SHAPE);
doc.activeLayer = gridLayerHor
doc.activeLayer.rasterize (RasterizeType.SHAPE)
break;
}
app.preferences.rulerUnits = oldPref
};//end function run
function setGridSame(){
//change this
gVertType.selection = Number(gHorType.selection)
gVertMinEtxt.text = gHorMinEtxt.text
gVertMaxEtxt.text = gHorMaxEtxt.text
gVertIntEtxt.text = gHorIntEtxt.text
}
function setLineSame(){
lVertType.selection = Number(lHorType.selection)
lVertMinEtxt.text = lHorMinEtxt.text
lVertMaxEtxt.text = lHorMaxEtxt.text
lVertIntEtxt.text = lHorIntEtxt.text
}
function lineArrayAdj(x){
if(lineRange.length==1){lineRange = fillRange(lineMinHor,lineMaxHor,lineAdvHor)}
else{var r = lineRange.splice(x,1)};
}
function gridArrayAdj(x){
if(gridRange.length==1){gridRange = fillRange(gridMinHor,gridMaxHor,gridAdvHor)}
else{var r = gridRange.splice(x,1)};
}
function fillRange(min,max,adv){
a = new Array()
for (var j=min;j<max+1;j+=adv){
a.push(j)
}
return a
}
function makeFirstLine(rL,rT,rR,rB){
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc15 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref5.putClass( idcontentLayer );
desc15.putReference( idnull, ref5 );
var idUsng = charIDToTypeID( "Usng" );
var desc16 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc17 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc18 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc18.putDouble( idRd, cR );
var idGrn = charIDToTypeID( "Grn " );
desc18.putDouble( idGrn, cG );
var idBl = charIDToTypeID( "Bl " );
desc18.putDouble( idBl, cB );
var idRGBC = charIDToTypeID( "RGBC" );
desc17.putObject( idClr, idRGBC, desc18 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc16.putObject( idType, idsolidColorLayer, desc17 );
var idShp = charIDToTypeID( "Shp " );
var desc19 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc19.putUnitDouble( idTop, idPxl, rT );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc19.putUnitDouble( idLeft, idPxl, rL );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc19.putUnitDouble( idBtom, idPxl, rB );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc19.putUnitDouble( idRght, idPxl, rR );
var idRctn = charIDToTypeID( "Rctn" );
desc16.putObject( idShp, idRctn, desc19 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc20 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc20.putInteger( idstrokeStyleVersion, 2 );
var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
desc20.putBoolean( idstrokeEnabled, false );
var idfillEnabled = stringIDToTypeID( "fillEnabled" );
desc20.putBoolean( idfillEnabled, true );
var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
var idPnt = charIDToTypeID( "#Pnt" );
desc20.putUnitDouble( idstrokeStyleLineWidth, idPnt, 3.000000 );
var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
var idPnt = charIDToTypeID( "#Pnt" );
desc20.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );
var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
desc20.putDouble( idstrokeStyleMiterLimit, 100.000000 );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );
desc20.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
desc20.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" );
desc20.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside );
var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
desc20.putBoolean( idstrokeStyleScaleLock, false );
var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
desc20.putBoolean( idstrokeStyleStrokeAdjust, false );
var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
var list2 = new ActionList();
desc20.putList( idstrokeStyleLineDashSet, list2 );
var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc20.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );
var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
var idPrc = charIDToTypeID( "#Prc" );
desc20.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );
var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
var desc21 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc22 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc22.putDouble( idRd, 0.000017 );
var idGrn = charIDToTypeID( "Grn " );
desc22.putDouble( idGrn, 0.000017 );
var idBl = charIDToTypeID( "Bl " );
desc22.putDouble( idBl, 0.000017 );
var idRGBC = charIDToTypeID( "RGBC" );
desc21.putObject( idClr, idRGBC, desc22 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc20.putObject( idstrokeStyleContent, idsolidColorLayer, desc21 );
var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
desc20.putDouble( idstrokeStyleResolution, 72.000000 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
desc16.putObject( idstrokeStyle, idstrokeStyle, desc20 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc15.putObject( idUsng, idcontentLayer, desc16 );
executeAction( idMk, desc15, DialogModes.NO );
};//end function make first line
function makeLine(rL,rT,rR,rB){
// =======================================================
var idAddT = charIDToTypeID( "AddT" );
var desc23 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref6.putEnumerated( idPath, idOrdn, idTrgt );
desc23.putReference( idnull, ref6 );
var idT = charIDToTypeID( "T " );
var desc24 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc24.putUnitDouble( idTop, idPxl, rT );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc24.putUnitDouble( idLeft, idPxl, rL );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc24.putUnitDouble( idBtom, idPxl, rB );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc24.putUnitDouble( idRght, idPxl, rR );
var idRctn = charIDToTypeID( "Rctn" );
desc23.putObject( idT, idRctn, desc24 );
executeAction( idAddT, desc23, DialogModes.NO );
};//end function makeLine
function textToNum(sMin,sMax,e,par){
var sHold = sMin;
if(par == 'int'){
if(isNaN(parseInt(e.text))){
alert('"' + e.text + '" is not a number\nEnter a value between ' + sMin + '-' + sMax );
e.text = sMin};
else{sHold = parseInt(e.text)
if(sHold < sMin){
rangeAlert();
sHold = sMin;
};
if(sHold > sMax){
rangeAlert();
sHold = sMax;
};
e.text = sHold;
}; //end else
};//end if par
else{
if(isNaN(parseFloat(e.text))){
alert('"' + e.text + '" is not a number\nEnter a value between ' + sMin + '-' + sMax );
e.text = sMin};
else{sHold = parseFloat(e.text)
if(sHold < sMin){
rangeAlert();
sHold = sMin;
};
if(sHold > sMax){
rangeAlert();
sHold = sMax;
};
e.text = sHold;
}; //end else
};//end else par
function rangeAlert(){alert('Number range must be between ' + sMin + '-' + sMax)};
};//end function textToNum
function mergeBG(){
fillLayer = doc.artLayers.add()
doc.selection.selectAll()
doc.selection.fill(backgroundColor)
doc.selection.deselect()
}
function readXMLFile(file) {
if (!file.exists) {
alert( "Cannot find file: " + deodeURI(file.absoluteURI));
}
else{
file.encoding = "UTF8";
file.lineFeed = "unix";
file.open("r", "TEXT", "????");
var str = file.read();
file.close();
return new XML(str);
};
};
function writeXMLFile(file, xml) {
file.encoding = "UTF8";
file.open("w", "TEXT", "????");
//unicode signature, this is UTF16 but will convert to UTF8 "EF BB BF"
file.write("\uFEFF");
file.lineFeed = "unix";
if (!(xml instanceof XML)) {
for(var g=0;g<scriptArray.length;g++){
try{
file.writeln (scriptArray[g].toString())
}
catch(e){$.writeln (e)}
};//end for loop
}
else{file.write(xml.toXMLString())};
file.close();
};
function storePrefs(meth){
var tempXML
if(meth == 'r'){
tempXML = new XML(startNodes);
setXML(tempXML,0,dlg);
if(uiX.children().length()==0){
uiX = new XML(tempXML);
}
else{
uiX.presets.preset[0] = XML(tempXML.presets.preset[0])
};
}//end if for method
else{
tempXML = new XML('<root><presets><preset presetName ="' + saveName + '"/></presets></root>');
setXML(tempXML,0,dlg);
uiX.presets.appendChild (XML(tempXML.presets.preset[0]))
setPresetList()
};//end else for appending xml
writeXMLFile(uiPref,uiX);
};//end function storePrefs
/////////////////////////////////////////////////////////////////////////////////////////////////////
//function loops through the ui object and if the control items have been assigned a name it stores the name and the value to an XML file.
function setXML(x,n,d){//x = xml file, n = starting node, d = dialog.
for(var i = 0;i<d.children.length;i++){
if(d.children[i].type == 'panel' || d.children[i].type == 'group' || d.children[i].type == 'tabbedpanel' || d.children[i].type == 'tab'){setXML(x,n,d.children[i])}//loops though UI and restarts function if it comes to a container that might have more children
else{
if(d.children[i].name){//check to make sure the control has a name assigned so that it only records those with name.
switch(d.children[i].type){
case 'radiobutton':
x.presets.child(n).appendChild(XML('<' + d.children[i].name +' type="' + d.children[i].type + '">' + d.children[i].value + '</' + d.children[i].name + '>'));
break;
case 'checkbox':
x.presets.child(n).appendChild(XML('<' + d.children[i].name +' type="' + d.children[i].type + '">' + d.children[i].value + '</' + d.children[i].name + '>'));
break;
case 'slider':
x.presets.child(n).appendChild(XML('<' + d.children[i].name +' type="' + d.children[i].type + '">' + d.children[i].value + '</' + d.children[i].name + '>'));
break;
case 'edittext':
x.presets.child(n).appendChild(XML('<' + d.children[i].name +' type="' + d.children[i].type + '"><![CDATA[' + d.children[i].text + ']]\></' + d.children[i].name + '>'));
break;
case 'statictext':
if(dvar.useRefFile.value){
x.presets.child(n).appendChild(XML('<' + d.children[i].name +' type="' + d.children[i].type + '"><![CDATA[' + refFile.fsName + ']]\></' + d.children[i].name + '>'));
}//end if
break;
case 'dropdownlist':
if(d.children[i].selection){varHold = d.children[i].selection.text}
else{varHold = 'null'};
x.presets.child(n).appendChild(XML('<' + d.children[i].name +' selecIndex="' + d.children[i].selection + '" type="' + d.children[i].type + '"><![CDATA[' + varHold + ']]\></' + d.children[i].name + '>'));
break;
};//end switch
}//end if for child having name
};//end else
};//end for loop
}//end function setXML
////////////////////////////////////////////////////////////////////////////////////////////////
//function loops through the ui object and if a control item has been assigned a name uses that name to look up the preset value in the XML.
function setUIvar(x,n,d){//x= xml file; n = node number (0 is default node), d = UI dialog
var currentXMLVal;//used to store values from XML file. When this value is assigned, it checks to see if value from XML exist
var noMatch = false
for(var i = 0;i<d.children.length;i++){
noMatch = false;
if(d.children[i].type == 'panel' || d.children[i].type == 'group' || d.children[i].type == 'tab' || d.children[i].type == 'tabbedpanel'){setUIvar(x,n,d.children[i])};//reruns function if child is container and not control item.
else{
if(d.children[i].name){//Checks to see if child has a name assigned so only will reset those control items that have a name will be stored.
try{
//Assigns all variables from presets node. The "n" tells which preset to select. "0" is always the default preset (last saved).
currentXMLVal = x.presets.preset[n].child(d.children[i].name);
if(currentXMLVal == 'null'){currentXMLVal = null};
}//end try
//catch assigns 'no_good' to current XMLVal so that if there is no value in the XML file, it will not try to assign a bad value to the UI controls.
catch(e){currentXMLVal = 'no_good'};//end catch
//switch makes sure proper type of value is reassigned back to UI controls.
if(x.presets.preset[n].child(d.children[i].name).length() > 0 || d.children[i].type == 'button'){
switch(d.children[i].type){
case 'radiobutton':
d.children[i].value = returnBoolean(currentXMLVal);
break;
case 'checkbox':
d.children[i].value = returnBoolean(currentXMLVal);
if( d.children[i].name == 'useRefFile' && dvar.useRefFile.value){
refFile = new File(x.presets.preset[n].child('refName'));
if(refFile.exists){
refXML = new XML(readXMLFile(refFile));
refSame ()
}//end if for refFile.exists
}//end if for detecting if refFile was set in preferences
break;
case 'edittext':
d.children[i].text = currentXMLVal;
break;
case 'slider':
d.children[i].value = parseFloat(currentXMLVal);
break;
case 'dropdownlist':
varHold = false;
if(x.presets.preset[n].child(d.children[i].name).@selecIndex.toString() == 'null'){d.children[i].selection = null}
else{d.children[i].selection = parseInt(x.presets.preset[n].child(d.children[i].name).@selecIndex)};
break;
};//end switch else
};//end if to see if there is a good value from the XML
};//end if for UI control having name
};//end else for if child is container or control
};//end for loop
};//end function setUIvar
//function returns a boolean value. Values stored in XML are returned as strings, so they need to be converted back to boolean values.
function returnBoolean(b){
if(b == 'true'){return true}
else{return false}
};
//Function resets the values of the preset list when items are added or deleted.
function setPresetList(){
presetList = new Array();
dlg.preGp.preLst.removeAll();
for(var i=0;i<uiX.presets.children().length();i++){dlg.preGp.preLst.add('item',uiX.presets.children()[i].@presetName)}
};//end function setPresetList
function vertG(position){
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc3 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc4 = new ActionDescriptor();
var idPstn = charIDToTypeID( "Pstn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc4.putUnitDouble( idPstn, idPxl, position );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idVrtc = charIDToTypeID( "Vrtc" );
desc4.putEnumerated( idOrnt, idOrnt, idVrtc );
var idGd = charIDToTypeID( "Gd " );
desc3.putObject( idNw, idGd, desc4 );
executeAction( idMk, desc3, DialogModes.NO );
};//end function vertG
function horG(position){
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc5 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc6 = new ActionDescriptor();
var idPstn = charIDToTypeID( "Pstn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idPstn, idPxl, position );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc6.putEnumerated( idOrnt, idOrnt, idHrzn );
var idGd = charIDToTypeID( "Gd " );
desc5.putObject( idNw, idGd, desc6 );
executeAction( idMk, desc5, DialogModes.NO );
};//end function horG
Copy link to clipboard
Copied
Thank you for your generous offer. But the two simple scripts I'm trying to combine have exactly the functionality I need, and I would prefer to work with them if possible. I'm also interested in finding out why the combined script doesn't work.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now