femkeblanco
Guide
femkeblanco
Guide
Activity
‎May 15, 2023
12:55 PM
This is an error message one gets with the menu command Object > Artboards > Convert to Artboards. So what object are you trying to convert to an artboard? In addition to the script, you probably need to show your document.
... View more
‎May 15, 2023
02:26 AM
I think you have to iterate all the top level pageItems and check each pageItems[i] as to whether it references the same selected object.
... View more
‎May 13, 2023
12:11 PM
Go to https://developer.adobe.com/illustrator/. Click "console" (in the upper right corner) and log in. Click "Download resources". Scroll down to "Illustrator", which is in the bottom half of the page. Click "View downloads". You'll find the JavaScript reference there. Alternatively, go to https://assets.adobe.com/public/aa41975d-3a2b-4ba9-6658-34e88a029a63 (courtesy of @CarlosCanto).
... View more
‎May 09, 2023
09:30 AM
I think the scripts are available from here
... View more
‎May 04, 2023
01:47 PM
1 Upvote
This should accommodate end points and closed paths. /*
* "Add an anchor point to a non-curved path" by Femke Blanco
* 04/05/2023
* Instructions:
* - select ONE point with the white arrow tool (A);
* - to add a point after the selected point, enter a (+) number;
* - to add a point before the selected point, enter a (-) number.
*/
var input = prompt("", "30");
var before = [];
var after = [];
var swap, i, addedPoint, array;
try {
var path1 = app.activeDocument.selection[0];
var points = path1.pathPoints;
for (var j = 0; j < points.length; j++) {
if (points[j].selected == PathPointSelection.ANCHORPOINT) {
swap = true;
i = j;
continue;
}
if (!swap) {
before.push([points[j].anchor[0], points[j].anchor[1]]);
} else {
after.push([points[j].anchor[0], points[j].anchor[1]]);
}
}
var j;
if (input > 0) {
if (i != points.length - 1) {
j = i + 1;
} else {
if (!path1.closed) j = i - 1, input *= -1;
else j = 0;
}
addedPoint = getAddedPoint(points[i], points[j], input);
array = before.concat(
[[points[i].anchor[0], points[i].anchor[1]], addedPoint]
);
} else {
if (i != 0) {
j = i - 1;
} else {
if (!path1.closed) j = i + 1, input *= -1;
else j = points.length - 1;
}
addedPoint = getAddedPoint(points[i], points[j], -input);
array = before.concat(
[addedPoint, [points[i].anchor[0], points[i].anchor[1]]]
);
}
array = array.concat(after);
var path2 = app.activeDocument.pathItems.add();
path2.setEntirePath(array);
if (path1.closed) path2.closed = true;
path2.selected = true;
path1.remove();
} catch (e) {
alert(e);
}
function getAddedPoint(p1, p2, h/*hypotenuse*/) {
var x1 = p1.anchor[0];
var y1 = p1.anchor[1];
var x2 = p2.anchor[0];
var y2 = p2.anchor[1];
var dx = x2 - x1;
var dy = y2 - y1;
var a = Math.atan2(dy, dx)
dx = Math.cos(a) * h;
dy = Math.sin(a) * h;
return [x1 + dx, y1 + dy];
}
... View more
‎May 04, 2023
01:55 AM
This was written with an open path in mind. I'll amend it later to accommodate closed paths.
... View more
‎Apr 27, 2023
02:23 AM
1 Upvote
The last position snippet I posted should still work, it being a matter of targeting the relevant clipping path. In this case, if I am correct, the relevant clipping path appears to be the same size as the artboard. So this may work var paths = app.activeDocument.pathItems;
for (var i = 0; i < paths.length; i++) {
if (paths[i].clipping == true &&
(Math.round(paths[i].width) == Math.round(docWidth) ||
Math.round(paths[i].height) == Math.round(docHeight))) {
var CP = paths[i];
break;
}
}
pastedObjects.position = [
docWidth / 2 - ((CP.left - pastedObjects.left) + CP.width / 2),
-docHeight / 2 + (-(CP.top - pastedObjects.top) + CP.height / 2)]; Or, to put it in the rest of your code #target illustrator
var artboardIndex = 1;
var artboards = app.activeDocument.artboards;
// var destFolder = Folder.selectDialog("Select the destination folder");
var destFileName = app.activeDocument.name;
var docWidth = prompt("Enter the new document width (in inches):") * 72;
var docHeight = prompt("Enter the new document height (in inches):")* 72;
// select the objects on the artboard
artboards.setActiveArtboardIndex(artboardIndex);
app.activeDocument.selectObjectsOnActiveArtboard();
// calculate the scale factor based on the original artboard size
var currentArtboard = app.activeDocument.artboards[artboardIndex];
var currentArtboardBounds = currentArtboard.artboardRect;
var pastedObjectsWidth = currentArtboardBounds[2] - currentArtboardBounds[0];
var pastedObjectsHeight = currentArtboardBounds[1] - currentArtboardBounds[3];
var scaleFactor = Math.min(docWidth / pastedObjectsWidth, docHeight / pastedObjectsHeight);
// copy and paste
app.copy();
var newDoc = app.documents.add(DocumentColorSpace.CMYK, docWidth, docHeight);
var ABR = newDoc.artboards[0].artboardRect = [0, 0, docWidth, -docHeight];
app.paste();
newDoc.views[0].centerPoint = [docWidth / 2, -docHeight / 2];
// group, re-size and re-position
app.executeMenuCommand("group")
var pastedObjects = newDoc.selection[0];
pastedObjects.width *= scaleFactor;
pastedObjects.height *= scaleFactor;
//
var paths = app.activeDocument.pathItems;
for (var i = 0; i < paths.length; i++) {
if (paths[i].clipping == true &&
(Math.round(paths[i].width) == Math.round(docWidth) ||
Math.round(paths[i].height) == Math.round(docHeight))) {
var CP = paths[i];
break;
}
}
pastedObjects.position = [
docWidth / 2 - ((CP.left - pastedObjects.left) + CP.width / 2),
-docHeight / 2 + (-(CP.top - pastedObjects.top) + CP.height / 2)];
//
// var newFile = new File(destFolder + "/" + destFileName);
app.executeMenuCommand("ungroup");
// newDoc.saveAs(newFile);
// newDoc.close();
... View more
‎Apr 25, 2023
04:44 PM
Thanks. This will probably come in handy in the future.
... View more
‎Apr 25, 2023
04:40 PM
Assuming the clipping path (CP) is the topmost item, you can centre a clipping set based on the centre of the clipping path as such var docWidth = app.activeDocument.width;
var docHeight = app.activeDocument.height;
var pastedObjects = app.activeDocument.selection[0];
var CP = pastedObjects.pathItems[0];
pastedObjects.position = [
docWidth / 2 - ((CP.left - pastedObjects.left) + CP.width / 2),
-docHeight / 2 + (-(CP.top - pastedObjects.top) + CP.height / 2)]; If this is not what you need, screenshots—including the relevant items visible in the Layers Panel—are suggested.
... View more
‎Apr 23, 2023
01:31 PM
2 Upvotes
var file1, firstPage, lastPage;
var w = new Window("dialog");
var g1 = w.add("group");
g1.orientation = "row";
var b1 = g1.add("button", undefined, "File");
b1.preferredSize.width = 75;
var et1 = g1.add("edittext", undefined, "");
et1.preferredSize.width = 300;
file1 = et1.text;
b1.onClick = function () {
file1 = File.openDialog("prompt");
et1.text = file1.fullName;
}
var g2 = w.add("group");
g2.orientation = "row";
var st1 = g2.add("statictext", undefined, "");
st1.preferredSize.width = 75;
var g3 = g2.add("group");
g3.preferredSize.width = 200;
g3.orientation = "column";
g3.alignChildren = ["left", "center"];
var st2 = g3.add("statictext", undefined, "Page interval");
var g4 = g3.add("group");
g4.orientation = "row";
var st3 = g4.add("statictext", undefined, "From:");
st3.preferredSize.width = 30;
var et3 = g4.add("edittext", undefined, "1");
et3.preferredSize.width = 50;
firstPage = Number(et3.text);
et3.onChange = function () {
firstPage = Number(et3.text);
}
var st4 = g4.add("statictext", undefined, "to:");
st4.preferredSize.width = 15;
var et4 = g4.add("edittext", undefined, "1");
et4.preferredSize.width = 50;
lastPage = Number(et4.text);
et4.onChange = function () {
lastPage = Number(et4.text);
}
var g6 = g2.add("group");
g6.orientation = "column";
var b2 = g6.add("button", undefined,"OK");
b2.preferredSize.width = 75;
var b3 = g6.add("button", undefined, "Cancel");
b3.preferredSize.width = 75;
w.show();
var doc = app.activeDocument;
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var pdfOptions = app.preferences.PDFFileOptions;
alert("File: " + file1 + "\nFrom: " + firstPage + "\nTo: " + lastPage);
// for (var i = firstPage; i < lastPage; i++) {
// pdfOptions.pageToOpen = i;
// var thisPlacedItem = doc.placedItems.add();
// thisPlacedItem.file = file1;
// }
... View more
‎Apr 23, 2023
03:19 AM
If (1) the group was rotated manually and (2) the group and its members have the same rotation angle (as shown in the image), then the rotation angle can be got by alert(app.selection[0].tags[0].name + ": \
" + app.selection[0].tags[0].value * 180 / Math.PI); (Courtesy of Silly-V). In this snipet, selection[0] is a path item (not group item) targeted by selecting it.
... View more
‎Apr 22, 2023
03:48 PM
1 Upvote
Just change it to UIElements[i].prototype.setBg=function(rgb){
... View more
‎Apr 22, 2023
06:55 AM
4 Upvotes
This is a quick attempt intended for non-curved lines. To Use: (1) select one point (with the white arrow tool); (2) to add a point after, use a positive number; to add a point before, use a negative number. (The script will fail if you try to add before the first point or after the last point.) var input = prompt("", "30");
var before = [];
var after = [];
var swap = false;
var j;
var path1 = app.activeDocument.selection[0];
var points = path1.pathPoints;
for (var i = 0; i < points.length; i++) {
if (points[i].selected == PathPointSelection.ANCHORPOINT) {
swap = true;
j = i;
continue;
}
if (swap) {
after.push([points[i].anchor[0], points[i].anchor[1]]);
} else {
before.push([points[i].anchor[0], points[i].anchor[1]]);
}
}
var addedPoint, array;
if (input > 0) {
addedPoint = getAddedPoint(points[j], points[j + 1], input);
array = before.concat(
[[points[j].anchor[0], points[j].anchor[1]], addedPoint])
} else {
addedPoint = getAddedPoint(points[j], points[j - 1], -input);
array = before.concat(
[addedPoint, [points[j].anchor[0], points[j].anchor[1]]])
}
array = array.concat(after);
var path2 = app.activeDocument.pathItems.add();
path2.setEntirePath(array);
path2.selected = true;
path1.remove();
function getAddedPoint(p1, p2, h) {
var x1 = p1.anchor[0];
var y1 = p1.anchor[1];
var x2 = p2.anchor[0];
var y2 = p2.anchor[1];
var dx = x2 - x1;
var dy = y2 - y1;
var a = Math.atan2(dy, dx)
dx = Math.cos(a) * h;
dy = Math.sin(a) * h;
return [x1 + dx, y1 + dy];
}
... View more
‎Apr 22, 2023
04:42 AM
Ten-thousandth of a point/pixel is imperceptible.
... View more
‎Apr 22, 2023
04:31 AM
There are few syntax and logic errors. 1. This is an invalid statement app.activeDocument.selection = pageItems To select, change it to app.activeDocument.selectObjectsOnActiveArtboard(); 2. You need to select and copy while you're on the first document, i.e. before you add the second document. So move the statements that select and copy before app.documents.add(). 3. These are invalid expressions pastedObjects.width
pastedObjects.height
pastedObjects.position A selection collection does not have such properties as width, height, position, et cetera. If you wish to manipulate items as a group, you'll have to group them. The alternative is to manipulate them individually. This may do what you want: var artboardIndex = 0;
var artboards = app.activeDocument.artboards;
var destFolder = Folder.selectDialog("Select the destination folder");
var destFileName = app.activeDocument.name;
var docWidth = prompt("Enter the new document width (in inches):") * 72;
var docHeight = prompt("Enter the new document height (in inches):")* 72;
// select
var selection = app.activeDocument.selection = null;
artboards.setActiveArtboardIndex(artboardIndex);
app.activeDocument.selectObjectsOnActiveArtboard();
// copy and paste
app.copy();
var newDoc = app.documents.add(DocumentColorSpace.CMYK, docWidth, docHeight);
var ABR = newDoc.artboards[0].artboardRect = [0, 0, docWidth, -docHeight];
app.paste();
newDoc.views[0].centerPoint = [docWidth / 2, -docHeight / 2];
// group, re-size and re-position
app.executeMenuCommand("group")
var pastedObjects = newDoc.selection[0];
var pastedObjectsWidth = pastedObjects.width;
var pastedObjectsHeight = pastedObjects.height;
var scaleFactor = Math.min(docWidth / pastedObjectsWidth,
docHeight / pastedObjectsHeight);
pastedObjects.width *= scaleFactor;
pastedObjects.height *= scaleFactor;
pastedObjects.position = [docWidth / 2 - pastedObjects.width / 2,
-docHeight / 2 + pastedObjects.height / 2];
var newFile = new File(destFolder + "/" + destFileName);
app.executeMenuCommand("ungroup");
newDoc.saveAs(newFile);
newDoc.close();
... View more
‎Apr 19, 2023
12:22 AM
It appears that a new line is converted to a carriage return when a string is assigned to the contents of a text frame. Both the escape character and decimal value change.
... View more
‎Apr 16, 2023
06:22 AM
A "symbol set" produced by the Symbol Sprayer tool is a pluginItem.
... View more
‎Apr 15, 2023
03:47 PM
The script will silently fail if any of the aforementioned named layers doesn't exist. Is that the case? And the script will not proceed unless the items to be rotated are placed items or text frames. Is that the intention? Also, the typename of a group is "GroupItem", not "Group".
... View more
‎Apr 15, 2023
12:00 PM
Sorry to be defeatist, but since this is a cursive style, separating the letters is beyond the power of any script.
... View more
‎Apr 15, 2023
11:57 AM
Is it a raster image? How is the dot/patch to be targeted?
... View more
‎Apr 15, 2023
05:05 AM
This duplicates the topmost path in a selected compound path. (The duplicate will still be within the compound path; if it should be out, it will have to be moved out.) var dup = app.selection[0].pathItems[0].duplicate();
dup.position = [0, 0]; If you want to duplicate the bottommost path, change the path's index to app.selection[0].pathItems.length - 1.
... View more
‎Apr 15, 2023
04:52 AM
This snippet duplicates the topmost of two selected items and interpolates the duplicates inbetween. if (app.selection.length == 2) {
var x1 = app.selection[0].geometricBounds[0];
var y1 = app.selection[0].geometricBounds[1];
var x2 = app.selection[1].geometricBounds[0];
var y2 = app.selection[1].geometricBounds[1];
var dx = x2 - x1;
var dy = y2 - y1;
var a = Math.atan2(dy, dx)
var n = +prompt("", "10", "Steps") + 1;
var h = Math.sqrt(dx * dx + dy * dy) / n;
dx = Math.cos(a) * h;
dy = Math.sin(a) * h;
for (var i = 0; i < n - 1; i++) {
x1 += dx;
y1 += dy;
var dup = app.selection[0].duplicate();
dup.selected = false;
dup.position = [x1, y1];
}
app.selection[0].zOrder(ZOrderMethod.BRINGTOFRONT);
}
... View more
‎Apr 13, 2023
09:49 AM
1 Upvote
Sorry for the late reply. I get the same result as Monika in CS6 on Windows. I've never thought about the definition of a "word" in AI, although I would have assumed it would be bound by whitespace.
... View more
‎Apr 11, 2023
01:55 AM
It's not possible with JavaScript. I have no knowledge of AppleScript, but I've hardly seen anyone use it around here.
... View more
‎Apr 11, 2023
01:40 AM
1 Upvote
It's JSDoc annotating JavaScript. Here a list of tags and what they mean.
... View more
‎Apr 10, 2023
01:10 PM
I've tried this a few times, and I didn't get an error. var currentDoc = app.activeDocument;
var woven = [];
for (i = 0; i < app.activeDocument.artboards.length; i++) {
woven.push(app.activeDocument.artboards[i])
}
if (woven.length > 0) {
var wovenDoc = app.documents.add(
DocumentColorSpace.RGB, currentDoc.width, currentDoc.height);
for (i = 0; i < woven.length; i++) {
app.activeDocument = currentDoc;
// copy art
currentDoc.artboards.setActiveArtboardIndex(i);
currentDoc.selectObjectsOnActiveArtboard();
app.copy();
app.selection = [];
// prepare info for new artboard
var boardRect = woven[i].artboardRect;
var boardName = woven[i].name;
// create new board and paste art
app.activeDocument = wovenDoc;
wovenDoc.artboards.add(boardRect);
wovenDoc.artboards[wovenDoc.artboards.length - 1].name = boardName;
wovenDoc.artboards.setActiveArtboardIndex(wovenDoc.artboards.length - 1);
app.executeMenuCommand("pasteInPlace");
}
// a blank artboard was created when the document was added
// it can be removed now.
wovenDoc.artboards[0].remove();
}
... View more
‎Apr 10, 2023
01:00 PM
You can't directly script blending. But you can indirectly do so, through executeMenuCommand. The first line brings up the options window; the second line makes the effect. app.executeMenuCommand("Path Blend Options");
app.executeMenuCommand("Path Blend Make"); If the options are set, you can do without the first line. If you want to set the options, but don't want to interact with the window, and you're on Windows, you can use a temporary VBS script to interact with the window.
... View more
‎Mar 29, 2023
12:02 AM
1 Upvote
I think there is a typo in the script. I think this line for (var i = allGroups.length-1; i > 0; i--) { should be for (var i = allGroups.length-1; i > -1; i--) { For a prompt, change the first line to var searchTexts = [prompt()]; Note that the script will only work with the particular hierarchy that is a text frame within a group.
... View more
‎Mar 28, 2023
11:33 PM
1 Upvote
Were you given this as an Illustrator script? Because, at a glance, it doesn't seem to be. The script doesn't do anything because it doesn't proceed past this line if (swatch.colorType == ColorModel.SPOT && swatch.tint != 100) { because Illustrator swatches don't have such properties as "colorType" and "tint". You can change the line to if (swatch.color.typename == "SpotColor" && swatch.color.tint != 100) { but this brings up errors related to creating a pattern. I've not looked beyond this point because as far as I know—and I'm happy to be corrected on the point—you can't directly create a pattern with a script in Illustrator.
... View more
‎Mar 25, 2023
03:24 PM
// select text frames
main();
function main(){
var frames = app.activeDocument.selection;
var array = [];
for(var i = 0; i < frames.length; i++){
array.push(frames[i]);
};
array.sort(function(a, b) {return a.contents > b.contents;});
sortZOrder(array);
bubbleSortTop(array);
}
function sortZOrder(frames) {
for (var j = 0; j < frames.length; j++) {
frames[j].zOrder(ZOrderMethod.SENDTOBACK);
};
}
function bubbleSortTop(a){
for (var i = a.length - 1; i > 0; i--){
for (var j = 0; j < i; j++){
if (a[j].top < a[j + 1].top){
var temp = a[j].top;
a[j].top = a[j + 1].top;
a[j + 1].top = temp;
}
}
}
return a;
}
... View more