COM用CreateObject能够自动创建一个dwg文件并打开Autocad环境,那么ObjectArx.Net用
COM用CreateObject能够自动创建一个dwg文件并打开Autocad环境,那么ObjectArx.Net用什么方法实现同样的功能COM用CreateObject能够自动创建一个dwg文件并打开Autocad环境,那么ObjectArx.Net用什么方法实现同样的功能<br/> <pre class="codeLine"></pre><pre class="codeLine">public static void ConnectToAcad()</pre><pre class="codeLine">{</pre><pre class="codeLine"></pre><pre class="codeLine">AcadApplication acAppComObj = null;</pre><pre class="codeLine">const string strProgId = "AutoCAD.Application.18";</pre><pre class="codeLine">
</pre><pre class="codeLine">// Get a running instance of AutoCAD</pre><pre class="codeLine">try</pre><pre class="codeLine">{</pre><pre class="codeLine"> acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);</pre><pre class="codeLine">}</pre><pre class="codeLine">catch // An error occurs if no instance is running</pre><pre class="codeLine">{</pre><pre class="codeLine"> try</pre><pre class="codeLine"> {</pre><pre class="codeLine"> // Create a new instance of AutoCAD</pre><pre class="codeLine"> acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);</pre><pre class="codeLine"> }</pre><pre class="codeLine"> catch</pre><pre class="codeLine"> {</pre><pre class="codeLine"> // If an instance of AutoCAD is not created then message and exit</pre><pre class="codeLine"> System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" +</pre><pre class="codeLine"> " could not be created.");</pre><pre class="codeLine">
</pre><pre class="codeLine"> return;</pre><pre class="codeLine"> }</pre><pre class="codeLine">}</pre><pre class="codeLine">
</pre><pre class="codeLine">// Display the application and return the name and version</pre><pre class="codeLine">acAppComObj.Visible = true;</pre><pre class="codeLine">System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name + </pre><pre class="codeLine"> " version " + acAppComObj.Version);</pre><pre class="codeLine">
</pre><pre class="codeLine">// Get the active document</pre><pre class="codeLine">AcadDocument acDocComObj;</pre><pre class="codeLine">acDocComObj = acAppComObj.ActiveDocument;</pre><pre class="codeLine">
</pre><pre class="codeLine">// Optionally, load your assembly and start your command or if your assembly</pre><pre class="codeLine">// is demandloaded, simply start the command of your in-process assembly.</pre><pre class="codeLine">acDocComObj.SendCommand("(command " + (char)34 + "NETLOAD" + (char)34 + " " +</pre><pre class="codeLine"> (char)34 + "c:/myapps/mycommands.dll" + (char)34 + ") ");</pre><pre class="codeLine">
</pre><pre class="codeLine">acDocComObj.SendCommand("MyCommand ");</pre><pre class="codeLine">}</pre> lin0799发表于2009-11-8 15:32:00static/image/common/back.gifpublic static void ConnectToAcad(){ AcadApplication acAppComObj = null; const string strProgId = \"AutoCAD.Application.18\"; // Get a
<p>先生的这种方法必须是在autocad环境打开的情况下才能在命令行发"ConnectToAcad"命令,此时的autocad环境已经打开了,发这个命令是否多余啊</p> <p>NetApi只能在Cad环境内</p><p>不过,你可以用scr实现类似的功能</p>
页:
[1]