-
-
Save mechanoboyu/1d9a71c1e1e09e3c9565607ed5149736 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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