Hello, I thought I'd start off with a background on what my goal is. I'm making a sculpture out of a book by folding each individual page, like this:
Creating words instead of geometric patterns are harder and take some planning in Photoshop. I create my word with the type tool and each single pixel vertical column of the word represents a page in the book. Here's an example of a letter done in that method:
Now in order to find the two measurements at which to make a single fold, I have to measure the distance from the first black pixel from the top, multiply it by 12, write it down, and do the same for the last black pixel in the column and repeat for every column in the image. That's 800 measurements and and 800 calculations I have to do before I can start folding. I thought I could possibly write a script to do all this and output to a csv file possibly, or at the least, make a text layer and store it in there. I don't have any experience writing Photoshop scripts, but I have taken three years of computer programming in high school. I wrote out in pseudo code how I think it would work, but I need a lot of help if someone is willing. I have two nested for loops to run through each pixel in a column to test if it's the first and last black pixel, and to store those locations in two arrays, and then cycle to the next column over.
Code: Select allvar doc = app.activeDocument;
var documentWidth = doc.width;
var documentHeight = doc.height;
var black = false; //boolean variable
for(w = 0; w <= documentWidth; ++w)
{
for(h = 0; h <= documentHeight; ++h)
{
if((pixel at documentWidth, documentHeight) == colorBlack) && !(black)
then store the height value in topArray[documentWidth]
and set black = true;
else if ((pixel at documentWidth, documentHeight) == colorWhite) && !(black)
then store the height value in bottomArray[documentWidth]
and set black = false;
}
}
Output array data (preferrably in csv text format, or maybe just an image file with text on it) in this or similar format
1 topArray[0] / 12 bottomArray[0] / 12
2 topArray[1] / 12 bottomArray[1] / 12
3 topArray[2] / 12 bottomArray[2] / 12
4 topArray[3] / 12 bottomArray[3] / 12
5 topArray[4] / 12 bottomArray[4] / 12
6 topArray[5] / 12 bottomArray[5] / 12
7 topArray[6] / 12 bottomArray[6] / 12
Thanks a ton!
[MOD EDIT] Details about this technique can be found at http://www.faitmain-faitcoeur.fr/photos ... -ecriture/ ... -ecriture/
Creating a CS5 script from scratch
-
david
Creating a CS5 script from scratch
Here's what I came up with. This assumes an RGB document. Wasn't quite sure what you wanted with the multiple of 12, but I'm sure you can figure that out. (your pseudo code used the divide symbol)
Code: Select allvar originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc=activeDocument;
var docWidth= doc.width;
var list = new File("~/fold_list.csv"); //~ Points to your OS account user folder
list.open('W');
for (var i=0;i<docWidth;i++){
selectColumn(i);
try{
var b = doc.selection.bounds;
list.writeln (Number(b[1])+","+Number(b[3]));
}catch(e){
list.writeln ("0,0");
}
}
list.close()
app.preferences.rulerUnits = originalRulerUnits
alert ("All done!")
///I used the ScriptListener plugin for "single column marquee" and "subtract RGB channel from selection")
function selectColumn(col){
var idsetd = charIDToTypeID( "setd" );
var desc107 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref68 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref68.putProperty( idChnl, idfsel );
desc107.putReference( idnull, ref68 );
var idT = charIDToTypeID( "T " );
var desc108 = new ActionDescriptor();
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc108.putUnitDouble( idLeft, idPxl, col );
var idSngc = charIDToTypeID( "Sngc" );
desc107.putObject( idT, idSngc, desc108 );
executeAction( idsetd, desc107, DialogModes.NO );
// =======================================================
var idSbtr = charIDToTypeID( "Sbtr" );
var desc109 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref69 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idRGB = charIDToTypeID( "RGB " );
ref69.putEnumerated( idChnl, idChnl, idRGB );
desc109.putReference( idnull, ref69 );
var idFrom = charIDToTypeID( "From" );
var ref70 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref70.putProperty( idChnl, idfsel );
desc109.putReference( idFrom, ref70 );
executeAction( idSbtr, desc109, DialogModes.NO );
}
Code: Select allvar originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc=activeDocument;
var docWidth= doc.width;
var list = new File("~/fold_list.csv"); //~ Points to your OS account user folder
list.open('W');
for (var i=0;i<docWidth;i++){
selectColumn(i);
try{
var b = doc.selection.bounds;
list.writeln (Number(b[1])+","+Number(b[3]));
}catch(e){
list.writeln ("0,0");
}
}
list.close()
app.preferences.rulerUnits = originalRulerUnits
alert ("All done!")
///I used the ScriptListener plugin for "single column marquee" and "subtract RGB channel from selection")
function selectColumn(col){
var idsetd = charIDToTypeID( "setd" );
var desc107 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref68 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref68.putProperty( idChnl, idfsel );
desc107.putReference( idnull, ref68 );
var idT = charIDToTypeID( "T " );
var desc108 = new ActionDescriptor();
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc108.putUnitDouble( idLeft, idPxl, col );
var idSngc = charIDToTypeID( "Sngc" );
desc107.putObject( idT, idSngc, desc108 );
executeAction( idsetd, desc107, DialogModes.NO );
// =======================================================
var idSbtr = charIDToTypeID( "Sbtr" );
var desc109 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref69 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idRGB = charIDToTypeID( "RGB " );
ref69.putEnumerated( idChnl, idChnl, idRGB );
desc109.putReference( idnull, ref69 );
var idFrom = charIDToTypeID( "From" );
var ref70 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref70.putProperty( idChnl, idfsel );
desc109.putReference( idFrom, ref70 );
executeAction( idSbtr, desc109, DialogModes.NO );
}
-
Fireater989
Creating a CS5 script from scratch
Thank you so much! As far as I can tell with a quick test document this works perfectly. The dividing by 12 has to do with the translating of pixels to the height of the book. Each horizontal pixel is a page, but the height of each fold is measured in cm. Someone else came up with this number through trial and error, but I got that working fine in the script. It was also triggering the "Warning: No pixels were selected" dialog, so I added Code: Select allapp.displayDialogs = DialogModes.NO; in the 3rd line, but it didn't do anything. I can click the check box that says "Don't show this again", but sometimes I need that for other projects when I mess up without realizing.
-
tirips
Creating a CS5 script from scratch
Why did you delete my comment?
Using Photoshop to make folded book is my creation.
Please respect the work done and let visible the link to my tuto :
http://www.faitmain-faitcoeur.fr/diy/fo ... o-writing/ ... o-writing/
Thanks in advance,
Using Photoshop to make folded book is my creation.
Please respect the work done and let visible the link to my tuto :
http://www.faitmain-faitcoeur.fr/diy/fo ... o-writing/ ... o-writing/
Thanks in advance,
-
Fireater989
Creating a CS5 script from scratch
I didn't (and can't) delete your post, a mod did. As you can see, credit and a link to your website has already long since been provided in the original post.