applescript Illustrator基于返回对话框缩放

时间:2014-04-25 16:16:55

标签: applescript adobe-illustrator

我正在编写一个脚本以消除重复。到目前为止,我将获得Illustrator中当前的艺术尺寸并以英寸显示尺寸,但我无法确定如何缩放基于回归对话的艺术。我试图让它按照与宽度返回的测量值成比例地缩放艺术品。然后,它将根据艺术的新尺寸调整画板大小(此部分可用)。这是我到目前为止所拥有的

tell application "Adobe Illustrator"
activate
tell document 1
    --define Spot1
    set docColorSpace to color space
    if (docColorSpace is CMYK) then
        set SpotColor1 to {cyan:21.0, magenta:0, yellow:100.0, black:0.0}
    else
        set SpotColor1 to {red:206.0, green:219.0, blue:41.0}

    end if

    --color change first
    set (path items whose fill color is not SpotColor1)'s fill color to SpotColor1



    --get current size
    set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
    duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
    set {w, h} to {width, height} of tempGroup -- get properties
    delete tempGroup
    display dialog "Width of Art: " & (w / 72) & return & "Height of Art: " & (h / 72)



    --change to desired size PROBLEM SECTION        
    set ArtWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")

    try
        if (w / 72) is greater than ArtWidth then
            set sizeDifference to (ArtWidth - (w / 72)) as integer
        else
            if (w / 72) is less than ArtWidth then
                set sizeDifference to ((w / 72) - ArtWidth) as integer

            end if
        end if


        set has selected artwork of (every layer of document 1) to true
        set everyPageItem to artItem
        set x1orig to item 1 of activeArt
        set y1orig to item 2 of activeArt
        set x2orig to item 3 of activeArt
        set y2orig to item 4 of activeArt
                    --not sure if activeArt


        --determine new page size (add inch in each direction)
        set x1new to (x1orig - sizeDifference) as real
        set y1new to (y1orig + sizeDifference) as real
        set x2new to (x2orig + sizeDifference) as real
        set y2new to (y2orig - sizeDifference) as real
        --set new art size
        set artItem to {x1new, y1new, x2new, y2new}



        --fit artboard to art 
        set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
        duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
        set {w, h} to {width, height} of tempGroup -- get properties
        set theBounds to visible bounds of tempGroup
        set artboard rectangle of first artboard to theBounds
        delete tempGroup

        -- one inch border      
        tell artboard 1
            --get original page size
            set artPage to artboard rectangle
            set x1orig to item 1 of artPage
            set y1orig to item 2 of artPage
            set x2orig to item 3 of artPage
            set y2orig to item 4 of artPage

            --determine new page size (add inch in each direction)
            set x1new to (x1orig - 72) as real
            set y1new to (y1orig + 72) as real
            set x2new to (x2orig + 72) as real
            set y2new to (y2orig - 72) as real
            --set new page size
            set artboard rectangle to {x1new, y1new, x2new, y2new}

            --print to rip, set path to folder

            --hop out to finder, close & file folders where they go 



        end tell

    end try
end tell
end tell
end

我觉得我忽略了一种更简单的方法 - 任何建议都值得赞赏

2 个答案:

答案 0 :(得分:1)

这是从我用于将艺术缩放到特定宽度的子程序中获取的。请注意,以英寸为单位的差异实际上并不重要。您只需要知道原始大小和新大小之间的比例。

set newWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")

tell application "Adobe Illustrator"
    set artWidth to width of tempGroup
    set scalePercentage to (newWidth / artWidth) * 100
    scale tempGroup horizontal scale scalePercentage vertical scale scalePercentage
end tell

答案 1 :(得分:0)

脚本的问题是Illustrator使用点而不是英寸,所以我不得不将点转换为英寸像这样

tell application "Adobe Illustrator"
activate
tell document 1

    --get current size
    set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
    duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
    set {w, h} to {width, height} of tempGroup -- get properties
    delete tempGroup
    display dialog "Width of Art: " & (w / 72) & return & "Height of Art: " & (h / 72)

    --resize        
    set newWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")
    set artWidth to width of tempGroup
    set sum to (artWidth / newWidth * 100)
    set scalePercentage to (72 / sum * 10000)

    scale tempGroup horizontal scale scalePercentage vertical scale scalePercentage


end tell
end tell

end