Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

javascript - 如何使用Java Script在Illustrator中编号对象?(How to number objects in illustrator using Java Script?)

在此处输入图片说明 I am very new to java script, I would like to number each object in illustrator using Java Script.

(我是Java脚本的新手,我想使用Java Script为Illustrator中的每个对象编号。)

Here is what I got so far, but that crashed Illustrator.

(这是到目前为止我得到的,但是使Illustrator崩溃了。)

I am trying to select several objects and beside each object a horizontal line with a number on the top for each.

(我正在尝试选择几个对象,然后在每个对象旁边选择一条水平线,并在顶部为每个对象添加数字。)

var selectedObjects = app.activeDocument.selection;
var selectedObjects = app.activeDocument.selection;
var doc = app.activeDocument;
var markLayer = app.activeDocument.layers.add()

if (selectedObjects.length > 0) {


  for (i = 0; i < selectedObjects.length; i++) {

    function makemark() {
      var group = doc.groupItems.add()
      var hline = group.pathItems.add()
      hline.setEntirePath([
        [-9, 0],
        [9, 0]
      ])
      stylepath(hline)
      return group
    }

    function stylepath(path) {
      var magenta = new CMYKColor()
      magenta.magenta = 100
      path.stroked = true
      path.strokeColor = magenta
      path.strokeCap = StrokeCap.ROUNDENDCAP
      path.opacity = 100
      path.strokeWidth = 1.5
    }


    var i = 0
    var bounds = selectedObjects[i].geometricBounds;



    var left = bounds[0]
    var top = bounds[1]
    var right = bounds[2]
    var bottom = bounds[3]


    var width = right - left
    var height = bottom - top


    var mark3 = makemark()
    mark3.position = [right + 18, top - height * -1 / 2 - 12]


    var myDocument = app.activeDocument;
    var myTextFrame = myDocument.textFrames.add();
    var range = myTextFrame.textRange;
    var attributes = range.characterAttributes;
    myTextFrame.position = [right + 28, top - height * -1 / 2 + 12];
    myTextFrame.contents = i + 1
    var magenta = new CMYKColor()
    magenta.magenta = 100
    attributes.fillColor = magenta;
    attributes.capitalization = FontCapsOption.ALLCAPS;
    attributes.size = 12
  }
} else {
  alert("Please Select At Least One Object");
}

I would appreciate your help.

(多谢您的协助。)

  ask by user8033911 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...