【问题标题】:How to create Rectangle object required by add method of the artboards object in Illustrator CS5.1+?如何在 Illustrator CS5.1+ 中创建画板对象的 add 方法所需的 Rectangle 对象?
【发布时间】:2016-09-13 00:41:14
【问题描述】:

我正在尝试借助 java 脚本添加新的画板。我无法在任何地方找到解决方案。 adobe 的脚本指南很差(不使用更强烈的词)。

无论我尝试什么都会返回错误:

错误 1242:非法参数 - 参数 1 - 应为矩形值

当我使用来自其他画板的 artboard.artboardRect 值时,它会在同一位置创建画板,但我无法修改它(调整大小),这使得该选项无用。

artboards.add(artboards[0].artboardRect);//works
artboards.add([0,0,200,50]);//Error 1200: an Illustrator error coccurred: 1346458189('PARAM')
var rect = artboards[0].artboardRect;
rect[0] = 0;
rect[1] = 0;
rect[2] = 200;
rect[3] = 50;
artboards.add(rect);//Error 1242: Illegal argument - argument 1 - Rectangle value expected

【问题讨论】:

    标签: javascript adobe-illustrator


    【解决方案1】:

    经过广泛搜索后,我发现了这个解决方法:

    var newRect = function(x, y, width, height) {
        var l = 0;
        var t = 1;
        var r = 2;
        var b = 3;
    
        var rect = [];
    
        rect[l] = x;
        rect[t] = -y;
        rect[r] = width + x;
        rect[b] = -(height - rect[t]);
    
        return rect;
    };
    
    artboard = artboards.add(artboards[0].artboardRect);
    artboard.name = "new name";
    artboard.artboardRect = newRect(0, 0, 200, 50);
    

    【讨论】:

    • Adobe 的文档很垃圾。这应该是本机方法。感谢您提供此信息。
    【解决方案2】:

    Illustrator Scripting PDFs rectsomeOtherPropRect 的几个地方被定义为“4 个数字的数组”。例如,

    var document = app.documents.add();
    $.writeln(document.artboards[0].artboardRect); // 0,792,612,0
    

    返回值对应topLeftX, topLeftY, bottomRightX, bottomRightY

    要理解这些值,我们需要看一下 Illustrator 的坐标系统。 Illustrator 的 UI 使用 modified coordinate system,而不是实际的 cartesian one。换句话说,屏幕的左上角是原点,而不是左下角。但是在编写脚本时,使用的是实际的笛卡尔坐标系。

    由于坐标系的这种差异,Y 轴上的输入值应该是负值。所以,如果我想重新定位和调整画板的大小,比如将其移动到(200,50) 并将其调整为(400,300),我需要做的是:

    var document = app.activeDocument;
    var artboard = document.artboards[0];
    
    var x = 200;
    var y = 50;
    var w = 400;
    var h = 300;
    
    artboard.artboardRect = [x, -y, (x + w), -(y + h)];
    
    $.writeln(document.artboards[0].artboardRect); // 200, -50, 600, -350
    

    这个解决方案可以包装在一个函数中:

    function rect(x, y, w, h) {
        return [x, -y, (x + w), -(y + h)];
    }
    
    artboard.artboardRect = rect(200, 50, 400, 300);
    

    YH 都应该是负数,否则你会得到一个错误提示

    错误 1200:发生 Illustrator 错误:1346458189('PARM')

    或不正确的重新定位/调整大小。

    【讨论】:

      【解决方案3】:

      以防万一其他人遇到Error: an Illustrator error occurred: 1346458189 ('PARM')

      至少在 CS6 中,如果height 不是 负数或width 负数,就会发生这种情况。这适用于 rect 类型的所有值。

      xy可以是正数也可以是负数,没关系。

      所以这工作:

      app.activeDocument.artboards.add([0 , 0, 200, -50]);
      app.activeDocument.artboards.add([-10 , -10, 200, -50]);
      app.activeDocument.artboards.add([10 , 10, 200, -50]);
      

      但这不会工作:

      app.activeDocument.artboards.add([0 , 0, 200, 50])
      app.activeDocument.artboards.add([0 , 0, -200, -50])
      app.activeDocument.artboards.add([0 , 0, -200, 50])
      

      【讨论】:

        猜你喜欢
        • 2012-07-29
        • 2017-09-12
        • 2016-10-15
        • 1970-01-01
        • 2012-08-14
        • 1970-01-01
        • 2019-12-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多