wmz 发表于 2007-4-12 21:44:00

请教delphi控制AutoCAD问题

我用VB写了一段代码,望能将其转换成delphi代码,如下:<br/>Sub AddPath()<br/>&nbsp; dim AcadApp as Object<br/>&nbsp; dim CurPath As Variant<br/>&nbsp; dim Path as string<br/>&nbsp; Path="c:\wmz"<br/>&nbsp;set AcadApp=CreatObject("AutoCAD.Application.16)<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcadApp.Visible=True<br/>&nbsp; AcadApp.Application.Preferences.Files=Path &amp; ";" &amp;&nbsp; AcadApp.Application.Preferences.Files<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcadApp.Quit<br/>end Sub<br/>注:以上代码是将路径为"c:\wmz"的加到AutoCAD的支持路径的最前面中去<br/>

wmz 发表于 2007-4-13 19:17:00

<div>在网上搜索了一下,终于找到可以和前面VB代码有相同作用的delphi代码了,不知可不可行:</div><div></div><div>procedure TForm1.Button1Click(Sender: TObject);<br/>&nbsp; var</div><div></div><div>&nbsp;&nbsp;&nbsp; MyReg : TRegistry;<br/>&nbsp;&nbsp;&nbsp; f:string;<br/>begin</div><div></div><div>&nbsp; MyReg := TRegistry.Create;</div><div></div><div>&nbsp; MyReg.RootKey := HKEY_CURRENT_USER;</div><div></div><div>&nbsp; try</div><div></div><div>&nbsp;&nbsp; if&nbsp; MyReg.OpenKey('\Software\Autodesk\AutoCAD\R16.0\ACAD-201:804\Profiles\&lt;&lt;未命名配置&gt;&gt;\General',true) then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f:= 'c:\wmz;' + MyReg.ReadString('ACAD');<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyReg.WriteString('ACAD',f);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyReg.CloseKey;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<br/>&nbsp; finally</div><div></div><div>&nbsp;&nbsp;&nbsp; MyReg.Free;</div><div></div><div>&nbsp; end;</div>

spshchen 发表于 2007-4-17 01:05:00

<p>我这里有一段给你参考吧</p><p>procedure TForm1.Button4Click(Sender: TObject);<br/>var<br/>&nbsp;&nbsp;&nbsp; vCadApp:Variant;<br/>&nbsp;&nbsp;&nbsp; vActiveDoc:Variant;<br/>&nbsp;&nbsp;&nbsp; sfilename,cmdsfile:string;<br/>&nbsp;&nbsp;&nbsp; i : integer;<br/>begin<br/>&nbsp;&nbsp;&nbsp; sfilename := ParamStr(1); //取运行参数,也就是带处理的dwg文件<br/>&nbsp;&nbsp;&nbsp; vCadApp := CreateOleObject('autoCad.Application');<br/>&nbsp;&nbsp;&nbsp; vCadApp.Visible := true;<br/>&nbsp;&nbsp;&nbsp; vActiveDoc :=&nbsp; vCadApp.ActiveDocument;</p><p>&nbsp;&nbsp;&nbsp; cmdsfile := ExtractFileDir(Application.ExeName)+'\zn_main_s.fas';<br/>&nbsp;&nbsp;&nbsp; cmdsfile := StringReplace(cmdsfile,'\','\\', );<br/>&nbsp;&nbsp;&nbsp; vActiveDoc.SendCommand('(load "'+cmdsfile+'")'+#13);<br/>&nbsp;&nbsp;&nbsp; vActiveDoc.SendCommand('(print "\n欢迎使用室内分布系统CAD辅助画图软件,版权属于50868,\nEmail:050868@163.com,陈海容2006年11月11日"&nbsp; )'+#13);<br/>&nbsp;&nbsp;&nbsp; cmdsfile := ExtractFileDir(Application.ExeName);<br/>&nbsp;&nbsp;&nbsp; cmdsfile := StringReplace(cmdsfile,'\','\\', );<br/>&nbsp;&nbsp;&nbsp; vActiveDoc.SendCommand('(zn_main_s_t "'+cmdsfile + '")'+#13);<br/>&nbsp;&nbsp;&nbsp; vActiveDoc.SendCommand('(repeat 400(print&nbsp; ))'+#13);<br/>&nbsp;end;</p>

wmz 发表于 2007-4-17 13:35:00

<div>非常感谢,就本问题而言,我只要下面这两句就够了</div><div>&nbsp;vActiveDoc :=&nbsp; vCadApp.ActiveDocument;</div><div>&nbsp;vActiveDoc.SendCommand('(load "'+cmdsfile+'")'+#13);</div>
页: [1]
查看完整版本: 请教delphi控制AutoCAD问题