Copy link to clipboard
Copied
If someone wants to test this Script please let me know if you notice issues.
It is supposed to distribute the selected Layers along the selected Path as Smart Object instances.
Not that much use for that, I guess, but what the hey …
// distribute selected layers as smart object instances along selected path, if no path is selected use the first one;
// additional points are calculated along the path to use for positioning the instances;
// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.pathItems.length > 0) {
// get id, center and half-dimensions of selected layers;
var theLayers = smartifyAndGetSelectedLayersIdxEtc();
// get selected path;
var thePath = selectedPath ();
if (thePath == undefined) {var thePath = myDocument.pathItems[0]};
////////////////////////////////////
if (theLayers.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var originalResolution = myDocument.resolution;
myDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
// create a layerset to hold the copies;
var myLayerSet = myDocument.layerSets.add();
myLayerSet.name = "copies on "+thePath.name;
var theGroupIndex = getLayerIndex(myLayerSet)-1;
// collect path info, array of points, angle, distance from last point;
var thePath = getPointsOnPath2015a (myDocument, thePath);
////////////////////////////////////
for (var m = 0; m < thePath.length; m++) {
var theCounter = 0;
var thisSubPath = thePath
; var thisLayer = theNextInTheArray(theLayers, theCounter);
var nextLayer = theNextInTheArray(theLayers, theCounter+1);
var theDistanceCovered = 0;
var theTargetLength = thisLayer[3];
// perform on each sub path array;
for (var n = 0; n < thisSubPath.length; n++) {
theDistanceCovered = theDistanceCovered + Number(thisSubPath
[2]); // if the length is met place instance at position of point with angle;
if (theDistanceCovered >= theTargetLength) {
theTargetLength = thisLayer[3] + nextLayer[3];
duplicateMoveAndScale (myDocument, thisLayer[0], theGroupIndex, thisSubPath
[1], thisSubPath [0][0]-thisLayer[1], thisSubPath [0][1]-thisLayer[2], 100, 100); theCounter++;
var thisLayer = theNextInTheArray(theLayers, theCounter);
var nextLayer = theNextInTheArray(theLayers, theCounter+1);
theDistanceCovered = 0;
}
}
};
////////////////////////////////////
// reset;
app.preferences.rulerUnits = originalRulerUnits;
myDocument.resizeImage(undefined, undefined, originalResolution, ResampleMethod.NONE);
};
////////////////////////////////////
}
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// based on code by mike hale and paul riggott //////
function selectLayerByID(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
// by mike hale, via paul riggott;
function selectLayerByIndex(index,add){
// http://forums.adobe.com/message/1944754#1944754
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
// by mike hale, via paul riggott;
function getLayerIndex(theLayer){
// http://forums.adobe.com/message/1944754#1944754
app.activeDocument.activeLayer = theLayer;
//Assumes activeDocument and activeLayer
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
d = executeActionGet(ref);
return d.getInteger(stringIDToTypeID('itemIndex'));
};
// by mike hale, via paul riggott;
function getLayerId(theLayer){
// http://forums.adobe.com/message/1944754#1944754
app.activeDocument.activeLayer = theLayer;
//Assumes activeDocument and activeLayer
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
d = executeActionGet(ref);
return d.getInteger(charIDToTypeID('LyrI'));
};
////// get array of arrays of smart objects witrh index, center and half-dimensions //////
function smartifyAndGetSelectedLayersIdxEtc(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count;
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
};
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
};
};
////////////////////////////////////
var theArray = new Array;
var theIDs = new Array;
for (var m = 0; m < selectedLayers.length; m++) {
var thisIndex = selectedLayers
; var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Lyr "), thisIndex);
var layerDesc = executeActionGet(ref);
var thisID = layerDesc.getInteger(stringIDToTypeID("layerID"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var halfWidth = theBounds.getUnitDoubleValue(stringIDToTypeID("width")) / 2;
var halfHeight = theBounds.getUnitDoubleValue(stringIDToTypeID("height")) / 2;
var theX = theBounds.getUnitDoubleValue(stringIDToTypeID("left")) + halfWidth;
var theY = theBounds.getUnitDoubleValue(stringIDToTypeID("top")) + halfHeight;
theIDs.push ([thisID, theX, theY, halfWidth, halfHeight])
};
////////////////////////////////////
for (var n = 0; n < theIDs.length; n++) {
if (hasSmartObject(theIDs
[0]) == false) { try {
selectLayerByID(theIDs
[0], false); var id557 = charIDToTypeID( "slct" );
var desc108 = new ActionDescriptor();
var id558 = charIDToTypeID( "null" );
var ref77 = new ActionReference();
var id559 = charIDToTypeID( "Mn " );
var id560 = charIDToTypeID( "MnIt" );
var id561 = stringIDToTypeID( "newPlacedLayer" );
ref77.putEnumerated( id559, id560, id561 );
desc108.putReference( id558, ref77 );
executeAction( id557, desc108, DialogModes.NO );
theArray.push([getLayerId(app.activeDocument.activeLayer), theIDs
[1], theIDs [2], theIDs [3], theIDs [4]]); } catch (e) {}
}
else {theArray.push(theIDs
)}; };
////////////////////////////////////
return theArray
////////////////////////////////////
//return selectedLayers;
};
////// smart object or not //////
function hasSmartObject(idx){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "smartObject" ));
//ref.putIndex( charIDToTypeID( "Lyr " ), idx);
ref.putIdentifier( charIDToTypeID( "Lyr " ), idx);
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('smartObject'))) {return true}
else {return false};
};
////// determine selected path, updated 08.2011 //////
function selectedPath () {
try {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
var theName = desc.getString(charIDToTypeID("PthN"));
return app.activeDocument.pathItems.getByName(theName)
}
catch (e) {
return undefined
}
};
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
for (var l = 0; l < myDocument.pathItems.length; l++) {
var thisPath = myDocument.pathItems
; if (thisPath == thePath && thisPath.name == "Work Path") {
ref.putProperty(cTID("Path"), cTID("WrPt"));
};
if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
ref.putIndex(cTID("Path"), l + 1);
};
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
var idPath = charIDToTypeID( "Path" );
var idPath = charIDToTypeID( "Path" );
var idvectorMask = stringIDToTypeID( "vectorMask" );
ref.putEnumerated( idPath, idPath, idvectorMask );
};
};
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
switch (operation1) {
case 1097098272:
var operation = 1097098272 //cTID('Add ');
break;
case 1398961266:
var operation = 1398961266 //cTID('Sbtr');
break;
case 1231975538:
var operation = 1231975538 //cTID('Intr');
break;
default:
// case 1102:
var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
break;
};
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
try {
var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(leftDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(rightDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
thisPoint.push(smoothOr)
}
catch (e) {thisPoint.push(false)};
theArray[theArray.length - 1].push(thisPoint);
};
theArray[theArray.length - 1].push(closed);
theArray[theArray.length - 1].push(operation);
};
};
// by xbytor, thanks to him;
function cTID (s) { return cTID
|| cTID= app.charIDToTypeID(s); };function sTID (s) { return sTID
|| sTID= app.stringIDToTypeID(s); };// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// determine length of path by creating additional points, by SATO Hiroyuki //////
function getLength(q, div_num){
////// from //////
// Path Length.js;
// Copyright(c) 2009 SATO Hiroyuki
// http://park12.wakwak.com/~shp/lc/et/en_aics_script.html
// ------------------------------------------------
// return the segment length
// segment = part of a path between 2 anchors
// q = [Q0[x,y],Q1,Q2,Q3], div_num = division number
// Simpson's method : with simplified coefficients to speed-up
var div_unit = 1 / div_num;
var m = [q[3][0] - q[0][0] + 3 * (q[1][0] - q[2][0]),
q[0][0] - 2 * q[1][0] + q[2][0],
q[1][0] - q[0][0]];
var n = [q[3][1] - q[0][1] + 3 * (q[1][1] - q[2][1]),
q[0][1] - 2 * q[1][1] + q[2][1],
q[1][1] - q[0][1]];
var k = [m[0] * m[0] + n[0] * n[0],
4 * (m[0] * m[1] + n[0] * n[1]),
2 * ((m[0] * m[2] + n[0] * n[2]) + 2 * (m[1] * m[1] + n[1] * n[1])),
4 * (m[1] * m[2] + n[1] * n[2]),
m[2] * m[2] + n[2] * n[2]];
var fc = function(t, k){
return Math.sqrt(t * ( t * ( t * ( t * k[0] + k[1]) + k[2]) + k[3]) + k[4]) || 0;
};
var total = 0;
var i;
for(i = 1; i < div_num; i += 2){
total += fc(i * div_unit, k);
};
total *= 2;
for(i = 2; i < div_num; i += 2){
total += fc(i * div_unit, k);
};
return (fc(0, k) + fc(1, k) + total * 2) * div_unit;
};
////// function to get array of points on a path; with the direction and distance to previous point //////
function getPointsOnPath2015a (myDocument, thePath) {
/*var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var originalResolution = app.activeDocument.resolution;
app.activeDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);*/
////////////////////////////////////
// get path info;
var theArray = collectPathInfoFromDesc2012(myDocument, thePath);
////////////////////////////////////
// create a high number of new points along the subpaths;
var hypotheticalPoints = new Array;
// and collect the distances;
var theDistances = new Array;
// work through the original array;
for (var m = 0; m < theArray.length; m++) {
var theSubArray = theArray
; var oneSubPath = new Array;
var closed = theSubArray[theSubArray.length - 2];
// change sub array;
theSubArray = theSubArray.slice(0, theSubArray.length - 2);
theSubArray.push(theArray
[0]); theSubArray.push(theArray
[1]); theSubArray.push(theArray
[theArray .length-2]); theSubArray.push(theArray
[theArray .length-1]); // if closed;
if (closed == true) {
var theSegments = theSubArray.length - 4
}
// if not closed;
else {
var theSegments = theSubArray.length - 5;
};
// add first point;
var pointA = theArray
[0][0]; var handleA = theArray
[0][1]; var pointB = theArray
[1][0]; var handleB = theArray
[1][2]; // add angle to ne next point;
if (pointA == handleA) {var theAngle = getAngle(pointA, handleB)}
else {var theAngle = getAngle(pointA, handleA)};
oneSubPath.push([pointA, theAngle, 0]);
// add points;
for (var n = 1; n <= theSegments; n++) {
// the in-between points;
var theNumberOfPoints = Math.round(getLength([pointA, handleA, handleB, pointB], 100)) * 3;
for (var o = 1; o < theNumberOfPoints; o++) {
var theFragment = 1 / theNumberOfPoints * o;
oneSubPath.push(bezierPoint (theFragment, pointA, handleA, pointB, handleB));
var theDist = getDistance (oneSubPath[oneSubPath.length-2][0], oneSubPath[oneSubPath.length-1][0])
oneSubPath[oneSubPath.length-1].push(theDist)
};
// the next point;
var pointA = theSubArray
[0]; var handleA = theSubArray
[1]; var theNext = n + 1;
var pointB = theSubArray[theNext][0];
var handleB = theSubArray[theNext][2];
// get angle;
if (pointA != handleB) {var theAngle = getAngle(pointA, handleB)}
else {var theAngle = getAngle(theSubArray[n-1][1], pointA)};
// angle for the last point;
if (n == theSegments) {
var theAngle = getAngle(pointA, theSubArray
[1]) };
// add point;
var theDist = getDistance (theSubArray
[0], oneSubPath[oneSubPath.length-1][0]) oneSubPath.push([theSubArray
[0], theAngle, theDist]) };
hypotheticalPoints.push(oneSubPath);
};
return hypotheticalPoints
};
////// get point on bezier curve and angle //////
function bezierPoint (theFragment, pointA, handleA, pointB, handleB) {
// the horizontal;
var theOne = (handleA[0] - pointA[0]) * theFragment + pointA[0];
var theTwo = (handleB[0] - handleA[0]) * theFragment + handleA[0];
var theThree = (pointB[0] - handleB[0]) * theFragment + handleB[0];
var theOneTwoH = (theTwo - theOne) * theFragment + theOne;
var theTwoThreeH = (theThree - theTwo) * theFragment + theTwo;
var theX = (theTwoThreeH - theOneTwoH) * theFragment + theOneTwoH;
// the vertical;
var theOne = (handleA[1] - pointA[1]) * theFragment + pointA[1];
var theTwo = (handleB[1] - handleA[1]) * theFragment + handleA[1];
var theThree = (pointB[1] - handleB[1]) * theFragment + handleB[1];
var theOneTwoV = (theTwo - theOne) * theFragment + theOne;
var theTwoThreeV = (theThree - theTwo) * theFragment + theTwo;
var theY = (theTwoThreeV - theOneTwoV) * theFragment + theOneTwoV;
// the point;
var thePoint = [[theX, theY], getAngle ([theOneTwoH, theOneTwoV], [theTwoThreeH, theTwoThreeV])];
// var thePoint = [[theX, theY],;
return thePoint
};
////// radians //////
function radiansOf (theAngle) {
return theAngle * Math.PI / 180
};
////// angle from radians //////
function angleFromRadians (theRad) {
return theRad / Math.PI * 180
};
////// get an angle, 3:00 being 0˚, 6:00 90˚, etc. //////
function getAngle (pointOne, pointTwo) {
// calculate the triangle sides;
var width = pointTwo[0] - pointOne[0];
var height = pointTwo[1] - pointOne[1];
var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
// calculate the angles;
if (width+width > width) {theAngle = Math.asin(height / sideC) * 360 / 2 / Math.PI}
else {theAngle = 180 - (Math.asin(height / sideC) * 360 / 2 / Math.PI)};
if (theAngle < 0) {theAngle = (360 + theAngle)};
// if (theAngle > 180) {theAngle = (360 - theAngle) * (-1)};
return theAngle
};
////// get a distance between two points //////
function getDistance (pointOne, pointTwo) {
// calculate the triangle sides;
var width = pointTwo[0] - pointOne[0];
var height = pointTwo[1] - pointOne[1];
var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
return sideC
};
////// rotate and move //////
function duplicateMoveAndScale (myDocument, theIndex, theGroupIndex, thisAngle, horizontalOffset, verticalOffset, horScale, verScale) {
// duplicate by index;
// =======================================================
var idmove = charIDToTypeID( "move" );
var desc8 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref8.putIdentifier( charIDToTypeID( "Lyr " ), theIndex );
desc8.putReference( idnull, ref8 );
var idT = charIDToTypeID( "T " );
var ref9 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref9.putIndex( idLyr, theGroupIndex );
desc8.putReference( idT, ref9 );
var idDplc = charIDToTypeID( "Dplc" );
desc8.putBoolean( idDplc, true );
var idAdjs = charIDToTypeID( "Adjs" );
desc8.putBoolean( idAdjs, false );
var idVrsn = charIDToTypeID( "Vrsn" );
desc8.putInteger( idVrsn, 5 );
executeAction( idmove, desc8, DialogModes.NO );
// do the transformations;
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref2.putEnumerated( idLyr, idOrdn, idTrgt );
desc3.putReference( idnull, ref2 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc4 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc4.putUnitDouble( idHrzn, idPxl, horizontalOffset );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc4.putUnitDouble( idVrtc, idPxl, verticalOffset );
var idOfst = charIDToTypeID( "Ofst" );
desc3.putObject( idOfst, idOfst, desc4 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc3.putUnitDouble( idWdth, idPrc, horScale );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc3.putUnitDouble( idHght, idPrc, verScale );
if (thisAngle != 0) {
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc3.putUnitDouble( idAngl, idAng, thisAngle );
};
executeAction( idTrnf, desc3, DialogModes.NO );
};
////// get netx in an array circularly //////
function theNextInTheArray (theArray, theNumber) {
if (theNumber < theArray.length - 1) {return theArray[theNumber]}
else {
var theNumber = theNumber - (Math.floor(theNumber / theArray.length )) * theArray.length;
return theArray[theNumber]
}
};
Copy link to clipboard
Copied
Hey there I recently got back into playing with the old deco scripts we created back in 2012 when we were testing and creating them. I have a particular script that places patterns along a path that I really like. I'm still using CS6 but a couple of weeks ago I downloaded CC version and I really liked the ' Place Along Path ' in the Fill dialogue box of scripted patterns. It has a lot of nice options that my script does not have. I wish I knew who wrote the script back then but I have no clue. This particular script script places a pattern along a path and copies and flips it. For instance if your pattern is a horizontal leaf it will create a path that has leaves on both sides. I really like it but I miss not having the color random option that is in CC. I have no idea how to write scripts. All I ever do is edit the numbers... so I don't know how to add the option to this script. This is what the dialogue box looks like.
This is the script;
#target photoshop
app.bringToFront();
main();
function main(){
var updated=false;
if(!documents.length) return;
var file = File(Folder.temp +"/deco.pat");
if(file.exists) file.remove();
savePatterns( file );
file.open("r");
file.encoding = 'BINARY';
var str = file.read();
file.close();
var patterns=[];
var rex = /(\x00\w|\x00\d)(\x00\-|\x00\w|\x00\s|\x00\d)+\x00\x00\$[-a-z\d]+/g;
while ((result = rex.exec(str)) != null) {
var sp = result[0].toString().replace(/\x00/g, '').split('$');
var X = readInt16(str,(result.index+(result[0].length)+22));
var Y = readInt16(str,(result.index+(result[0].length)+18));
patterns.push([[sp[0]],[sp[1]],
, ]); }
patterns=ReturnUniqueSortedList(patterns);
file.remove();
var win = new Window( 'dialog', 'Path Fill' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Path Fill');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLD",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "row";
win.g5.alignment='fill';
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Spacing pattern (in pixels): ');
win.g5.st1.preferredSize=[250,20];
win.g5.et1 = win.g5.add('edittext',undefined,'20,100');
win.g5.et1.preferredSize=[200,20];
win.g5.et1.onChanging = function() {
if (this.text.match(/[^,.\-\d]/)) {
this.text = this.text.replace(/[^,.\-\d]/g, '');
}
};
win.g6 =win.p1.add('group');
win.g6.orientation = "row";
win.g6.alignment='fill';
win.g6.spacing=10;
win.g6.st1 = win.g6.add('statictext',undefined,'Rotation pattern (in degrees): ');
win.g6.st1.preferredSize=[250,20];
win.g6.et1 = win.g6.add('edittext',undefined,'60,-60');
win.g6.et1.preferredSize=[200,20];
win.g6.et1.onChanging = function() {
if (this.text.match(/[^,.\-\d]/)) {
this.text = this.text.replace(/[^,.\-\d]/g, '');
}
};
win.g7 =win.p1.add('group');
win.g7.orientation = "row";
win.g7.alignment='fill';
win.g7.spacing=10;
win.g7.st1 = win.g7.add('statictext',undefined,'Size Factor Pattern : ');
win.g7.st1.preferredSize=[250,20];
win.g7.et1 = win.g7.add('edittext',undefined,'1,.9,.8');
win.g7.et1.preferredSize=[200,20];
win.g7.et1.onChanging = function() {
if (this.text.match(/[^,.\-\d]/)) {
this.text = this.text.replace(/[^,.\-\d]/g, '');
}
};
win.g11 =win.p1.add('group');
win.g11.orientation = "row";
win.g11.alignment='fill';
win.g11.spacing=10;
win.g11.st1 = win.g11.add('statictext',undefined,'Mirror Pattern : ');
win.g11.st1.preferredSize=[250,20];
win.g11.et1 = win.g11.add('edittext',undefined,'1,-1');
win.g11.et1.preferredSize=[200,20];
win.g11.et1.onChanging = function() {
if (this.text.match(/[^,.\-\d]/)) {
this.text = this.text.replace(/[^,.\-\d]/g, '');
}
};
win.g8 =win.p1.add('group');
win.g8.orientation = "row";
win.g8.alignment='fill';
win.g8.spacing=10;
win.g8.st1 = win.g8.add('statictext',undefined,'Parallel offset factor pattern: ');
win.g8.st1.preferredSize=[250,20];
win.g8.et1 = win.g8.add('edittext',undefined,'1');
win.g8.et1.preferredSize=[200,20];
win.g8.et1.onChanging = function() {
if (this.text.match(/[^,.\-\d]/)) {
this.text = this.text.replace(/[^,.\-\d]/g, '');
}
};
win.g9 =win.p1.add('group');
win.g9.orientation = "row";
win.g9.alignment='fill';
win.g9.spacing=10;
win.g9.st1 = win.g9.add('statictext',undefined,'Final pattern size factor: ');
win.g9.st1.preferredSize=[250,20];
win.g9.et1 = win.g9.add('edittext',undefined,'1');
win.g9.et1.preferredSize=[50,20];
win.g9.et1.onChanging = function() {
if (this.text.match(/[^\-\.\d]/)) {
this.text = this.text.replace(/[^\-\.\d]/g, '');
}
};
win.g10 =win.p1.add('group');
win.g10.orientation = "row";
win.g10.alignment='fill';
win.g10.st1 = win.g10.add('statictext',undefined,'Please select Pattern:');
win.g10.st1.preferredSize=[250,20];
win.g10.dd1 = win.g10.add('dropdownlist');
for(var p in patterns){win.g10.dd1.add('item',patterns
[0]);}
win.g10.dd1.selection=0;
win.g10.dd1.onChange = function(){
var str = patterns[win.g10.dd1.selection.index][0].toString() + " ( X = " ;
str += Number(patterns[win.g10.dd1.selection.index][2]) + " Y = ";
str += Number(patterns[win.g10.dd1.selection.index][3]) + ")";
win.g10.dd1.helpTip = str;
}
win.g10.dd1.onChange();
win.g15 =win.p1.add('group');
win.g15.orientation = "row";
win.g15.alignment='fill';
var Blend = ['Normal','Dissolve','-','Darken','Multiply','Color Burn','Linear Burn','Darker Color','-','Lighten','Screen','Color Dodge',
'Linear Dodge (Add)','Lighter Color','-','Overlay','Soft Light','Hard Light','Vivid Light','Linear Light', 'Pin Light','Hard Mix','-','Difference', 'Exclusion',
'Subtract','Divide','-','Hue','Saturation','Color','Luminosity'];
var bMode=['Nrml','Dslv','-','Drkn','Mltp','CBrn','linearBurn','darkerColor','-','Lghn', 'Scrn',
'CDdg','linearDodge','lighterColor','-','Ovrl','SftL','HrdL','vividLight','linearLight','pinLight','hardMix','-',
'Dfrn','Xclu','blendSubtraction','blendDivide','-','H ','Strt','Clr ','Lmns'];
win.g15.st1 = win.g15.add('statictext',undefined,'Blend Mode:');
win.g15.st1.preferredSize=[250,20];
win.g15.dd1 = win.g15.add('dropdownlist',undefined,Blend);
win.g15.dd1.selection=0;
win.g20 =win.p1.add('group');
win.g20.orientation = "row";
win.g20.alignment='fill';
win.g20.st1 = win.g20.add('statictext',undefined,'Opacity:');
win.g20.st1.preferredSize=[250,20];
win.g20.et1 = win.g20.add('edittext',undefined,'100');
win.g20.et1.preferredSize=[50,20];
win.g20.et1.onChanging = function() {
if (this.text.match(/[^\-\.\d]/)) {
this.text = this.text.replace(/[^\-\.\d]/g, '');
}
};
var pictureFlag = true //flag about whether you choose to select patterns by name or by picture
win.g100 =win.p1.add('group');
win.g100.orientation = "row";
win.g100.alignment='center';
win.g100.bu1 = win.g100.add('button',undefined,'Update');
win.g100.bu1.preferredSize=[150,30];
win.g100.bu3 = win.g100.add('button',undefined,'See pattern pictures');
win.g100.bu3.preferredSize=[150,30];
win.g100.bu2 = win.g100.add('button',undefined,'Close');
win.g100.bu2.onClick=function(){
win.close(0);
}
win.g100.bu2.preferredSize=[150,30];
win.g100.bu1.onClick=function(){
if(win.g5.et1.text == ''){
alert("Your spacing cannot be blank");
return;
}
//if(isNaN(Number(win.g5.et1.text) )){
// alert("Your entry for the spacing is not a number");
// return;
// }
if(win.g9.et1.text == ''){
alert("Your final size specification cannot be blank");
return;
}
if(isNaN(Number(win.g9.et1.text) )){
alert("Your entry for the final size is not a number");
return;
}
if(ScriptUI.environment.keyboardState.shiftKey){
win.close(0);
}
pictureFlag = false;
if (updated==true){
executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );
}
updated=true;
doit(pictureFlag);
app.refresh();
} //end finction for using the patterns by name
win.g100.bu3.onClick=function(){
//if(win.g5.et1.text == ''){
// alert("Your spacing cannot be blank");
// return;
// }
if(win.g9.et1.text == ''){
alert("Your final size specification cannot be blank");
return;
}
if(isNaN(Number(win.g9.et1.text) )){
alert("Your entry for the final size is not a number");
return;
}
pictureFlag = true;
if(!ScriptUI.environment.keyboardState.shiftKey) win.close(0);
doit(pictureFlag);
app.refresh();
} //end finction for using the patterns by pictures - through the fill dialog box
//} //closing brace to end main
function doit(useFillBoxFlag) {
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
var startDisplayDialogs = app.displayDialogs;
// Set Adobe Photoshop CS6 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
//app.displayDialogs = DialogModes.NO;
var activePath=activePathIndex()
if (activePath=-1)activePath=0;
myPath=activeDocument.pathItems[activePathIndex()].subPathItems[0]; //I'm just calculating the first subpath of the active path
var scriptEndSize = Number(win.g9.et1.text); //factor of Final pattern size
var spacing=[];
spacing = win.g5.et1.text.match(/[0-9.]+/g);
for (var i =0; i< spacing.length; i++){
spacing=parseFloat(spacing);
}
spacedPoints= new Array; //The position of each of the equally spaced points
rotations = new Array; //The rotation of each of the equally spaced points
sizes = new Array;
mirrors=new Array;
//accuracy of calculation... how many straight line segments each curved segment is split into.
var granularity = 100;
var results = new Array; //points of the straight line segment.... these aren't evenly spaced.
var pointCount=myPath.pathPoints.length-1;
//Approximate Path by dividing into straight line segments
var d = myPath.pathPoints[0].anchor;
for(var i = 0; i< pointCount; i++)
{
var a = d
var b = myPath.pathPoints.leftDirection;
var c = myPath.pathPoints[i+1].rightDirection;
var d = myPath.pathPoints[i+1].anchor;
for (var j =0; j < granularity; j++)
{
var t = j/granularity;
results[i*granularity + j] = bezier (a, b, c, d, t);
}
}
// Calculate the last path segment if the path is closed.... same code as above
if(myPath.closed==true){
var a = myPath.pathPoints[pointCount].anchor
var b = myPath.pathPoints[pointCount].leftDirection;
var c = myPath.pathPoints[0].rightDirection;
var d = myPath.pathPoints[0].anchor;
for (var j =0; j < granularity; j++)
{
var t = j/granularity;
results[pointCount*granularity + j] = bezier (a, b, c, d, t);
}
}
spacedPoints[0]=(0,0)
var totalEq=0;
//Calculate the length of the curve up to each point
var segmentLength= new Array;
segmentLength[0]=0;
var totalLength=segmentLength[0];
for(var i = 0; i < results.length-1; i++)
{
segmentLength[i+1]= segmentLength+Math.sqrt(Math.pow(results[0]-results[i+1][0],2) + Math.pow(results[1]-results[i+1][1],2));
}
//Points aren't equally distributed, This makes an array of equally spaced points
var spacingCount=0;
var count = 0;
var count2 = 0;
var fullLength=segmentLength[segmentLength.length-1]
//adjust spacing so it will devide evenly into the full length of a closed path
/*
if(myPath.closed==true){
spacing = fullLength / Math.round(fullLength/spacing)
}
*/
while(totalEq < segmentLength[segmentLength.length-1]){
while(totalEq>=segmentLength[count+1])
{
//alert(totalEq+"\n"+segmentLength[count+1])
count++;
}
while(segmentLength[count+1]>=totalEq && totalEq < segmentLength[segmentLength.length-1])
{
spacedPoints[count2]= lerp(results[count],results[count+1], (totalEq-segmentLength[count]) / (segmentLength[count+1]-segmentLength[count]));
rotations[count2]= Math.atan2 ((results[count+1][1]-results[count][1]),(results[count+1][0]-results[count][0]))*(180/Math.PI);
if(rotations[count2]<0)rotations[count2]+=360
sizes[count2]=1;
totalEq+=spacing[spacingCount];
spacingCount++;
if (spacingCount==spacing.length) spacingCount=0
//Create a count item to show where the points are
//activeDocument.countItems.add(spacedPoints[count2]);
count2++;
}
}
if(ScriptUI.environment.keyboardState.ctrlKey){
spacedPoints = spacedPoints.reverse();
}
var rotationPattern=[];
rotationPattern = win.g6.et1.text.match(/-?[0-9.]+/g);
rotationCount=0;
var mirrorPattern=[];
mirrorPattern = win.g11.et1.text.match(/-?[0-9.]+/g);
mirrorCount=0;
var offsetPattern=[]
offsetPattern = win.g8.et1.text.match(/-?[0-9.]+/g);
offsetCount=0;
var sizingPattern=[]
sizingPattern = win.g7.et1.text.match(/-?[0-9.]+/g);
sizingCount=0
for (var i =0; i< rotationPattern.length; i++){
rotationPattern=parseFloat(rotationPattern);
}
for (var i =0; i< sizingPattern.length; i++){
sizingPattern=parseFloat(sizingPattern);
}
for (var i =0; i< mirrorPattern.length; i++){
mirrorPattern=parseFloat(mirrorPattern);
}
for (var i =0; i< offsetPattern.length; i++){
offsetPattern=parseFloat(offsetPattern);
}
for(var i=0;i<rotations.length;i++){
rotations+=rotationPattern[rotationCount++]
if (rotationCount==rotationPattern.length)rotationCount=0;
sizes*=sizingPattern[sizingCount++]
sizes*=(1-scriptEndSize)*(rotations.length-i)/rotations.length + scriptEndSize
//var scale = (100 - endsize)*(totalPointCount - n)/totalPointCount + endsize
if (sizingCount==sizingPattern.length)sizingCount=0;
spacedPoints[0]+= Math.cos(rotations*(Math.PI/180)) * offsetPattern[offsetCount]*Number(patterns[win.g10.dd1.selection.index][2])*sizes
spacedPoints[1]+= Math.sin(rotations*(Math.PI/180)) * offsetPattern[offsetCount++]*Number(patterns[win.g10.dd1.selection.index][2])*sizes
if (offsetCount==offsetPattern.length)offsetCount=0;
mirrors=mirrorPattern[mirrorCount++]
if (mirrorCount==mirrorPattern.length)mirrorCount=0;
}
Math.cos(45*(Math.PI/180))
//set temp vars in memory
$.setenv("DECOpoints","var points = ["+spacedPoints.toString()+"];");
$.setenv("DECOrotations","var rotations = ["+rotations.toString()+"];");
$.setenv("DECOsizes","var sizes = ["+sizes.toString()+"];");
$.setenv("DECOmirrors","var mirrors = ["+mirrors.toString()+"];");
// Reset the application preferences
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
//call fill menu
var Name = patterns[win.g10.dd1.selection.index][0];
var PatID = patterns[win.g10.dd1.selection.index][1];
var BMODE = bMode[win.g15.dd1.selection.index];
var Opacity = Number(win.g20.et1.text);
if(Opacity > 100) Opacity = 100;
if(Opacity < 0) Opacity = 0;
decoFill(Name,PatID,BMODE,Opacity,useFillBoxFlag);
}
win.center();
win.show();
}
function bezier(a,b,c,d,t)
{
var ab,bc,cd,abbc,bccd;
ab = lerp(a,b,t);
bc = lerp(b,c,t);
cd = lerp(c,d,t);
abbc = lerp(ab,bc,t);
bccd = lerp(bc,cd,t);
return lerp(abbc,bccd,t);
}
function lerp(a,b,t)
{
var x = a[0] + (b[0]-a[0])*t;
var y = a[1] + (b[1]-a[1])*t;
return [x,y];
}
function readByte(str, ofs) {
return str.charCodeAt(ofs);
}
function readInt16(str, ofs) {
return (readByte(str, ofs) << 8) + readByte(str, ofs+1);
}
function activePathIndex(){// returns -1 if no path active/selective
try{
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet( ref );
return desc.getInteger(charIDToTypeID("TrgP" ));
}catch(e){}
};
function decoFill(Name,PatID,BMODE,Opacity,useFillBoxFlag) {
if(BMODE.length> 4) {
var blendMode ="stringIDToTypeID(BMODE);";
}else{
var blendMode = "charIDToTypeID(BMODE);";
}
var desc16 = new ActionDescriptor();
desc16.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('FlCn'), charIDToTypeID('Ptrn') );
var desc17 = new ActionDescriptor();
desc17.putString( charIDToTypeID('Nm '), Name.toString());
desc17.putString( charIDToTypeID('Idnt'), PatID.toString());
desc16.putObject( charIDToTypeID('Ptrn'), charIDToTypeID('Ptrn'), desc17 );
desc16.putPath( stringIDToTypeID('decoScriptFile'), new File( app.path +"/Presets/Deco/Path_Deco.jsx" ) );
desc16.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), Number(Opacity) );
desc16.putEnumerated( charIDToTypeID('Md '), charIDToTypeID('BlnM'), eval(blendMode));
try{
if (useFillBoxFlag) {
executeAction( charIDToTypeID('Fl '), desc16, DialogModes.ALL )}
else {
executeAction( charIDToTypeID('Fl '), desc16, DialogModes.NO )}
}catch(e){alert(e+" - "+ e.line);}
};
function savePatterns( file ) {
var desc = new ActionDescriptor();
desc.putPath( charIDToTypeID( "null" ), new File(file) );
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "Ptrn" ) );
ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "T " ), ref );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
};
function ReturnUniqueSortedList(ArrayName){
var unduped = new Object;
for (var i = 0; i < ArrayName.length; i++) {
unduped[ArrayName] = ArrayName;
}
var uniques = new Array;for (var k in unduped) {
uniques.push(unduped
);} return uniques.sort();
}
_____
If you could point me in the write direction to learn how to edit scripts and add the color random option I'd REALLY REALLY appreciate it ! Thanks so much !
-Jodi
PS I really like your script of having smart objects follow a path ! Very cool !!
Copy link to clipboard
Copied
Jodi, did you want to edit a deco script or make a script that places shapes, or other layers along a path?
Copy link to clipboard
Copied
Well Chuck I really just wanted to add a color random option to the script that David wrote. The one I posted earlier. I like color variations when creating these paths. I like the way it's done in CC but I don't have that version now. I'm still using CS6. I was hoping to find some documention on writing these scripts. They were posted a while back and the links I found are dead. After all this time I really didn't want to bother the original author. It's just for personal use.
Copy link to clipboard
Copied
It's always hard for me to dissect someone else's script. I'm not sure, but it doesn't look like David's used Radomir's deco fill API but used the generic Photoshop javascript. With Radomir's method, you could add the color variation easily. I'm not sure how you could go about that with David's script, or if you can.
Copy link to clipboard
Copied
Ah ok then. I guess you saved me a lot of loop time
Thanks so much Chuck. I appreciate you looking.
Copy link to clipboard
Copied
Same leaf with your script
Copy link to clipboard
Copied
Richard Kain wrote those scripts, I believe.
Copy link to clipboard
Copied
Hi Chuck ! I just found the old post and the user profile of the person who created it is Yelnats1 but I can't find further info on this individual's profile so I'm not sure if it is in fact Richard Kain. Thanks though as maybe I can look him up and see if he's the author. Thank you !
Edit; I've been playing with your fill script quite a bit lately as well Chuck...that very neat one you wrote way back when..
Copy link to clipboard
Copied
Do you have a link to the discussion?
Copy link to clipboard
Copied
yup !
What is a downer is the links on Radomir's write up on the deco engine are all dead links... the documentation at bottom of page for writing deco scripts and the links to other scripts are dead too. That's what happens when I dig into the past ;/
Copy link to clipboard
Copied
David's last name is eluding me.
Copy link to clipboard
Copied
That's fine Chuck. I'll try to figure it out. I know there was much more info available back then on writing these deco scripts. Thanks so much !
Copy link to clipboard
Copied
Copy link to clipboard
Copied
OMG how ????
Thank you !!!!
Copy link to clipboard
Copied
Thanks, pixxxel schubser! That's it. Jensen.
Copy link to clipboard
Copied
Chuck you responded to his post where he shares this script and you called him ' David ' ... Any ideas ??
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Can you provide the file?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now