在Illustrator中使用C#automation绘制一条线

时间:2013-12-05 12:07:27

标签: c# adobe-illustrator

我想在Illustrator中使用下面的代码绘制一个C#行。无论发送什么点坐标,它总是绘制从0,0到10,-10的相同线。

        // x1,y1 x2,y2 are point coordinates
        // doc is the active document

        var myLine = Doc.PathItems.Add();
        myLine.Left = Math.Min(x1, x2);
        myLine.Top = Math.Min(y1, y2);

        //set stroked to true so we can see the path
        myLine.Stroked = true;

        var newPoint = myLine.PathPoints.Add();
        newPoint.Anchor[0]=x1;
        newPoint.Anchor[1]=y1;
        //giving the direction points the same value as the 
        //anchor point creates a straight line segment
        newPoint.LeftDirection = newPoint.Anchor;
        newPoint.RightDirection = newPoint.Anchor;
        newPoint.PointType = AiPointType.aiCorner;

        var newPoint1= myLine.PathPoints.Add();
        newPoint1.Anchor[0] = x2;
        newPoint1.Anchor[1] = y2;
        newPoint1.LeftDirection = newPoint1.Anchor;
        newPoint1.RightDirection = newPoint1.Anchor;
        newPoint1.PointType = AiPointType.aiCorner;

此代码来自Adobe VB doc转换为C#。

编辑:我猜问题来自

        newPoint.Anchor[0]=x1;
        newPoint.Anchor[1]=y1;

VB版本中的newPoint.anchor = [x1,y1]。如何正确翻译C#? 文档说明newPoint.Anchor是一个2个双精度变量数组。

1 个答案:

答案 0 :(得分:0)

发现它!

要在C#中设置变量数组,解决方案是

newPoint.Anchor = new object[] { x1,y1 };