簡體   English   中英

JXA和OmniGraffle

[英]JXA & OmniGraffle

我不知道如何將以下AppleScript轉換成JXA(Mac OS X Yosemite下的JavaScript for Automation):

tell application id "com.omnigroup.OmniGraffle6"
    tell canvas of front window
        make new line at end of graphics with properties {point list:L, draws shadow:false}
    end tell
end tell

這是我嘗試過的操作,但是在執行最后一行時出錯,並顯示錯誤“ AppleEvent handler failed”:

app = Application('OmniGraffle')

pt1 = app.Point({x:1,y:2})
pt2 = app.Point({x:1,y:2})

L = []
L.push(pt1)
L.push(pt2)

line = app.Line({pointList:L})

app.documents[0].canvases[0].lines.push(line)

有人可以幫忙嗎?

謝謝,Aurelien

圖形對象(線,形狀等)包含在圖形集合中。 因此,您必須將最后一行更改為

app.documents[0].canvases[0].graphics.push(line)

還有一個等效但更完整的示例:

(function () {
    'use strict';

    var og = Application("OmniGraffle"),
        ds = og.documents,
        d = ds.length ? ds[0] : null,
        cnvs = d ? d.canvases : [],
        cnv = cnvs.length ? cnvs[0] : null,
        gs = cnv ? cnv.graphics : null;

    return gs ? (
        gs.push(
            og.Line({
                pointList: [[72, 216], [216, 72]],
                drawsShadow: true,
                thickness: 3,
                lineType: 'orthogonal',
                strokeColor: [1.0, 0.0, 0.0],
                headType: "FilledArrow"
            })
        )
    ) : null;

})();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM