Skip to content

Instantly share code, notes, and snippets.

@mechanoboyu
Last active March 4, 2018 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mechanoboyu/1d9a71c1e1e09e3c9565607ed5149736 to your computer and use it in GitHub Desktop.
Save mechanoboyu/1d9a71c1e1e09e3c9565607ed5149736 to your computer and use it in GitHub Desktop.
'Autocad LTや互換CADで使うSCRファイルを生成します。
Private Const START_CELL = "B2"
Private Const TemplateFileName = "\cad-script-template.txt"
Private Const OutputFileName = "\output-cad-script.scr"
Sub main()
Dim Cell As Range
Dim t As MiniTemplator
Set t = New MiniTemplator
'CADスクリプトのテンプレートを読み込みます。
t.ReadTemplateFromFile ThisWorkbook.Path & TemplateFileName
Dim rng As Range
set rng = Range("B2", "B3")
If WorksheetFunction.CountA(rng) = 0 Then
 MsgBox "ファイルパスが未入力です。入力して下さい。"
Else
'図面データのフルパスリストの読み込み開始位置を指定します。
Set Cell = Range(START_CELL)
'図面データのフルパスリストが空白行になるまで繰り返します。
Do until Cell.Value = ""
'図面データのフルパスを一行ずつ生成ファイルにセットします。
t.SetVariable "file", Cell.Value
'ファイル名にA3が含まれていたらバージョンを2000に、A4なら2013に指定します。
If Cell.Value Like "*A3*" Then
t.SetVariable "ver", "2000"
ElseIf Cell.Value Like "*A4*" Then
t.SetVariable "ver", "2013"
Else
t.SetVariable "ver", "2000"
End If
'ブロックに追加します。
t.AddBlock "scr"
'一行下のセルに移動します。
Set Cell = Cell.offset(1,0)
Loop
'生成したスクリプトを書き出します。
'例では.scrとしているが、.txtにすれば、txtファイルとして出力可能。
t.GenerateOutputToFile ThisWorkbook.Path & OutputFileName
MsgBox "スクリプト生成成功"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment