【问题标题】:applescript Illustrator scaling based on return dialogapplescript Illustrator 缩放基于返回对话框
【发布时间】:2014-05-09 05:42:31
【问题描述】:

我正在编写一个脚本以消除重复。到目前为止,我将在 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

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

【问题讨论】:

  • 我已将此问题返回到编辑前的第一个版本,因为您已将我的答案应用于该问题。这使得答案不再真正回答问题。如果您仍然遇到同样的问题,请使用更多详细信息编辑问题。如果您对新代码有不同的问题,请提出一个新问题。
  • 我的错误 - 对不起。我标记了已回答的问题。感谢您的帮助
  • 您在此处提交的脚本确实对艺术进行了缩放,由我来找出计算差异并将其转换为缩放百分比的正确方法(现在它对艺术的缩放非常小)跨度>

标签: applescript adobe-illustrator


【解决方案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

【讨论】:

  • 我明白你在说什么,这似乎比我以前尝试做的更有效率。我无法让它工作,但我已经发布了没有脚本其他部分的内容,因此我可以突出显示问题区域。 tempGroup 不太理想,因为它会导致某些艺术作品显示不正确。谢谢你的建议!
【解决方案2】:

脚本的问题是 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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    相关资源
    最近更新 更多