前回の投稿の検証用スクリプトに、
n:= IntDialog('分割数 = ', '20');
という行があります。
スクリプトの実行中にここでダイアログが出てユーザーに値の入力を求めます。このとき毎回デフォルト値が20になるのですが、出来るなら前回の値を使用したいところです。
スクリプトが終了すると変数も消えてしまうので、別のところに値を保存しておく必要があります。考えられるのはテキストファイル、ワークシート、レコードの3つです。
テキストファイルの場合はVectorWorksのデータファイルごとに違う値を保存するのに適していません。
ワークシートとレコードの場合はデータファイルに設定値を保存します。
レコードの場合はレイヤごとに異なる設定値を持たせることも可能です。
難易度は、テキストファイル < ワークシート < レコード です。レコードの場合は値をスクリプトで確認するしかないのが最大の壁です。
ということで、最初はテキストファイルに保存する方法です。単純化のために1つの設定ファイルに1つの値だけを保存します。古いバージョンではスクリプトからフォルダを作れないのでパスも指定しません。エラーメッセージやアウトプットのファイルが保存されるフォルダに設定ファイルを保存します。
function GetDefaultTF(name :string; def :real; dialog :boolean): real;
{ デフォルト値をテキストファイルから読み込む
テキストファイルが無い場合は数値入力ダイアログで数値を入力し、テキストファイルに保存する
dialogがTrueのときは必ずダイアログを開く }
const
FolderPath = '';
var
result :real;
filePath :string;
thereIsFile :boolean;
begin{main}
filePath:= Concat(FolderPath, name, '.txt');
UseDefaultFileErrorHandling(false);
Open(filePath);
if GetLastFileErr <> 0 then begin
Rewrite(filePath);
if GetLastFileErr = 0 then begin
WriteLn(def);
Close(filePath);
dialog:= true;
thereIsFile:= true;
end
else
thereIsFile:= false;
end
else begin
Read(def);
Close(filePath);
thereIsFile:= true;
end;
if not thereIsFile then begin
AlrtDialog(Concat('ファイル「', filePath, '」は開ません!'));
dialog:= true;
end;
if dialog then begin
result:= RealDialog(Concat(name, ' = '), Concat(def));
if DidCancel then
result:= def;
if def <> result then begin
Rewrite(filePath);
WriteLn(result);
Close(filePath);
end;
end
else
result:= def;
GetDefaultTF:= result;
end;{GetDefaultRF}
上の関数をインクルード・ファイルに保存して {$INCLUDE ファイルパス名} で参照し、検証用スクリプトの
n:= IntDialog('分割数 = ', '20');
n:= GetDefaultTF('補間-分割数', 20, true);