Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Using Delphi with Autocad II

Title: Using Delphi with Autocad II Question: I have an application and I need to show some Autocad drawings in my help files. Plant layout, Process Flow diagrams, equipment arangments, etc. The users do not know autocad, and you certainly want them to alter company documents (See my previous Article). In this example we will build an "Acad Reader" Answer: We will need several things: 1) Autodesk Whip 4.0 ActiveX. Download it from Autodesk. If you have Acad2000 it is probably allready registered on your computer. If not check out http://www3.autodesk.com/adsk/section/0,,163301-123112,00.html 2) Install it on your computer, and use Import ActiveX to make it available to delphi. You also will be able to see the Acad DWF files in Explorer or Netscape. 3) If you have Autocad14 or 2000, make 3 sample Drawing Web Files (dwf). Define some views in your files, like top view, east view, boilerhouse etc. If you do not have, borrow some files. For delphi we need a form, a TTreeview, a TSplitter and a TWhip object. Also a global pointer variable (MyRecPtr) to link the Acad dwf files to the nodes in the treeview component. Drop a Treeview component on the form, align it to the left. Drop a splitter, align it to the left Drop a Whip component align it all client On the Form OnShow event, we will create 3 nodes. I defined the nodes: Overall Map Pumps Boilers On the OnChangeEvent of the treeview component key the following code: Whip1.StreamName := PMyRec(TreeView1.Selected.Data)^.FName When you run the program, right clicking the draw area, will enable you to zoom, print, turn off layers, change views, etc. Good luck ------------------------------------------------------------------------------ unit main; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ComCtrls, OleCtrls, WHIPLib_TLB; type TForm1 = class(TForm) TreeView1: TTreeView; Splitter1: TSplitter; Whip1: TWhip; procedure FormShow(Sender: TObject); procedure TreeView1Change(Sender: TObject; Node: TTreeNode); private { Private declarations } public { Public declarations } end; var Form1: TForm1; type PMyRec = ^TMyRec; TMyRec = record FName: string; end; var MyRecPtr: PMyRec; //File to be loaded TreeViewIndex: LongInt; implementation {$R *.DFM} procedure TForm1.FormShow(Sender: TObject); begin New(MyRecPtr); //define first node MyRecPtr^.FName := 'D:\Articles\RefMap.dwf'; if TreeView1.Items.Count = 0 then TreeView1.Items.AddObject(nil, 'Overall Map' , MyRecPtr); //define second node TreeViewIndex := 0; New(MyRecPtr); MyRecPtr^.FName := 'D:\Articles\Moyno-Model.dwf'; with treeview1 do Items.AddObject(Items[TreeViewIndex], 'Pumps' , MyRecPtr); //define last node inc(TreeViewIndex); New (MyRecPtr); MyRecPtr^.FName := 'D:\Articles\Boilers Schematic-Model.dwf'; with treeview1 do Items.AddObject(Items[TreeViewIndex], 'Boilers' , MyRecPtr); end; procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode); begin Whip1.StreamName := PMyRec(TreeView1.Selected.Data)^.FName end; end.