2014-11-19 6 views
0

이것은 내 마음을 잃어 버리게 만듭니다. 여기에 내가 노력하려고 노력하는 짧은 코드가 있습니다. 기괴한 값을 반환하고 무작위 높이 및 너비 설정에서 오류가 발생합니다. 나는 내가 잘못한 곳을 알아낼 수 없다! 입력을 결정하는 논리 게이트가 견고하다고 생각했습니다! 어떤 도움이라도 대단히 감사하겠습니다!Indesign에서 AppleScript를 사용하는 여러 조건부 - 작동하지 않습니까?

tell application "Adobe InDesign CS6" 
    activate 
    set myDoc to active document 

    set origLevel to user interaction level of script preferences 
    set user interaction level of script preferences to interact with all 

    set myDialog to make dialog with properties {name:"Make Template", can cancel:true} 
    tell myDialog 
     tell (make dialog column) 
      tell (make border panel) 
       tell (make dialog column) 
        make static text with properties {static label:"Width:", min width:60} 
        make static text with properties {static label:"Height:", min width:60} 
        make static text with properties {static label:"Bleed:", min width:60} 
       end tell 
       tell (make dialog column) 
        set myWidth to make text editboxes with properties {edit contents:"", min width:60} 
        set myHeight to make text editboxes with properties {edit contents:"", min width:60} 
        set myBleed to make text editboxes with properties {edit contents:"", min width:60} 
       end tell 
       tell (make dialog column) 
        make static text with properties {static label:"in", min width:0} 
        make static text with properties {static label:"in", min width:0} 
        make static text with properties {static label:"in", min width:0} 
       end tell 
       tell (make dialog column) 
        make static text with properties {static label:"", min width:25} 
       end tell 
      end tell 
     end tell 
    end tell 

    set userResponse to show myDialog 
    if userResponse is true then 
     set docWidth to edit contents of myWidth as string 
     set docHeight to edit contents of myHeight as string 
     set docBleed to edit contents of myBleed as string 
     destroy myDialog 
    else 
     destroy myDialog 
     error number -128 
    end if 

    tell myDoc 

     if docHeight > docWidth then 
      set bigDim to docHeight 
     else 
      set bigDim to docWidth 
     end if 

     if bigDim ≤ 216 then 
      set buildSize to "1" 
     else if bigDim > 216 and bigDim ≤ 432 then 
      set buildSize to "2" 
     else if bigDim > 432 and bigDim ≤ 864 then 
      set buildSize to "4" 
     else if bigDim > 864 and bigDim ≤ 2160 then 
      set buildSize to "10" 
     end if 

     set newWidth to (docWidth/buildSize) 
     set newHeight to (docHeight/buildSize) 
     set newBleed to (docBleed/buildSize) 

     set document bleed top offset of document preferences to newBleed 
     set page width of document preferences to newWidth 
     set page height of document preferences to newHeight 

    end tell 

    set user interaction level of script preferences to origLevel 
end tell 
+0

예상되는 결과와 실제 오류 메시지에 대한 설명이 유용합니다. –

+0

높이와 너비를 "5"로 설정하면 25 %의 배율 크기로 반환됩니다. 다른 모든 if-then 문을 제거하고 "bigDim ≤ 216이라면 buildSize를"1 "로 설정하면 작동하지 않습니다. 단지 buildSize가 정의되지 않았다고 말합니다 - 내 입력 > 216이었습니다. 단지 의미가 없습니다! –

답변

0

당신은

set docWidth to edit contents of myWidth as string 
    set docHeight to edit contents of myHeight as string 

를 작성하고 실제로는 정수와 문자열을 비교 : if bigDim ≤ 216 then합니다. 코드를 처리하려면 Applescript는 이러한 값 중 하나를 변환해야하며 값 216을 문자열 "216"으로 변환하는 것처럼 보입니다. 문자열 비교를 사용하면 문자열 "5"는 "216"보다 커서 비교 " else if bigDim > 432 and bigDim ≤ 864 then"에 해당합니다. 문자열 "5"는 "432"와 "864"사이에 들어 있기 때문입니다.

편집 내용을 정수로 변환하는 것은 어떨까요? 그냥 의미는 두 개의 문자열 ;-)

즐겨을 분할하지 않기 때문에 AppleScript를 숫자로 두 값을 변환 할 정도로 똑똑하기 때문에

set docWidth to edit contents of myWidth as integer 
    set docHeight to edit contents of myHeight as integer 

은 BTW 나중에 스크립트에서 사용되는 코드 set newWidth to (docWidth/buildSize) 만했다 Michael/Hamburg