femkeblanco
Guide
femkeblanco
Guide
Activity
‎Jul 09, 2024
01:55 PM
1 Upvote
There seems to be just three or four active posts per day on average, sometimes just one to two, and even these are oftentimes just bumped old posts. Scripters who were active when I started frequenting this forum during the pandemic seem to have gone for good. Those still around seem to be posting less and less. Has ChatGPT rendered the scripting section no longer useful? Is everything that's possible with Illustrator scripting been done, and there is nothing more to add? Is it the lack of investment in Illustrator scripting? But the main point of this post is to ask if scripters, and people looking for scripting help, have gone elsewhere? I know there is a general "Coding Corner" community, but that seems to be even less active than here.
... View more
‎Jun 10, 2024
02:34 PM
1 Upvote
You can access @CarlosCanto's link through Wayback Machine (if it's not blocked by your ISP): http://web.archive.org/web/20141209031628/http://forums.adobe.com/message/5004635
... View more
‎Jun 04, 2024
03:51 PM
1 Upvote
I don't know if this will help you, but applying the default graphic style will give the rectangle a visible stroke. app.activeDocument.graphicStyles[0].applyTo(rect);
... View more
‎May 13, 2024
11:12 AM
So the only difference is that iterating and checking layers is no longer required, all the text frames being in one layer in the source (excel data) and target (artwork)? If so, see if this works (I've added two lines, 95 and 96, and commented-out the loop and conditional immediately below): function showDialog() {
var dialog = new Window(
'dialog',
'Copy/Paste Text between Illustrator File(s)'
);
dialog.alignChildren = 'fill';
dialog.alignChildren = 'left';
// Panel for template file selection
var templateFilePanel = dialog.add('panel', undefined, '');
templateFilePanel.add('statictext', undefined, 'Template File:');
templateFilePanel.orientation = 'row';
var templateFilePathInput = templateFilePanel.add('edittext', undefined, '', {
readonly: true
});
templateFilePathInput.size = [302, 20];
var templateFileBrowseBtn = templateFilePanel.add(
'button',
undefined,
'Browse'
);
templateFileBrowseBtn.onClick = function() {
var file = File.openDialog('Select the Template File', '*.ai', false);
if (file) {
templateFilePathInput.text = file.fsName;
}
};
// Panel for data file selection
var dataFilePanel = dialog.add('panel', undefined, '');
dataFilePanel.add('statictext', undefined, 'Data File:');
dataFilePanel.orientation = 'row';
var dataFilePathInput = dataFilePanel.add('edittext', undefined, '', {
readonly: true
});
dataFilePathInput.size = [330, 20];
var dataFileBrowseBtn = dataFilePanel.add('button', undefined, 'Browse');
dataFileBrowseBtn.onClick = function() {
var file = File.openDialog('Select the Data File', '*.ai', false);
if (file) {
dataFilePathInput.text = file.fsName;
}
};
// Panel for output folder selection
var outputPanel = dialog.add('panel', undefined, '');
outputPanel.add('statictext', undefined, 'Select Folder to Save New File:');
outputPanel.orientation = 'row';
var outputPathInput = outputPanel.add('edittext', undefined, '', {
readonly: true
});
outputPathInput.size = [210, 20];
var outputBrowseBtn = outputPanel.add('button', undefined, 'Browse');
outputBrowseBtn.onClick = function() {
var folder = Folder.selectDialog('Select Folder to Save New File');
if (folder) {
outputPathInput.text = folder.fsName;
}
};
// Dialog buttons
var buttonGroup = dialog.add('group');
buttonGroup.alignment = 'center';
buttonGroup.add('button', undefined, 'OK', { name: 'ok' });
buttonGroup.add('button', undefined, 'Cancel', { name: 'cancel' });
if (dialog.show() === 1) {
// User clicked OK
return {
dataFilePath: dataFilePathInput.text,
templateFilePath: templateFilePathInput.text,
outputPath: outputPathInput.text
};
} else {
return null; // User clicked Cancel or closed the dialog
}
}
// Function to copy data from source to target based on layer names
function transferData(source, target) {
// Create a dictionary to check target layers quickly
var targetLayerNames = {};
for (var k = 0; k < target.layers.length; k++) {
targetLayerNames[target.layers[k].name] = target.layers[k];
}
var sourceLayer = source.layers["excel data"];
var targetLayer = target.layers["artwork"];
// Iterate over each layer in the source document
// for (var i = 0; i < source.layers.length; i++) {
// var sourceLayer = source.layers[i];
// Check if the layer exists in the target document by looking up the dictionary
// if (targetLayerNames.hasOwnProperty(sourceLayer.name)) {
// var targetLayer = targetLayerNames[sourceLayer.name];
// Iterate over each text frame in the source layer
for (var j = 0; j < sourceLayer.textFrames.length; j++) {
if (j < targetLayer.textFrames.length) {
// Copy text from source to target if corresponding text frame exists
var sourceText = sourceLayer.textFrames[j];
var targetText = targetLayer.textFrames[j];
targetText.contents = sourceText.contents;
} else {
// Log error or information when source has more text frames than target
$.writeln(
"Info: Additional text frame in source layer '" +
sourceLayer.name +
"' at position " +
j +
' has no corresponding frame in target.'
);
}
}
// } else {
// // Log information when no corresponding layer is found in the target document
// $.writeln(
// "Info: No corresponding layer found in target for source layer '" +
// sourceLayer.name +
// "'. Layer ignored."
// );
// }
// }
}
function main() {
var fileSelections = showDialog();
if (fileSelections) {
var dataDoc = app.open(File(fileSelections.dataFilePath)); // Open the selected data file
var templateDoc = app.open(File(fileSelections.templateFilePath)); // Open the selected template file
transferData(dataDoc, templateDoc); // Run the transfer function
// Save the new document
var dataFileName = decodeURI(File(fileSelections.dataFilePath).name);
// To save as 'templateFileName_dataFileName.ai'
var templateFileName = decodeURI(
File(fileSelections.templateFilePath).name
);
var newFileName = templateFileName.replace('.ai', '') + '_' + dataFileName;
// // To save as 'dataFileName.ai_Output'
// var newFileName = dataFileName.replace('.ai', '') + '_Output';
var saveFile = new File(fileSelections.outputPath + '/' + newFileName);
templateDoc.saveAs(saveFile);
templateDoc.close();
dataDoc.close();
alert('Data successfully transferred and file saved as: \n' + newFileName);
}
}
main();
... View more
‎May 04, 2024
02:37 PM
1 Upvote
// select an object
var doc = app.activeDocument;
var ABR = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect;
doc.selection[0].position = [
(ABR[0] + ((ABR[2] - ABR[0]) / 2)) - (doc.selection[0].width / 2),
(ABR[1] + ((ABR[3] - ABR[1]) / 2)) + (doc.selection[0].height / 2)
];
... View more
‎May 03, 2024
03:33 PM
1 Upvote
The spirograph part can be created with a simple script. Select a circle (the count can be changed in the first line): var count = 25;
var doc = app.activeDocument;
var source = doc.selection[0];
var r = source.width / 2;
var first = doc.pathItems.ellipse(source.top - r / 2, source.left, r, r);
first.stroked = true;
first.filled = false;
for (var i = 0; i < count; i++) {
var duple = first.duplicate();
duple.rotate(360 / count * (i + 1), undefined, undefined, undefined, undefined,
Transformation.RIGHT);
} I can't find a formula for the concentric circles.
... View more
‎May 02, 2024
05:27 AM
1 Upvote
Unnamed items are an empty string (""), not undefined.
... View more
‎Apr 30, 2024
04:58 PM
1 Upvote
Demo: var doc = app.activeDocument;
// create flag
var flag = createFlag();
// create text
var index = createText(
"FLORIDA", doc.width / 2, -doc.height / 2, 72, "Myriad-Bold");
var index = index.createOutline();
var repeats = doc.groupItems.add();
repeat(0.5, 0);
repeat(0.75, 0.5);
repeat(0.875, 0.75);
repeat(-0.5, -0);
repeat(-0.75, -0.5);
repeat(-0.875, -0.75);
// cleate clipping set
var compoundPath = doc.compoundPathItems.add();
index.moveToEnd(compoundPath);
repeats.moveToEnd(compoundPath);
compoundPath.selected = true;
flag.selected = true;
app.executeMenuCommand("makeMask");
function createFlag() {
var w = doc.width / 4, h = doc.height / 2, y = - doc.height / 2 + h / 2;
function createRect(x, red, blue) {
var rect = doc.pathItems.rectangle(y, x, w, h);
var color = new RGBColor;
color.red = red;
color.blue = blue;
rect.fillColor = color;
return rect;
}
var flag = doc.groupItems.add();
createRect(doc.width / 2 - w, 255, 0).moveToEnd(flag);
createRect(doc.width / 2, 0, 255).moveToEnd(flag);
return flag;
}
function createText(contents, x, y, fontSize, textFont) {
var textFrame = doc.textFrames.pointText( [x, y] );
textFrame.contents = contents;
textFrame.textRange.size = fontSize;
textFrame.textRange.textFont = textFonts[textFont];
textFrame.textRange.justification = Justification.CENTER;
return textFrame;
}
function repeat(value1, value2) {
var members = [];
for (var i = index.pageItems.length - 1; i > -1; i--) {
var duple = index.pageItems[i].duplicate(index, ElementPlacement.PLACEAFTER);
members.push(duple);
}
for (var i = 0; i < members.length; i++) {
members[i].translate(0, members[i].height * value1);
var rect = doc.pathItems.rectangle(
index.top, index.left, index.width, index.height);
rect.translate(0, rect.height * value2);
rect.selected = members[i].selected = true;
app.executeMenuCommand("group");
app.executeMenuCommand("Live Pathfinder Subtract");
app.executeMenuCommand("expandStyle");
app.executeMenuCommand("ungroup");
rect.remove();
for (var j = app.selection.length - 1; j > -1; j--) {
app.selection[j].moveToEnd(repeats);
}
app.selection = null;
}
}
... View more
‎Apr 30, 2024
01:18 PM
1 Upvote
Note that "the first selected object" refers to the topmost of the two selected objects. (If this doesn't have a rotation tag, an error will occur.) If you want it the other way around, swap the 0 and 1 in doc.selection[0] and doc.selection[1]. // Check if a document is open in Illustrator
if (app.documents.length > 0) {
// Get the active document
var doc = app.activeDocument;
// Check if exactly two objects are selected
if (doc.selection.length == 2) {
// Get the first and second selected objects
var selectedObject1 = doc.selection[0];
var selectedObject2 = doc.selection[1];
// Get the rotation angle of the first selected object
var rotationAngle = selectedObject1.pathItems[0].tags[0].value * 180 / Math.PI;
// Apply opposite rotation angle to the second selected object
selectedObject2.rotate(-rotationAngle);
} else {
alert("Please select exactly two objects in Illustrator.");
}
} else {
alert("Please open a document in Illustrator.");
}
... View more
‎Apr 29, 2024
12:26 PM
I think a group doesn't have a BBAccumRotation tag , but paths within a group do. Assuming that paths within a group will have the same tag, you can access the first one (selection[0] is a selected group): alert(app.selection[0].pathItems[0].tags[0].name + ": \
" + app.selection[0].pathItems[0].tags[0].value * 180 / Math.PI); (Courtesy of Silly-V).
... View more
‎Apr 14, 2024
02:01 PM
2 Upvotes
‎Apr 14, 2024
01:54 PM
1 Upvote
Yes, there is a way. How you do it depends on whether "c" is a sublayer or an item (for example, a group item). var doc = app.activeDocument;
var source = doc.layers["Layer 1"];
var goal = doc.layers["Layer 2"];
source.layers["Sublayer"].move(goal, ElementPlacement.PLACEATEND);
source.pageItems["Group"].move(goal, ElementPlacement.PLACEATEND);
... View more
‎Mar 31, 2024
04:00 PM
2 Upvotes
function drawHeatmapBox (values) {
var doc = app.activeDocument;
// box
var boxWidth = values.length;
var boxHeight = 100;
var rect = doc.pathItems.rectangle(- 100, 100, boxWidth, boxHeight);
rect.stroked = true;
rect.strokeWidth = 1;
// columns
for (var i = 0; i < values.length; i++) {
var color = new GrayColor();
color.gray = values[i] * 100;
var column = doc.pathItems.rectangle(- 100, 100 + i, 1, boxHeight);
column.stroked = false;
column.fillColor = color;
}
}
var values = [0.98, 0.99, 0.06, 0.07];
drawHeatmapBox (values)
... View more
‎Mar 01, 2024
02:23 AM
I've not looked into it in any detail, but my understanding is that JSX is transpiled into JS anyway, so there should be no disadvantage of using JS.
... View more
‎Feb 28, 2024
02:44 PM
I can't replicate the problem What about removing this line: app.redraw();
... View more
‎Feb 28, 2024
10:11 AM
3 Upvotes
// select text frames
var doc = app.activeDocument;
var contents = [];
for (var i = 0; i < doc.selection.length; i++) {
contents.push(doc.selection[i].contents);
}
for (var i = 0; i < doc.selection.length; i++) {
var index = Math.floor(Math.random() * contents.length);
doc.selection[i].contents = contents[index];
contents.splice(index, 1);
}
... View more
‎Feb 28, 2024
12:40 AM
I already had the main part (the part that draws the tiling) from before, so I felt close to the end result. But there was no applicable logic to generate the colors; most of the time was spent inputting the colors by hand. It took just over an hour.
... View more
‎Feb 27, 2024
12:18 PM
4 Upvotes
var d = 15; // tile width (points)
var colors = [
"999999", "CCCCCC", "FFFFFF", "000000", "333333", "666666", "CCFF99", "FFFFCC",
"FFCC99", "FFCCCC", "FF99CC", "FFCCFF", "CC99FF", "CCCCFF", "99CCFF", "CCFFFF",
"99FFCC", "CCFFCC", "99CC66", "CCCC99", "FFFF99", "CC9966", "CC9999", "FF9999",
"CC6699", "CC99CC", "FF99FF", "9966CC", "9999CC", "9999FF", "6699CC", "99CCCC",
"99FFFF", "66CC99", "99CC99", "99FF99", "669933", "999966", "CCCC66", "FFFF66",
"996633", "996666", "CC6666", "FF6666", "993366", "996699", "CC66CC", "FF66FF",
"663399", "666699", "6666CC", "6666FF", "336699", "669999", "66CCCC", "66FFFF",
"339966", "669966", "66CC66", "66FF66", "336600", "666633", "999933", "CCCC33",
"FFFF33", "663300", "663333", "993333", "CC3333", "FF3333", "660033", "663366",
"993399", "CC33CC", "FF33FF", "330066", "333366", "333399", "3333CC", "3333FF",
"003366", "336666", "339999", "33CCCC", "33FFFF", "006633", "336633", "339933",
"33CC33", "33FF33", "66CC00", "333300", "666600", "999900", "CCCC00", "FFFF00",
"CC6600", "330000", "660000", "990000", "CC0000", "FF0000", "CC0066", "330033",
"660066", "990099", "CC00CC", "FF00FF", "6600CC", "000033", "000066", "000099",
"0000CC", "0000FF", "0066CC", "003333", "006666", "009999", "00CCCC", "00FFFF",
"00CC66", "003300", "006600", "009900", "00CC00", "00FF00", "99FF33", "CCFF66",
"99CC33", "669900", "996600", "CC9933", "FFCC66", "FF9933", "FF9966", "CC6633",
"993300", "990033", "CC3366", "FF6699", "FF3399", "FF66CC", "CC3399", "990066",
"660099", "9933CC", "CC66FF", "9933FF", "9966FF", "6633CC", "330099", "003399",
"3366CC", "6699FF", "3399FF", "66CCFF", "3399CC", "006699", "009966", "33CC99",
"66FFCC", "33FF99", "66FF99", "33CC66", "009933", "339900", "66CC33", "99FF66",
"99FF00", "CCFF00", "CCFF33", "99CC00", "CC9900", "FFCC33", "FFCC00", "FF9900",
"FF6600", "FF3300", "FF6633", "CC3300", "CC0033", "FF3366", "FF0033", "FF0066",
"FF0099", "FF00CC", "FF33CC", "CC0099", "9900CC", "CC33FF", "CC00FF", "9900FF",
"6600FF", "3300FF", "6633FF", "3300CC", "0033CC", "3366FF", "0033FF", "0066FF",
"0099FF", "00CCFF", "33CCFF", "0099CC", "00CC99", "33FFCC", "00FFCC", "00FF99",
"00FF66", "00FF33", "33FF66", "00CC33", "33CC00", "66FF33", "33FF00", "66FF00"
];
var doc = app.activeDocument;
var centres = [];
var hexagon = draw(doc.width / 2, -doc.height / 2);
hexagon.filled = false;
for (var i = 0; i < 8; i++) {
var replica = hexagon.duplicate();
replica.resize(100 * (i + 1) * Math. sqrt(3), 100 * (i + 1) * Math. sqrt(3));
replica.rotate(-90);
for (var j = 0; j < replica.pathPoints.length; j++) {
centres.push(replica.pathPoints[j].anchor);
if (j + 1 < replica.pathPoints.length) {
centres = centres.concat(findMidPoints(
replica.pathPoints[j].anchor, replica.pathPoints[j + 1].anchor, i));
} else {
centres = centres.concat(findMidPoints(
replica.pathPoints[j].anchor, replica.pathPoints[0].anchor, i));
}
}
replica.remove();
}
for (var i = 0; i < centres.length; i++) {
var hexagon = draw(centres[i][0], centres[i][1]);
var RGB = hexToRGB(colors[i]);
var color = new RGBColor();
color.red = RGB[0], color.green = RGB[1], color.blue = RGB[2];
hexagon.fillColor = color;
addText(centres[i], colors[i], RGB);
}
function draw(x, y) {
return doc.pathItems.polygon(x, y, d, 6);
}
function findMidPoints(p1, p2, n) {
if (n == 0) return [];
var midPoints = [];
var dX = p2[0] - p1[0];
var dY = p2[1] - p1[1];
for (var i = 1; i <= n; i++) {
var x = p1[0] + i * dX / (n + 1);
var y = p1[1] + i * dY / (n + 1);
midPoints.push([x, y]);
}
return midPoints;
}
function hexToRGB(hex){
return [parseInt(hex.substr(0,2), 16),
parseInt(hex.substr(2,2), 16),
parseInt(hex.substr(4,2), 16)]
}
function addText(point, contents1, contents2) {
var text = doc.textFrames.pointText([point[0], point[1] + d / 4]);
text.contents = contents1 + "\n" + contents2;
text.textRange.textFont = textFonts["ArialMT"];
text.textRange.size = d / 4;
text.textRange.justification = Justification.CENTER;
}
... View more
‎Feb 25, 2024
03:28 PM
It should be doable with a script. If I have time in the next couple of days, I'll look into it.
... View more
‎Feb 25, 2024
10:16 AM
1 Upvote
See if this helps: https://community.adobe.com/t5/illustrator-discussions/is-there-a-way-or-a-script-to-smooth-out-convex-corners-only-not-concave-corners-of-a-closed-curve/m-p/14401773#M396240
... View more
‎Feb 22, 2024
12:46 PM
As far as I know, the latest JavaScript reference is the 2021 one (which is in @CarlosCanto's second link), which is not that different from the ones before it, going all the way back to 2013.
... View more
‎Feb 20, 2024
03:43 PM
If the purpose is not to save changes to the first file, you can just save a second file under another name. I've added a line (line 46) that adds the word "Copy" to the second file. var w = new Window("dialog", "Choose a Preset");
var dropdownlist = w.add("dropdownlist", undefined, app.PDFPresetsList);
dropdownlist.preferredSize.width = 200;
dropdownlist.selection = 0;
var choice = dropdownlist.selection;
dropdownlist.onChange = function() {
choice = dropdownlist.selection;
};
var button = w.add("button", undefined, "OK");
button.onClick = function() {
saveDocsAsPDF(choice);
w.close();
};
w.show();
function saveDocsAsPDF(choice) {
// original SaveDocsAsPDF script
try {
if (app.documents.length > 0) {
var destFolder = null;
destFolder = Folder.selectDialog('Select folder for PDF files.', '~');
if (destFolder != null) {
var options, i, sourceDoc, targetFile;
options = getOptions();
for (i = 0; i < app.documents.length; i++) {
sourceDoc = app.documents[i];
targetFile = getTargetFile(sourceDoc.name, '.pdf', destFolder);
sourceDoc.saveAs(targetFile, options);
}
alert('Documents saved as PDF');
}
} else {
throw new Error('There are no document open!');
}
} catch (e) {
alert(e.message, "Script Alert", true);
}
function getOptions() {
var options = new PDFSaveOptions();
options.pDFPreset = choice;
return options;
}
function getTargetFile(docName, ext, destFolder) {
ext = " - Copy" + ext;
var newName = "";
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}
var myFile = new File(destFolder + '/' + newName);
if (myFile.open("w")) {
myFile.close();
} else {
throw new Error('Access is denied');
}
return myFile;
}
}
... View more
‎Feb 18, 2024
01:25 PM
Without a runnable snippet of code and the file causing the error, your chances of an answer are slim.
... View more
‎Feb 14, 2024
03:43 PM
1 Upvote
Why would you expect anyone to help you if you're rude to the first person who tries?
... View more
‎Feb 14, 2024
03:30 PM
2 Upvotes
Not extensively tested, and not tested with sizeable text. "ouput" is an array of the left-most and right-most characters. You can access their position properties. // select 1 textFrame
var doc = app.activeDocument;
var frames = doc.selection[0];
var replica = frames.duplicate(frames, ElementPlacement.PLACEAFTER);
var item = replica.createOutline();
var objects = [];
for (var i = 0; i < item.pageItems.length; i++) {
objects.push(item.pageItems[i]);
}
item.remove();
var temp = [];
for (var i = 0, counter = 1; i < objects.length; i += counter) {
counter = 1;
var row = [];
row.push(objects[i]);
for (var j = i + 1; j < objects.length; j++) {
if (horizontalOverlap(objects[i], objects[j])) {
row.push(objects[j]);
counter++;
}
}
temp.push(row);
}
function horizontalOverlap(obj1, obj2) {
var top1 = obj1.geometricBounds[1];
var bottom1 = obj1.geometricBounds[3];
var top2 = obj2.geometricBounds[1];
var bottom2 = obj2.geometricBounds[3];
return ((top1 >= top2 && bottom1 <= top2) ||
(top1 <= top2 && top1 >= bottom2));
}
// "ouput" is an array of the left-most and right-most chars
var output = [];
for (var i = 0; i < temp.length; i++) {
temp[i].sort(function (a, b) {return a.left - b.left});
output.push(temp[i][0]);
output.push(temp[i][temp[i].length - 1]);
}
// e.g. of using "ouput", marking the positions of its elements (with red dots)
for (var i = 0; i < output.length; i++) {
var d = 5;
var item = doc.pathItems.ellipse(
output[i].position[1] + 5/2, output[i].position[0] - d/2, d, d);
var color1 = new RGBColor;
color1.red = 255;
color1.green = color1.blue = 0;
item.stroked = false;
item.fillColor = color1;
}
... View more
‎Feb 09, 2024
06:13 PM
1 Upvote
It can easily be modified to sort in zOrder. var doc = app.activeDocument;
var paths = doc.pathItems;
var array1 = [];
for (var i = 0; i < paths.length; i++) {
array1.push(paths[i]);
}
array1.sort(function(a, b) {
return b.fillColor.spot.color.black - a.fillColor.spot.color.black;
})
bubbleSort(array1);
function bubbleSort(a){
for (var i = a.length-1; i > 0; i--){
for (var j = 0; j < i; j++){
if (a[j].zOrderPosition > a[j+1].zOrderPosition){
a[j].move(a[j+1], ElementPlacement.PLACEAFTER);
}
}
}
}
... View more
‎Feb 09, 2024
01:58 PM
3 Upvotes
Here's a simple snippet that sorts paths horizontally based on the black value of the fill. var doc = app.activeDocument;
var paths = doc.pathItems;
var array1 = [];
for (var i = 0; i < paths.length; i++) {
array1.push(paths[i]);
}
array1.sort(function(a, b) {
return b.fillColor.spot.color.black - a.fillColor.spot.color.black;
})
bubbleSort(array1);
function bubbleSort(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;
}
}
}
}
... View more
‎Feb 09, 2024
01:11 PM
Sorting shouldn't be a problem. How are you converting a color to grayscale?
... View more
‎Feb 09, 2024
12:58 PM
As requested, try this for polygons other than rectangles. This should work for the text frame whose centre lies within the path (without depending on the bounding boxes). var doc = app.activeDocument;
var items = doc.pathItems;
var text = doc.textFrames;
for (var i = items.length - 1; i > -1; i--) {
for (var j = text.length - 1; j > -1; j--) {
var textBounds = text[j].geometricBounds;
var centre = [
textBounds[0] + ((textBounds[2] - textBounds[0]) / 2),
textBounds[1] + ((textBounds[3] - textBounds[1]) / 2)
];
if (pointIsInPoly(items[i].pathPoints, centre)) {
items[i].name = text[j].contents;
text[j].remove();
continue;
}
}
}
// Jonas Raoni Soares Silva
// http://jsfromhell.com/math/is-point-in-poly
function pointIsInPoly(poly, pt){
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i].anchor[1] <= pt[1] && pt[1] < poly[j].anchor[1]) ||
(poly[j].anchor[1] <= pt[1] && pt[1] < poly[i].anchor[1]))
&&
(pt[0] <
(poly[j].anchor[0] - poly[i].anchor[0]) * (pt[1] - poly[i].anchor[1]) /
(poly[j].anchor[1] - poly[i].anchor[1]) + poly[i].anchor[0])
&&
(c = !c);
return c;
}
... View more
‎Feb 06, 2024
02:10 PM
1 Upvote
"jntp" is the join type of 0 (0 round, 1 bevel and 2 miter). "mlim" is the miter limit of 4. "ofst" is the offset of 0.283 points (or 0.1 mm); this can be a negative value.
... View more