Grossa Speaks Final

コンピュータに関するテーマを
気の向くまま取り上げています。
(時々雑談...)

DenGasの作成ノート2

2006年11月25日 | Programming
レイヤーを管理するツール DenGas の現在のコーディングは次の通り。
アクティブな図面のレイヤー状態を取得し、それを変更し、図面に反映させるところ
まで、完了。

StringGridのCell範囲外をクリックすると、例外発生。
しばらく原因がわからず、悩む。
だが、高さを調整して、問題解決。

(ぼやきの始まり)
AutoCADの日本語版はlayerを画層というが、勘弁して欲しい。
layerはレイヤーでよいと思う。
そういえば、Windows XPの日本語版の起動画面で ようこそ と出る。
これも勘弁して欲しい。ようこそ ここへ と 桜田淳子の歌を思い出す。
Macのように Welcome to Mac がスマート。
(ぼやきの終わり)


-----Start of Coding
unit UnitDenGas;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComObj, StdCtrls, ExtDlgs, ExtCtrls, FileCtrl, Grids, ImgList,ShellApi;

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
StringGrid2: TStringGrid;
Button4: TButton;
Button5: TButton;
Label1: TLabel;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;

var
Form1: TForm1;
ICAD: OLEVariant;
ICADHWND: HWND;
MyRowCount: integer;
LayerNum: integer;
IsGet: Boolean;
IsRight : boolean;
implementation

{$R *.dfm}

//IntelliCADが起動しているかをチェック
//StringGridの初期設定

procedure TForm1.FormActivate(Sender: TObject);
begin
ICADHWND := FindWindow('IntelliCADApplicationWindow',nil);

if IsWindow(ICADHWND) then
begin
//IntelliCADを検出
Icad := GetActiveOleObject('ICAD.Application');
//
IsGet := False;
//StringGridの初期設定
MyRowCount := 10;
with StringGrid1 do
begin
RowCount := MyRowCount; //行数
ColCount := 3; //列数
FixedRows := 1; //固定行の数
FixedCols := 0; //固定列の数
Width := 470;
ColWidths[0] := 300;
ColWidths[1] := 70;
ColWidths[2] := 70;
Cells[0,0] := 'Layer Name';
Cells[1,0] := 'On/Off';
Cells[2,0] := 'Locked';
end;

with StringGrid2 do
begin
RowCount := 21; //行数
ColCount := 1; //列数
FixedRows := 1; //固定行の数
Width := 330;
ColWidths[0] := 300;
Cells[0,0] := 'Layerstatus';
end;
ShowMessage('アクティブな図面のレイヤー状態を取得するには' + #13
+ '<GetStatus>をクリックして下さい。');
end
else
begin
ShowMessage('IntelliCADが起動していません。' +#13 + 'DenGasを終了します。');

//アプリケーションの終了
Application.Terminate;
end;

end;

//アクティブな図面のすべてのレイヤー名称、状態を取得
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
ActName : string; //アクティブな図面の名称

begin
IsGet := True; //最初に<Get>をクリックしないと、<Set>が利用できない
LayerNum := ICAD.ActiveDocument.Layers.Count; //レイヤーの数
StringGrid1.RowCount := LayerNum + 1; //行数の設定
//StringGrid1.Height := StringGrid1.RowCount * 24;
ActName := ICAD.ActiveDocument.FullName;
Edit1.Text := ActName; //アクティブな図面の名称

for i :=1 to LayerNum do //レイヤー名称
begin
StringGrid1.Cells[0,i] := ICAD.ActiveDocument.Layers.Item(i).Name;
end;

for i := 1 to LayerNum do //表示(-1)、非表示(0)
begin
IsRight := ICAD.ActiveDocument.Layers.Item(i).LayerOn;
case IsRight of
True: StringGrid1.Cells[1,i] := 'On';
False: StringGrid1.Cells[1,i] := 'Off';
end;
end;

for i := 1 to LayerNum do //ロック(-1),非ロック(0)
begin
IsRight := ICAD.ActiveDocument.Layers.Item(i).Lock;
case IsRight of
True: StringGrid1.Cells[2,i] := 'Yes';
False: StringGrid1.Cells[2,i] := 'No';
end;
end;

ShowMessage('アクティブな図面のレイヤー状態を取得しました。' +#13
+ 'セルをクリックするとOn/Off,Yes/Noが切替わります。');

end;

//レイヤーの状態を図面に反映する
procedure TForm1.Button4Click(Sender: TObject);
var
i: integer;
Lays: OLEVariant;
begin
if IsGet then
begin
Lays := ICAD.ActiveDocument.Layers;

//表示、非表示を設定
for i := 1 to LayerNum do
begin
if StringGrid1.Cells[1,i] = 'On' then Lays.Item(i).LayerOn := True
else if StringGrid1.Cells[1,i] = 'Off' then Lays.Item(i).LayerOn := False;
end;

//ロック、非ロックを設定
for i := 1 to LayerNum do
begin
if StringGrid1.Cells[2,i] = 'Yes' then Lays.Item(i).Lock := True
else if StringGrid1.Cells[2,i] = 'No' then Lays.Item(i).Lock := False;
end;

Icad.RunCommand('_regen' + #13);
ShowMessage('設定変更を図面に反映しました。');
end
else
ShowMessage('最初に<GetStatus>をクリックして下さい。');
end;


//レイヤーの状態を設定する
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Column, Row: Longint;
begin
if IsGet then
begin
StringGrid1.MouseToCell(X, Y, Column, Row);
if (Row <> 0) and (Column <> 0) then //固定行、レイヤー名称の修正禁止
begin //シングルクリックでトグル操作
with StringGrid1 do
begin
if Cells[Column,Row] = 'On' then Cells[Column,Row] := 'Off'
else if Cells[Column,Row] = 'Off' then Cells[Column,Row] := 'On'
else if Cells[Column,Row] = 'Yes' then Cells[Column,Row] := 'No'
else if Cells[Column,Row] = 'No' then Cells[Column,Row] := 'Yes';
end;
end;
end
else
ShowMessage('最初に<GetStatus>をクリックして下さい。');

end;

end.
-----End of Coding

最新の画像もっと見る

コメントを投稿