-- DXF を DWG に変換するデスクトップアプリ(ドロップ型) -- ・DXF をアイコンにドラッグするか、ダブルクリックして選ぶ -- ・同じフォルダに、同じ名前の .dwg を作る(同じ名前があれば「_変換」を付けて上書きしない) -- ・変換には無料の ODA File Converter を使う(/Applications に入れておく) property odaPath : "/Applications/ODAFileConverter.app/Contents/MacOS/ODAFileConverter" property outVersion : "ACAD2018" on run set picked to choose file with prompt "DWG にしたい DXF を選んでください(複数選べます)" of type {"dxf", "DXF", "com.autodesk.dxf"} with multiple selections allowed convertAll(picked) end run on open droppedItems convertAll(droppedItems) end open on convertAll(items_) if not odaReady() then return set okCount to 0 set ngList to {} repeat with f in items_ set p to POSIX path of f if p does not end with ".dxf" and p does not end with ".DXF" then set end of ngList to (name of (info for f)) & "(DXF ではありません)" else if convertOne(p) then set okCount to okCount + 1 else set end of ngList to (name of (info for f)) end if end if end repeat set msg to (okCount as text) & " 枚を DWG にしました(" & outVersion & ")。元の DXF と同じフォルダにあります。" if (count of ngList) > 0 then set AppleScript's text item delimiters to return set msg to msg & return & return & "変換できなかったもの:" & return & (ngList as text) set AppleScript's text item delimiters to "" end if display dialog msg buttons {"OK"} default button 1 with title "DXF→DWG" end convertAll on convertOne(p) set dirPath to do shell script "dirname " & quoted form of p set baseName to do shell script "basename " & quoted form of p & " | sed -E 's/\\.[dD][xX][fF]$//'" set work to do shell script "mktemp -d /tmp/dxf2dwg.XXXXXX" try do shell script "mkdir " & quoted form of (work & "/in") & " " & quoted form of (work & "/out") & " && cp " & quoted form of p & " " & quoted form of (work & "/in/" & baseName & ".dxf") do shell script quoted form of odaPath & " " & quoted form of (work & "/in") & " " & quoted form of (work & "/out") & " " & outVersion & " DWG 0 1 '*.DXF' >/dev/null 2>&1 || true" set made to work & "/out/" & baseName & ".dwg" if (do shell script "test -s " & quoted form of made & " && echo y || echo n") is "n" then error "no output" -- 同じ名前があれば _変換, _変換2, _変換3 … と付けて、元のファイルは上書きしない set dest to do shell script "d=" & quoted form of (dirPath & "/" & baseName) & "; t=\"$d.dwg\"; n=1; while [ -e \"$t\" ]; do if [ $n -eq 1 ]; then t=\"${d}_変換.dwg\"; else t=\"${d}_変換$n.dwg\"; fi; n=$((n+1)); done; echo \"$t\"" do shell script "mv -n " & quoted form of made & " " & quoted form of dest do shell script "rm -rf " & quoted form of work return true on error do shell script "rm -rf " & quoted form of work return false end try end convertOne on odaReady() if (do shell script "test -x " & quoted form of odaPath & " && echo y || echo n") is "y" then return true set r to button returned of (display dialog "変換には、無料の「ODA File Converter」が必要です。" & return & return & "ダウンロードページを開くので、Mac 用(Apple Chip)の dmg を入れて、アプリを「アプリケーション」フォルダに入れてください。入れたら、もう一度このアプリに DXF をドロップしてください。" buttons {"やめる", "ページを開く"} default button 2 with title "DXF→DWG") if r is "ページを開く" then open location "https://www.opendesign.com/guestfiles/oda_file_converter" return false end odaReady