문제

The first part of this script finds the art size and returns with the size in inches - I want this to then ask what size to make the width then enter the number and have Illustrator scale the art to the width in the returned dialog. I'm trying to figure out where the calculation is off here. It seemed at first the scale percentage would be correct but to enlarge the percentage must be over 100 % (i.e. 125% or 150% etc.) I can't get the script to compile with an else between my if's so I'm sure I'm missing something here.

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 newWidth to text returned of (display dialog "Please enter Art Width:" default answer "100")

    tell application "Adobe Illustrator"
        set artWidth to width of tempGroup
        set sizeDifference to (newWidth / artWidth) * 100

        try
            if newWidth is equal to artWidth then
                set scalePercentage to 100
            end if


            if newWidth is greater than artWidth then
                set scalePercentage to (100 + sizeDifference)
            end if


            if newWidth is less than artWidth then
                set scalePercentage to (100 - sizeDifference)
            end if
    end tell

end 

I appreciate any suggestions. I realize javascript is probably the way to go with Illustrator but am trying to saw my way through understanding some applescripts before moving on to something more advanced. Thanks in advance.

도움이 되었습니까?

해결책

I found the answer after playing with the math. The problem was Illustrator doesn't deal with inches only points hence the (w/72) (h/72) portion when it gets the size. 72 points = 1 inch so the math had to convert points to inches. like so

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top