乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 30|回复: 1

c#里怎么连接CAD?^_^万分感谢

[复制链接]

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2010-4-7 15:08:00 | 显示全部楼层 |阅读模式
在VB里的连接CAD函数怎么移植到C#下啊?万分感谢
Sub 连接()
        On Error Resume Next
        Acadapp = GetObject(, "AutoCAD.Application")
        If Err.Number Then
            Err.Clear()
            Acadapp = CreateObject("AutoCAD.Application")
            If Err.Number Then
                MsgBox("不能运行AutoCAD,请检查是否安装了AutoCAD 2004")
                Exit Sub
            End If
        End If
        Acadapp.Visible = True '界面可视
        AcadApp.WindowState = autocad.AcWindowState.acMax '界面最大化
        AppActivate(Acadapp.Caption) '显示AutoCAD界面
    End Sub
回复

使用道具 举报

11

主题

43

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
87
发表于 2010-7-30 12:47:00 | 显示全部楼层
class  AutoCADConnector: IDisposable
    {
      public  AcadApplication _application;

      private bool _initialized;
      private bool _disposed;
   
      public   AutoCADConnector()
      {
         try
         {
            // Upon creation, attempt to retrieve running instance
            _application = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.16");
         
      
         
           
         }
         catch
         {
            try
            {
               // Create an instance and set flag to indicate this
               _application =  new  AcadApplicationClass();
               
               _initialized = true;
            }
            catch
            {
               throw;
            }
         }
      }
      // If the user doesn't call Dispose, the
      // garbage collector will upon destruction
      ~AutoCADConnector()
      {
         Dispose(false);
      }

      public AcadApplication Application
      {
         get
         {
            // Return our internal instance of AutoCAD
            return _application;
         }
      }
              
      // This is the user-callable version of Dispose.
      // It calls our internal version and removes the
      // object from the garbage collector's queue.
      public void Dispose()
      {
        
         Dispose(true);
        GC.SuppressFinalize(this);
      }

      // This version of Dispose gets called by our
      // destructor.
      protected virtual void Dispose(bool disposing)
      {
         // If we created our AutoCAD instance, call its
         // Quit method to avoid leaking memory.
          if (!this._disposed && _initialized)
          {
              
              try
              {
                  if (Marshal.GetActiveObject("AutoCAD.Application.16").Equals(this._application))
                  {
                      _application.Quit();
                  }
                  
              }
            
             catch
              {
             }
              
                       
          }
          _disposed = true;  
         
         
            
               
      }
         }
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-1 08:54 , Processed in 0.295026 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表