femkeblanco
Guide
femkeblanco
Guide
Activity
‎Feb 06, 2024
01:22 PM
1 Upvote
This snippet will apply an offset effect with the parameters you specified to a selected path. var string = '<LiveEffect name="Adobe Offset Path">' +
'<Dict data="I jntp 0 R mlim 4 R ofst 0.283"/>' +
'</LiveEffect>';
app.selection[0].applyEffect(string);
... View more
‎Jan 31, 2024
03:04 PM
3 Upvotes
I presume "sourceArt" should be a vector item, not a layer.
... View more
‎Jan 31, 2024
05:35 AM
6 Upvotes
Untested. var doc = app.activeDocument;
var items = doc.pathItems;
var text = doc.textFrames;
for (var i = 0; i < items.length; i++) {
var itemBounds = items[i].geometricBounds;
for (var j = text.length - 1; j > -1; j--) {
var textBounds = text[j].geometricBounds;
if ((textBounds[0] > itemBounds[0] && textBounds[0] < itemBounds[2]) &&
(textBounds[1] < itemBounds[1] && textBounds[1] > itemBounds[3])) {
items[i].name = text[j].contents;
text[j].remove();
continue;
}
}
}
... View more
‎Jan 29, 2024
03:31 PM
1 Upvote
I keep it simple. I use "classes" when I want to create many objects with similar properties, for example here. I use inheritance when I have many classes with similar functions, which is admittedly not common. I think there is some value in learning about prototypes, even if you don't use them, because you will come across cool scripts that do. Apart from that, there is the satisfaction of just understanding the concept of prototypes, which many Javascripters don't. (I can't help you with the question about actions. I don't think I have used actions in scripts.)
... View more
‎Jan 29, 2024
03:09 PM
2 Upvotes
Back in CS5, the origin was changed from the left bottom to the left top. So y values should be negative, as in the examples above.
... View more
‎Jan 22, 2024
12:31 PM
3 Upvotes
@tomd75724979 @m1b You're welcome. If you're interested, I found the crouse Ultimate JavaScript Part 2: Advanced Topics by Mosh Hamedani to be the easiest intro to OOP-like JavaScript. The first part of the course is available on YouTube for free, but not the parts on prototypes and prototypal inheritance. Still, you can check to see if it's not too basic for you. The good thing about it is that it uses pre-ES6 JavaScript for the most part, which you can emulate with pollyfills (e.g. Object.create, Object.assign, etc), although there are some things ES3 just can't emulate.
... View more
‎Jan 20, 2024
01:02 PM
2 Upvotes
Object.create is used in defining extend(). If you want to use it directly in the above example, you can use B.prototype = Object.create(A.prototype); instead of extend(B, A); and B will inherit the functions in A's prototype. The pollyfills are used once and go right at the top of the script. Or, you can put them in a separate file with any other pollyfills you regularly use (and access them with #include). Java and JS conventions say that each class should be a separate file, but this can be ignored, of course.
... View more
‎Jan 20, 2024
10:48 AM
3 Upvotes
Most, if not all, of what is in the link you posted works in ES3. All you need is an Object.create polyfill. You can add an extend() function to emulate "class B extends A" in Java and ES6+ (@dolce5EC2 called it inheret()). // polyfills
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
function extend(Child, Parent) {
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;
}
// 1st class
var A = function (p1, p2) {
this.p1 = p1;
this.p2 = p2;
};
A.prototype.f1 = function () {
return "f1 is called by " + this.p1 + this.p2;
};
// 2nd class (using inheritance)
var B = function (p1, p2) {
// this.p1 = p1;
// this.p2 = p2;
// or, call super constructor, A:
A.call(this, p1, p2);
};
extend(B, A); // B inherits A's prototype
// creating objects
var a1 = new A("a", 1);
var b1 = new B("b", 1);
// accessing objects
alert(
a1.f1() /*f1 is called by object1*/
+ "\n" +
b1.f1() /*f1 is called by object2*/
);
... View more
‎Jan 20, 2024
10:36 AM
You're welcome.
... View more
‎Jan 17, 2024
02:24 PM
2 Upvotes
I don't understand what you are trying to do (probably my fault), but from the stackexchange question and answer, I presume you're trying to divide an array of length "l" into sets of a number "n". If so, I think this function should do what you want var l = 6; // length of array
var n = 3; // number of sets
// sets is an array of sets,
// each set being an array of two indices,
// a start and an end
var sets = divideArray(l, n);
alert(sets);
function divideArray(l, n) {
if (n > l) {
alert("n cannot be >l.");
return;
}
var sets = [];
for (var i = 0; i < n; i++) {
var start = Math.floor((i * l) / n);
var end = Math.floor(((i + 1) * l) / n) - 1;
sets.push([start, end]);
}
return sets;
}
... View more
‎Jan 07, 2024
12:52 PM
"readonly" is a property of an object called "properties". So the expression to access it would be "widthLink.properties.readonly". Having said that, it seems to operate exclusively as an argument to add(). It can be overwritten in the next line and it won't do anything. Off the top of my head, there are two workarounds. 1. Remove and recreate the edittext, although this produces an unexpected location, even when the bounds are set. function createWindow() {
var dialog = new Window("dialog", "My Dialog");
var widthLink = dialog.add("edittext", [20, 20, 100, 40], "Initial Text",
{ readonly: true });
var editLinkButton = dialog.add("button", undefined, "Edit");
editLinkButton.onClick = function() {
dialog.remove(widthLink);
widthLink = dialog.add("edittext", [20, 20, 100, 40], "Initial Text",
{ readonly: false });
};
dialog.show();
}
createWindow(); 2. Recreate the window. function createWindow(readonly) {
var dialog = new Window("dialog", "My Dialog");
widthLink = dialog.add("edittext", undefined, "Initial Text",
{ readonly: readonly });
var editLinkButton = dialog.add("button", undefined, "Edit");
editLinkButton.onClick = function() {
dialog.close();
createWindow(false);
};
dialog.show();
}
createWindow(true);
... View more
‎Dec 28, 2023
11:52 AM
I've not read this whole thread, but I assume this is what you want. // select ellipse
var doc = app.activeDocument;
var bounds = doc.selection[0].geometricBounds;
var d1 = (bounds[2] - bounds[0]);
var d2 = -(bounds[3] - bounds[1]);
var x = bounds[0] + d1 / 2;
var y = bounds[1] - d2 / 2;
doc.pathItems.ellipse(
y + ((d2 * 2 / 3) / 2), x - ((d1 * 2 / 3) / 2),
(d1 * 2 / 3), (d2 * 2 / 3));
doc.pathItems.ellipse(
y + ((d2 * 1 / 3) / 2), x - ((d1 * 1 / 3) / 2),
(d1 * 1 / 3), (d2 * 1 / 3));
... View more
‎Dec 26, 2023
06:58 AM
2 Upvotes
I can confirm it exists in CS4 (2008). By the way, has anyone curated a list of all the known bugs?
... View more
‎Dec 25, 2023
08:03 AM
This can be done with Offset path, as suggested by @kphotopage, with a negative offset.
... View more
‎Dec 25, 2023
04:30 AM
Do you mean the order in which the items were selected (which item was selected before/after which)? If so, no, it's not possible.
... View more
‎Dec 24, 2023
03:26 PM
1 Upvote
I agree, it's a bug. If you open two documents and run var docs = app.documents;
docs[0].artboards[0].name = "AB1";
docs[1].artboards[0].name = "AB2"; the artboard in only the top document will change name (i.e. "artboards" points to the same collection).
... View more
‎Dec 19, 2023
10:48 AM
1 Upvote
It think this is because documents.add() adds a document with whatever default width and size, with the origin (0, 0) being the lower left corner of the document. Any change to the origin will be in reference to that lower left corner.
... View more
‎Dec 06, 2023
02:16 PM
1 Upvote
I have not seen a ready-made script. There's a well known algorithm out there to find the intersection of two cubic Bezier curvese (the Bezier subdivision algorithm), but it is not simple, and it will take some work to write it into a script.
... View more
‎Dec 05, 2023
12:13 PM
@Disposition_Dev I would be interested in this too. Please post it if you find it. Thanks in advance.
... View more
‎Dec 05, 2023
12:15 AM
The total area of a fill color could be obtained with a script, but this will not include strokes.
... View more
‎Dec 03, 2023
02:26 PM
1 Upvote
system.callSystem() in After Effects seems to run a command line, as if run in the system's command line interface. I have not seen such thing in Illustrator scripting. Instead, what are you trying to get the command line to do?
... View more
‎Dec 01, 2023
01:12 AM
Should <\/?[strong]> have the escape character? If so, it will need an escape character for the escape character.
... View more
‎Dec 01, 2023
12:52 AM
1 Upvote
@m1b Very nice. Makes more sense than my way.
... View more
‎Nov 30, 2023
12:36 PM
2 Upvotes
There may be an easier way, but this is what came to me intuitively. Not extensively tested. // select textFrame
var string1 = app.selection[0].textRange.contents;
var regex = /<b>|<\/b>|<i>|<\/i>/g;
// create array of attributes of characters
var textRanges = app.selection[0].textRanges;
var attributes = [];
for (var i = 0; i < textRanges.length; i++) {
var o = {};
o.textFont = textRanges[i].characterAttributes.textFont;
o.size = textRanges[i].characterAttributes.size;
attributes.push(o);
}
// create array of indices of to-be-removed substrings
var indices = [];
for (var i = regex.exec(string1); i != null; i = regex.exec(string1)) {
var o = {};
o.start = i.index;
if (i == "<b>" || i == "<i>") o.n = 3;
else o.n = 4;
indices.push(o);
}
// remove attributes of to-be-removed substrings
for (var i = indices.length - 1; i > -1; i--) {
attributes.splice(indices[i].start, indices[i].n)
}
// remove substrings
var string2 = string1.replace(regex, "");
app.selection[0].contents = string2;
// re-assign attributes to characters
for (var i = 0; i < textRanges.length; i++) {
textRanges[i].characterAttributes.textFont = attributes[i].textFont;
textRanges[i].characterAttributes.size = attributes[i].size;
}
... View more
‎Nov 27, 2023
01:07 PM
1 Upvote
Pretty smart.
... View more
‎Nov 26, 2023
10:22 AM
What do you want the script to do?
... View more
‎Nov 22, 2023
11:11 AM
Are the items to be removed top level items or children of top level items that are themselves to be removed? Or could they be children of items not to be removed (e.g. the header or part of the header grouped with spec)? It will make a difference for a script having to iterate top level items vs. having to iterate all items in a doc, in particular if this is going to be multiplied by many docs.
... View more
‎Nov 20, 2023
02:50 PM
I had this once. Restarting the PC solved it.
... View more