我一直在研究一个 InDesign 脚本,该脚本将选择图形框架内的实际图像......这可能吗

问题描述 投票:0回答:1

这是我现在的位置:

// Check if any document is open
if (app.documents.length > 0) {
    var doc = app.activeDocument;

    // Check if any frame is selected
    if (doc.selection.length > 0 && doc.selection[0].constructor.name == "Rectangle") {
        var selectedFrame = doc.selection[0];

        // Check if the selected frame contains any graphics
        if (selectedFrame.allGraphics.length > 0) {
            // Select the first graphic inside the frame (assuming it's an image)
            var graphic = selectedFrame.allGraphics[0];
            graphic.select();
        } else {
            alert("The selected frame does not contain any graphics.");
        }
    } else {
        alert("Please select a frame to proceed.");
    }
} else {
    alert("No document is open.");
}

当我选择框架并运行脚本时,没有任何反应。如果我不选择框架,我确实会收到警报。我尝试过很多变体,但一无所获。我对编码很陌生,但在这里学到了很多东西。谢谢你

javascript graphics adobe-indesign
1个回答
0
投票

尝试将

graphic.select() 
更改为
app.select(graphic);

这是一种更灵活的方法,只需检查您的选择是否具有图形属性。如果是这样,它会选择与其关联的第一个图形。

// Check if there is a selection
if (app.selection.length > 0) {
    // Get the first item of the selection
    var selectedItem = app.selection[0];
    
    // Check if the selected item has a 'graphics' property and it contains graphics
    if (selectedItem.hasOwnProperty('graphics') && selectedItem.graphics.length > 0) {
        // Select the first graphic in the container
        app.select(selectedItem.graphics[0]);
    }
}
``
© www.soinside.com 2019 - 2024. All rights reserved.