jw_cad 外部変形 - (530) vbscriptで円を点に変換する -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

vbscriptで円を点に変換する

:vbscriptで円を点に変換する
@echo off
set ci=円を残す
:set ci=円を残さない
set src=\jww\Lite\pro\jw.vbs
if not exist %~dp0eval.vbs echo ExecuteGlobal WScript.StdIn.ReadAll > %~dp0eval.vbs
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
  copy jwc_temp.txt myfiles > nul
  (
:   echo Option Explicit
    echo On Error Resume Next
:   echo On Error GoTo 0
    type %src%
    more +%%n %0
  ) | cscript //nologo %~dp0eval.vbs %* > jwc_temp.txt
)
goto:eof

REM #jww
REM #h1
REM #g1
REM #hc 円を選択してください
REM #e

#!この次の行からプログラムを書いてください
Dim line, F
With CreateObject("Scripting.FileSystemObject")
  Dim g
  Set g = .OpenTextFile("myfiles")
  Do While Not g.AtEndOfStream
    line = g.ReadLine
    With New RegExp
      .Pattern = "[ ]+": F = Split(Trim(.Replace(line," ")))
      .Pattern = "^ci": .IgnoreCase = True
      if .Test(line) then 'ci 指示円
        if UBound(F) = 3 then
          WScript.Echo .Replace(line,"pt") '半径も出力して構わない
          if Env("ci") = "円を残す" then
            WScript.Echo line '円を復帰する
          end if
        else
          WScript.Echo line '円弧・楕円を復帰する
        end if
      else
        .Pattern = "^hq": .IgnoreCase = True
        if .Test(line) then
          WScript.Echo "hd"
        else
          WScript.Echo line 'hq を除き 円以外は復帰する
        end if
      end if
    End With
  Loop
  g.Close
End With

 

○jw2.vbs

'1)正規表現
Dim re
Set re = New RegExp
re.IgnoreCase = True '大文字と小文字を区別しない
re.Global = True '文字列全体を検索する

function reSplit(str)
  re.Pattern = "[ ]+"
  reSplit = Split(Trim(re.Replace(str," ")))
end function

function reTest(pat, str)
  re.Pattern = pat
  reTest = re.Test(str)
end function

'2)円周率
Const PI = 3.141592653589793

'3)環境変数
Dim Env
Set Env = CreateObject("WScript.Shell").Environment("Process")

'4)ユーザ定義関数
function dec(x)
  if x = "a" then x = 10
  if x = "b" then x = 11
  if x = "c" then x = 12
  if x = "d" then x = 13
  if x = "e" then x = 14
  if x = "f" then x = 15
  dec = x
end function

function deg(x)
  deg = x / PI * 180
end function

function rad(x)
  rad = x / 180 * PI
end function

function hypot(x, y)
  hypot = sqr(x * x + y * y)
end function

function sqrt(x)
  sqrt = sqr(x)
end function

function atan2(y, x)
  if x = 0 then
    atan2 = atn(1) * 2 * sgn(y)
  else
    atan2 = atn(y / x)
  end if
  if x < 0 then
    if y < 0 then
      atan2 = atan2 - atn(1) * 4
    else
      atan2 = atan2 + atn(1) * 4
    end if
  end if
end function