添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I wrote a script in JavaScript for Adobe Illustrator CC 2017. In this script I am trying to add artboard to the document in function, but it isn't working.

Here code:

function addArtboard() {
    var doc = app.documents.add(null,1000,1000);
    doc = app.activeDocument;
    var artboards = doc.artboards;
     artboards.add([0 , 0, 1000, 1000]);
addArtboard();

Your problems seems to be the measurement of your new artboard. Take a look into the scripting guide here .

The add method takes an artboardRect as argument.

The code below creates a new doc and adds an artboard next to the first one.

/* global app, $ */
function addArtboard() {
  var doc = app.documents.add(); // create a doc with defaults
  var firstArtBoard = doc.artboards[0]; // get the default atboard
    // inspect its properties
  for(var prop in firstArtBoard) {
    // exclude protptypes
    if(firstArtBoard.hasOwnProperty(prop)) {
      $.writeln(prop);
  // there is a rect property
  // take a look at the values
  $.writeln(firstArtBoard.artboardRect);
  // create a artboard with the same size and an
  // offset of 5 points to the right
  var x1 = firstArtBoard.artboardRect[2] + 10;
  var y1 = firstArtBoard.artboardRect[1];
  var x2 = x1 + firstArtBoard.artboardRect[2];
  var y2 = firstArtBoard.artboardRect[3];
  doc.artboards.add([x1, y1, x2, y2]);
addArtboard();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.