如何使用 Basil.js 将 InDesign 中的字符样式与笔画链接起来
我想将字符样式与笔画链接起来,但我不知道如何开始。我有这个只是绘制一条随机线,但我希望该线链接所有字符样式:
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
function draw() {
var selItems = b.selections(); // get all selected items
var textFrame1 = selItems[0]; // the first textframe
var textFrame2 = selItems[1]; // the second textframe
var words1 = b.words(textFrame1);
var words2 = b.words(textFrame2);
b.layer("generatedLines"); // get or create this layer and set it as the active one
b.strokeWeight(1); // we like hairs
for(var i = 0; i < words1.length; i++){ // for each word
var w1 = words1[i]; // current word from the first textframe
// nested for-loop, connect each word with all other words of other textframe
for(var j = 0; j < words2.length; j++){
var w2 = words2[j]; // the current word from the second textframe
b.line(
// add half of the width and height to make sure the lines are centered
b.bounds(w1).left + b.bounds(w1).width / 2,
b.bounds(w1).top + b.bounds(w1).height / 2,
b.bounds(w2).left + b.bounds(w2).width / 2,
b.bounds(w2).top + b.bounds(w2).height / 2
);
}
}
}
b.go();
I would like to link character styles with a stroke but I don't know how to begin. I have this that just draws a random line, but I would like the line to link all the character styles :
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
function draw() {
var selItems = b.selections(); // get all selected items
var textFrame1 = selItems[0]; // the first textframe
var textFrame2 = selItems[1]; // the second textframe
var words1 = b.words(textFrame1);
var words2 = b.words(textFrame2);
b.layer("generatedLines"); // get or create this layer and set it as the active one
b.strokeWeight(1); // we like hairs
for(var i = 0; i < words1.length; i++){ // for each word
var w1 = words1[i]; // current word from the first textframe
// nested for-loop, connect each word with all other words of other textframe
for(var j = 0; j < words2.length; j++){
var w2 = words2[j]; // the current word from the second textframe
b.line(
// add half of the width and height to make sure the lines are centered
b.bounds(w1).left + b.bounds(w1).width / 2,
b.bounds(w1).top + b.bounds(w1).height / 2,
b.bounds(w2).left + b.bounds(w2).width / 2,
b.bounds(w2).top + b.bounds(w2).height / 2
);
}
}
}
b.go();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是如何在文档第一页上绘制文本线条的示例:
但它不使用
basiljs
库。如果你需要处理很多页面,我认为也可以做到。但这需要更多的编码。
更新
这是处理多个页面的脚本版本:
Here is example how you can draw the lines for the texts on the first page of your document:
It doesn't use
basiljs
library though.If you need to handle many pages, I think it can be done as well. But it will require more coding.
Update
Here is a version of the script that handles many pages: