Example #1
0
        private void Send_btn_Click(object sender, EventArgs e)
        {
            if (Tabs_cbx.Text == "")
            {
                MessageBox.Show("Please Select a Tab", "Select a Tab", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Tabs_cbx.Focus();
                return;
            }
            PlanSwift.Tab CurrentTab;
            CurrentTab = TGlobal.pc.Tabs.ByName(Tabs_cbx.Text);
            CurrentTab.MakeActive();
            AuCad         = new Autodesk.AutoCAD.Interop.AcadApplication();
            AuCad.Visible = true;
            AuDocument    = AuCad.ActiveDocument;

            for (int ItemIndex = 0; ItemIndex <= CurrentTab.Count - 1; ItemIndex++)
            {
                GetItems(CurrentTab[ItemIndex]);
            }

            AuCad.ZoomAll();
            AuCad      = null;
            AuDocument = null;
            this.Close();
        }
Example #2
0
 public void OnButton2Pressed(IRibbonControl control)
 {
     try
     {
         AcadApp = (Autodesk.AutoCAD.Interop.AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
         AcadDoc = AcadApp.ActiveDocument;
     }
     catch
     {
         OpenFileDialog op = new OpenFileDialog();
         op.Filter = "CAD文件(*.dwg)|*.dwg|CAD图形文件(*.dxf)|*.dxf";
         op.Title  = "打开CAD文件";
         op.ShowDialog();
         string filePath = op.FileName;
         if (filePath == "")
         {
             MessageBox.Show("选择CAD文件无效!!", "文件无效!!");
         }
         else
         {
             AcadApp = new Autodesk.AutoCAD.Interop.AcadApplication();
             AcadDoc = AcadApp.Documents.Open(filePath, null, null);
         }
     }
     AcadApp.Application.Visible = true;
     //使CAD程序跳到在最前面,需要添加引用“Microsoft.VisualBasic”
     Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
     //让CAD自动执行netload命令加载程序集DLL,如果注册表加载方法无效的话
     AcadDoc.SendCommand("(command \"_netload\" \"" + @"C:\\Windows\\System\\xl2cad\\xl2cad.dll" + "\") ");
     AcadDoc.SendCommand("zselect ");
 }
Example #3
0
 public static void LoadDVBFile(String dvbPath, String macroName)
 {
     Autodesk.AutoCAD.Interop.AcadApplication myAcadApplication = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;  //.Application.AcadApplication;
     myAcadApplication.LoadDVB(@dvbPath);
     myAcadApplication.RunMacro(macroName);
     myAcadApplication.UnloadDVB(dvbPath);
 }
 static void Main(string[] args)
 {
     try
     {
         CloseAllInstance();
         Autodesk.AutoCAD.Interop.AcadApplication AcadApp = new Autodesk.AutoCAD.Interop.AcadApplication();
         AcadApp.Application.WindowState = Autodesk.AutoCAD.Interop.Common.AcWindowState.acMax;
         AcadApp.Application.Visible     = true;
         int menu_count = AcadApp.Application.MenuBar.Count;
         for (int i = 0; i < menu_count; ++i)
         {
             Console.WriteLine(AcadApp.Application.MenuBar.Item(i).Name);
         }
         int group_count = AcadApp.Application.MenuGroups.Count;
         for (int i = 0; i < group_count; ++i)
         {
             Console.WriteLine(AcadApp.Application.MenuGroups.Item(i).Name);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error:" + e);
     }
     Console.WriteLine("Press key");
     Console.ReadLine();
 }
Example #5
0
 //Ribbon界面的回调函数,响应事件,将Excel表格数据写入CAD
 public void OnButton1Pressed(IRibbonControl control)
 {
     //选取Excel表格数据
     wbk = app.ActiveWorkbook;
     wsh = (Worksheet)wbk.ActiveSheet;
     Excel.Range rngLeftTop     = null;
     Excel.Range rngRightButtom = null;
     rngLeftTop     = (Excel.Range)app.InputBox("点击左上角单元格", Type: 8);
     rngRightButtom = (Excel.Range)app.InputBox("点击右下角单元格", Type: 8);
     object[,] data = (object[, ])wsh.Range[rngLeftTop.Address + ":" + rngRightButtom.Address].Value2;
     //把数据导入Access数据库
     try
     {
         AccessDataBase.WriteDB(data);
         MessageBox.Show("选定的数据读取完毕,点击确定导入CAD");
     }
     catch (SystemException ex)
     {
         MessageBox.Show(ex.ToString());
     }
     //选定的数据读取完毕,点击确定导入CAD
     if (rngLeftTop != null & rngRightButtom != null)
     {
         //打开cad
         try
         {
             AcadApp = (Autodesk.AutoCAD.Interop.AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
             AcadDoc = AcadApp.ActiveDocument;
         }
         catch
         {
             OpenFileDialog op = new OpenFileDialog();
             op.Filter = "CAD文件(*.dwg)|*.dwg|CAD图形文件(*.dxf)|*.dxf";
             op.Title  = "打开CAD文件";
             op.ShowDialog();
             string filePath = op.FileName;
             if (filePath == "")
             {
                 MessageBox.Show("选择CAD文件无效!!", "文件无效!!");
             }
             else
             {
                 AcadApp = new Autodesk.AutoCAD.Interop.AcadApplication();
                 AcadDoc = AcadApp.Documents.Open(filePath, null, null);
             }
         }
         AcadApp.Application.Visible = true;
         //使CAD程序跳到在最前面,需要添加引用“Microsoft.VisualBasic”
         Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
         //让CAD自动执行netload命令加载程序集DLL,如果注册表加载方法无效的话
         AcadDoc.SendCommand("(command \"_netload\" \"" + @"C:\\Windows\\System\\xl2cad\\xl2cad.dll" + "\") ");
         AcadDoc.SendCommand("zdbtext ");
     }
     else
     {
         MessageBox.Show("没有选择数据!");
     }
 }
Example #6
0
        public void Initialize()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("正在初始化...");
            Autodesk.AutoCAD.Interop.AcadApplication acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
            //acadApp.MenuGroups
            //MyMenu.ShowMyMenu();
        }
Example #7
0
        /// <summary>
        /// 多实体定位
        /// </summary>
        /// <param name="polylineHandleList"></param>
        public static void FindPolyline(List <string> polylineHandleList)
        {
            DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
            Document     doc            = Application.DocumentManager.MdiActiveDocument;
            Database     db             = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    List <Point3d> maxList = new List <Point3d>();
                    List <Point3d> minList = new List <Point3d>();
                    foreach (var polylineHandle in polylineHandleList)
                    {
                        ObjectId newObjectId = TechnologicalProcess.GetObjectId(polylineHandle, 10);
                        Entity   entity      = tr.GetObject(newObjectId, OpenMode.ForWrite) as Entity;
                        if (entity == null)
                        {
                            continue;
                        }
                        var range = entity.GeometricExtents;
                        entity.Highlight();
                        maxList.Add(range.MaxPoint);
                        minList.Add(range.MinPoint);
                    }
                    double maxX = GetMaximumValue(maxList, true);
                    double maxY = GetMaximumValue(maxList, false);
                    double minX = GetMinimumBValue(minList, true);
                    double minY = GetMinimumBValue(minList, false);
                    Autodesk.AutoCAD.Interop.AcadApplication acadApplication = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
                    //参数要求是双精度的数组
                    if (acadApplication != null)
                    {
                        double[] doubles1 = new double[3] {
                            minX, minY, 0
                        };
                        double[] doubles2 = new double[3] {
                            maxX, maxY, 0
                        };
                        acadApplication.ZoomWindow(doubles1, doubles2);
                    }
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("定位:" + e.ToString());
                }
                finally
                {
                    tr.Commit();
                    m_DocumentLock.Dispose();
                }
            }
        }
Example #8
0
        /// <summary>
        /// 定位
        /// </summary>
        /// <param name="polylineHandle"></param>
        public static void FindPolyline(string polylineHandle)
        {
            DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
            Document     doc            = Application.DocumentManager.MdiActiveDocument;
            Database     db             = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    ObjectId newObjectId = TechnologicalProcess.GetObjectId(polylineHandle, 10);
                    Entity   entity      = tr.GetObject(newObjectId, OpenMode.ForWrite) as Entity;
                    var      range       = entity.GeometricExtents;
                    if (entity == null)
                    {
                        return;
                    }
                    Autodesk.AutoCAD.Interop.AcadApplication acadApplication = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
                    //参数要求是双精度的数组
                    if (acadApplication != null)
                    {
                        double[] doubles1 = new double[3] {
                            range.MinPoint.X, range.MinPoint.Y, range.MinPoint.Z
                        };
                        double[] doubles2 = new double[3] {
                            range.MaxPoint.X, range.MaxPoint.Y, range.MaxPoint.Z
                        };
                        acadApplication.ZoomWindow(doubles1, doubles2);
                        entity.Highlight();
                    }
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("定位:" + e.ToString());
                }
                finally
                {
                    tr.Commit();
                    m_DocumentLock.Dispose();
                }
            }
        }
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args">0.cad .dxf文件夹路径  1.处理数据类型</param>
        public static void Main(string[] args)
        {
            CloseAllInstance();
            Console.WriteLine("开始处理..");
            Console.WriteLine("正在打开cad");
            cadapp = new Autodesk.AutoCAD.Interop.AcadApplication();
            cadapp.Visible = true;
            string procType = args[1];
            switch (procType)
            {
                case "t1":
                    Console.WriteLine("正在处理方式1"+args[0]+"  "+args[1]);
                    Program.procFile(args[0]);
                    break;


            }
                

          

                


        }