mengxiangge 5 rokov pred
commit
6839a181f3

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+################################################################################
+# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
+################################################################################
+
+/.vs/TestCad/v15

+ 6 - 0
App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+    </startup>
+</configuration>

+ 300 - 0
AutoCADConnector.cs

@@ -0,0 +1,300 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using AutoCAD = Autodesk.AutoCAD.Interop;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+using Autodesk.AutoCAD.DatabaseServices;
+using Newtonsoft.Json;
+using TestCad;
+using dbx = Autodesk.AutoCAD.Interop.Common;
+namespace SmartSoft.ACAD
+{
+    ///
+    /// 读取AutoCAD属性信息
+    ///
+    public class AutoCADConnector : IDisposable
+    {
+        private AutoCAD.AcadApplication _Application;
+        private bool _Initialized;
+        private bool _Disposed;
+        private dbx.AxDbDocument doc_as;
+
+        #region 类初始化及析构操作
+        ///
+        /// 类初始化,试图获取一个正在运行的AutoCAD实例,
+        /// 如果没有则新起动一个实例。
+        ///
+        public AutoCADConnector()
+        {
+            try
+            {
+                //取得一个正在运行的AUTOCAD实例
+                this._Application = (AutoCAD.AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.22");
+            }//end of try
+            catch
+            {
+                try
+                {
+                    //建立一个新的AUTOCAD实例,并标识已经建立成功。
+                    _Application = new AutoCAD.AcadApplication();
+                    _Initialized = true;
+                }
+                catch
+                {
+                    throw new Exception("无法起动AutoCAD应用程序,确认已经安装");
+                }
+            }//end of catch
+        }//end of AutoCADConnector
+
+        ~AutoCADConnector()
+        {
+            Dispose(false);
+        }
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!this._Disposed && this._Initialized)
+            {
+                //如果建立了AUTOCAD的实列,调用QUIT方法以避免内存漏洞
+                this._Application.ActiveDocument.Close(false, "");
+                this._Application.Quit();
+                this._Disposed = true;
+            }
+        }
+        #endregion
+
+        #region 公共用户接口属性
+        ///
+        /// 取得当前类所获得的AUTOCAD实例
+        ///
+        public AutoCAD.AcadApplication Application
+        {
+            get
+            {
+                return _Application;
+            }
+        }//end of Application
+        #endregion
+
+        #region 公共用户接口方法
+        ///
+        /// 根据给定的文件名以AxDbDocument类型返回该文档
+        ///
+        public dbx.AxDbDocument GetThisDrawing(string FileName, string PassWord)
+        {
+            //这是AutoCAD2004的Programe ID
+            string programeID = "ObjectDBX.AxDbDocument.22";
+            AutoCAD.AcadApplication AcadApp = this.Application;
+            dbx.AxDbDocument dbxDoc;
+            dbxDoc = (dbx.AxDbDocument)AcadApp.GetInterfaceObject(programeID);
+            try
+            {
+                if (System.IO.File.Exists(FileName) == false) throw new Exception("文件不存在。");
+
+                dbxDoc.Open(FileName, PassWord);
+            }// end of try
+            catch (Exception e)
+            {
+                System.Windows.Forms.MessageBox.Show(e.Message);
+                dbxDoc = null;
+            }
+            return dbxDoc;
+        }//end of function GetThisDrawing
+
+        ///
+        /// 根据当前文档和块名取得当前块的引用
+        ///
+        public dbx.AcadBlockReference GetBlockReference(dbx.AxDbDocument thisDrawing, string blkName)
+        {
+            dbx.AcadBlockReference blkRef = null;
+            bool found = false;
+            string str = "";
+            try
+            {
+                foreach (dbx.AcadEntity entity in thisDrawing.ModelSpace)
+                {
+                    str += entity.EntityName + ",";
+                    if (entity.EntityName == "AcDbBlockReference")
+                    {
+                        blkRef = (dbx.AcadBlockReference)entity;
+                        //System.Windows.Forms.MessageBox.Show(blkRef.Name);
+                        if (blkRef.Name.ToLower() == blkName.ToLower())
+                        {
+                            found = true;
+                            break;
+                        }
+                    }//end of entity.EntityName=="AcDbBlockReference"
+                }// end of foreach thisDrawing.ModelSpace
+            }//end of try
+            catch (Exception e)
+            {
+                System.Windows.Forms.MessageBox.Show("图形中有未知的错误,格式不正确或图形数据库需要修愎。系统错误提示:" + e.Message, "信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
+                thisDrawing = null;
+            }//end of catch
+            if (!found) blkRef = null;
+
+            return blkRef;
+        }//end of function GetBlockReference
+         ///
+         /// 根据给定的块引用(dbx.AcadBlockReference)和属性名返回属性值
+         ///
+        public object GetValueByAttributeName(dbx.AcadBlockReference blkRef, string AttributeName)
+        {
+            object[] Atts = (object[])blkRef.GetAttributes();
+            object attValue = null;
+            for (int i = 0; i < Atts.Length; i++)
+            {
+                dbx.AcadAttributeReference attRef;
+                attRef = (dbx.AcadAttributeReference)Atts[i];
+                if (attRef.TagString == AttributeName)
+                {
+                    attValue = attRef.TextString;
+                    break;
+                }
+            }//end of for i
+            return attValue;
+        }// end of function
+
+        //===
+
+        ///
+        /// 根据当前文档和实体名取得当前块的引用
+        ///
+        public void GetEntityReference(dbx.AxDbDocument thisDrawing)
+        {
+            dbx.AcadEntity entRef = null;
+            bool found = false;
+            string str = "", str2 = "";
+            try
+            {
+                var mbiDoc = TestCad.Model.Document.CreateDocument();
+
+                foreach (dbx.AcadEntity entity in thisDrawing.ModelSpace)
+                {
+                    if (entity is dbx.AcadBlockReference blockReference)
+                    {
+                        var cadObject = new TestCad.Model.BlockReference();
+                        cadObject.Handle = entity.Handle;
+                        cadObject.Layer = entity.Layer;
+                        cadObject.Rotation = blockReference.Rotation;
+                        cadObject.Position = ExportUtils.Point2XYZ(blockReference.InsertionPoint);
+                        mbiDoc.AddObject(cadObject);
+                    }
+
+                    else if (entity is dbx.AcadLine line)
+                    {
+                        var cadObject = new TestCad.Model.Line();
+                        cadObject.Handle = entity.Handle;
+                        cadObject.Layer = entity.Layer;
+                        cadObject.Start = ExportUtils.Point2XYZ(line.StartPoint);
+                        cadObject.End = ExportUtils.Point2XYZ(line.EndPoint);
+                        mbiDoc.AddObject(cadObject);
+                    }
+
+                    else
+                    {
+                        if (entity is dbx.AcadLWPolyline polyline)
+                        {
+                            var tt = thisDrawing.Database.ObjectIdToObject(polyline.ObjectID);
+
+                            var cadObject = ExportUtils.Coordinates2PloyLine(polyline.Coordinates);
+                            cadObject.Handle = entity?.Handle;
+                            cadObject.Layer = entity.Layer;
+                            mbiDoc.AddObject(cadObject);
+
+                        }
+                        else if (entity is dbx.AcadCircle circle)
+                        {
+                            var cadObject = new TestCad.Model.Circle();
+                            cadObject.Handle = entity.Handle;
+                            cadObject.Layer = entity.Layer;
+                            cadObject.Center = ExportUtils.Point2XYZ(circle.Center);
+                            cadObject.Radius = circle.Radius;
+                            mbiDoc.AddObject(cadObject);
+                        }
+                        else if (entity is dbx.AcadText text)
+                        {
+                            var cadObject = new TestCad.Model.DBText();
+                            cadObject.Handle = entity.Handle;
+                            cadObject.Layer = entity.Layer;
+                            cadObject.Position = ExportUtils.Point2XYZ(text.InsertionPoint);
+                            cadObject.TextString = text.TextString;
+                            mbiDoc.AddObject(cadObject);
+                        }
+                        else if (entity is dbx.AcadHatch hatch)
+                        {
+
+                        }
+                        else if (entity is dbx.AcadMText mtext)
+                        {
+                            var cadObject = new TestCad.Model.DBText();
+                            cadObject.Handle = entity.Handle;
+                            cadObject.Layer = entity.Layer;
+                            cadObject.Position = ExportUtils.Point2XYZ(mtext.InsertionPoint);
+                            cadObject.TextString = mtext.TextString;
+                            mbiDoc.AddObject(cadObject);
+                        }
+                        else if (entity is dbx.AcadSolid solid)
+                        {
+                          
+                        }
+                        else if (entity is dbx.AcadPoint point)
+                        {
+                        
+                        }
+                        else if (entity is dbx.AcadArc arc)
+                        {
+                            var cadObject = new TestCad.Model.Arc();
+                            cadObject.Handle = entity.Handle;
+                            cadObject.Layer = entity.Layer;
+                            cadObject.Center = ExportUtils.Point2XYZ(arc.Center);
+                            cadObject.Radius = arc.Radius;
+                            cadObject.StartPoint = ExportUtils.Point2XYZ(arc.StartPoint);
+                            cadObject.EndPoint = ExportUtils.Point2XYZ(arc.EndPoint);
+                            cadObject.Normal = ExportUtils.Point2XYZ(arc.Normal);
+                            mbiDoc.AddObject(cadObject);
+                        }
+                        else if (entity is dbx.AcadAttribute attribute)
+                        {
+                           
+                        }
+                        else
+                        {
+                            var layer = entity.Layer;
+                            if (layer == "PUB_DIM")
+                            { }
+                            else
+                            {
+                                var tt = entity;
+                            }
+
+                        }
+                    }
+
+                }// end of foreach thisDrawing.ModelSpace
+                mbiDoc.GroupElements();
+                string dataStr = JsonConvert.SerializeObject(mbiDoc);
+                string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
+                string path = Path.Combine($"{thisDrawing.Name}_{fileName}.json");
+                File.AppendAllText(path, dataStr);
+                MessageBox.Show("导出成功");
+                //thisDrawing.SaveAs("D:\\ww.dwg");
+                //thisDrawing.DxfOut("D:\\dxf.dxf", Type.Missing, Type.Missing);
+            }//end of try
+            catch (Exception e)
+            {
+                System.Windows.Forms.MessageBox.Show("图形中有未知的错误,格式不正确或图形数据库需要修愎。系统错误提示:" + e.Message, "信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
+                thisDrawing = null;
+            }//end of catch
+            
+        }//end of function GetBlockReference
+
+        #endregion
+    }//end of class CAutoCADConnector
+}//end of namespace AutoCAD

+ 104 - 0
CadExport.csproj

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{A7F24E0A-8AAE-4484-A5EA-5B7235D095CE}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <RootNamespace>TestCad</RootNamespace>
+    <AssemblyName>TestCad</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject />
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="accoremgd">
+      <HintPath>Dll\accoremgd.dll</HintPath>
+    </Reference>
+    <Reference Include="AcDbMgd">
+      <HintPath>Dll\AcDbMgd.dll</HintPath>
+    </Reference>
+    <Reference Include="AcMgd">
+      <HintPath>Dll\AcMgd.dll</HintPath>
+    </Reference>
+    <Reference Include="Autodesk.AutoCAD.Interop">
+      <HintPath>Dll\Autodesk.AutoCAD.Interop.dll</HintPath>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </Reference>
+    <Reference Include="Autodesk.AutoCAD.Interop.Common">
+      <HintPath>Dll\Autodesk.AutoCAD.Interop.Common.dll</HintPath>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="SAGA.DotNetUtils">
+      <HintPath>Dll\SAGA.DotNetUtils.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="AutoCADConnector.cs" />
+    <Compile Include="ConnectToAcad.cs" />
+    <Compile Include="ExportUtils.cs" />
+    <Compile Include="Model\BlockReference.cs" />
+    <Compile Include="Model\CADObject.cs" />
+    <Compile Include="Model\Arc.cs" />
+    <Compile Include="Model\Document.cs" />
+    <Compile Include="Model\DBText.cs" />
+    <Compile Include="Model\Circle.cs" />
+    <Compile Include="Model\Line.cs" />
+    <Compile Include="Model\PolyLine.cs" />
+    <Compile Include="Model\XYZ.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="WinMain.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="WinMain.Designer.cs">
+      <DependentUpon>WinMain.cs</DependentUpon>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="WinMain.resx">
+      <DependentUpon>WinMain.cs</DependentUpon>
+    </EmbeddedResource>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 42 - 0
ConnectToAcad.cs

@@ -0,0 +1,42 @@
+/* ==============================================================================
+ * 功能描述:ConnectToAcad  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/16 11:54:13
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.AutoCAD.Interop.Common;
+using Autodesk.AutoCAD.Runtime;
+using SmartSoft.ACAD;
+
+namespace TestCad
+{
+    /// <summary>
+    /// ConnectToAcad
+    /// </summary>
+    class ConnectToAcad
+    {
+        public static void Connect(string path)
+        {
+            try
+            {
+                AutoCADConnector acd = new AutoCADConnector();//生成操作类对象
+
+                AxDbDocument doc_as = acd.GetThisDrawing(path, "");
+                if (doc_as != null)
+                {
+                    acd.GetEntityReference(doc_as);
+                }
+                acd.Dispose();
+            }
+            catch (System.Exception ac)
+            {
+                Console.WriteLine(ac);
+                throw;
+            }
+        }
+    }
+}

BIN
Dll/AcDbMgd.dll


BIN
Dll/AcMgd.dll


BIN
Dll/Autodesk.AutoCAD.Interop.Common.dll


BIN
Dll/Autodesk.AutoCAD.Interop.dll


BIN
Dll/SAGA.DotNetUtils.dll


BIN
Dll/accoremgd.dll


+ 56 - 0
ExportUtils.cs

@@ -0,0 +1,56 @@
+/* ==============================================================================
+ * 功能描述:ExportUtils  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:20:14
+ * ==============================================================================*/
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Extend;
+using TestCad.Model;
+
+namespace TestCad
+{
+    /// <summary>
+    /// ExportUtils
+    /// </summary>
+    public class ExportUtils
+    {
+        public static TestCad.Model.XYZ Point2XYZ(object point)
+        {
+            string str = "";
+            XYZ xyz = null;
+            if (point is double[] array)
+            {
+                if (array.Length == 3)
+                {
+                    xyz=new XYZ(){X = array[0],Y= array[1], Z= array[2] };
+                }
+            }
+
+            return xyz;
+        }
+
+        public static TestCad.Model.PolyLine Coordinates2PloyLine(object points)
+        {
+            string str = "";
+            List<XYZ> list=new List<XYZ>();
+            if (points is IEnumerable iEnumerable)
+            {
+                for (int i = 0; i < iEnumerable.GetCount()-1; i=i+2)
+                {
+                    double[] array = {iEnumerable.GetByIndexT<double>(i), iEnumerable.GetByIndexT<double>(i + 1), 0};
+                    XYZ xyz = Point2XYZ(array);
+                    list.Add(xyz);
+                }
+            }
+
+
+            return new PolyLine(list);
+        }
+    }
+}

+ 26 - 0
Model/Arc.cs

@@ -0,0 +1,26 @@
+/* ==============================================================================
+ * 功能描述:Line  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:15:44
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// Line
+    /// </summary>
+    class Arc : CADObject
+    {
+        public XYZ Center { get; set; }
+
+        public double Radius { get; set; }
+        public XYZ StartPoint { get; set; }
+        public XYZ EndPoint { get; set; }
+        public XYZ Normal { get; set; }
+    }
+}

+ 25 - 0
Model/BlockReference.cs

@@ -0,0 +1,25 @@
+/* ==============================================================================
+ * 功能描述:BlockReference  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 15:52:19
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// BlockReference
+    /// </summary>
+    class BlockReference: CADObject
+    {
+
+
+        public XYZ Position { get; set; }
+
+        public double Rotation { get; set; }
+    }
+}

+ 24 - 0
Model/CADObject.cs

@@ -0,0 +1,24 @@
+/* ==============================================================================
+ * 功能描述:CADObject  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 16:18:21
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// CADObject
+    /// </summary>
+    public class CADObject
+    {
+
+        public string Handle { get; set; }
+
+        public string Layer { get; set; }
+    }
+}

+ 23 - 0
Model/Circle.cs

@@ -0,0 +1,23 @@
+/* ==============================================================================
+ * 功能描述:Line  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:15:44
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// Line
+    /// </summary>
+    class Circle : CADObject
+    {
+        public XYZ Center { get; set; }
+
+        public double Radius { get; set; }
+    }
+}

+ 23 - 0
Model/DBText.cs

@@ -0,0 +1,23 @@
+/* ==============================================================================
+ * 功能描述:Line  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:15:44
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// Line
+    /// </summary>
+    class DBText : CADObject
+    {
+        public string TextString { get; set; }
+
+        public XYZ Position { get; set; }
+    }
+}

+ 52 - 0
Model/Document.cs

@@ -0,0 +1,52 @@
+/* ==============================================================================
+ * 功能描述:Document  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 16:18:00
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// Document
+    /// </summary>
+    class Document
+    {
+        private Document()
+        {
+            m_Objects = new List<CADObject>();
+            Elements =new Dictionary<string, List<CADObject>>();
+        }
+
+        public static Document CreateDocument()
+        {
+            return new Document();
+        }
+
+        private List<CADObject> m_Objects;
+        public Dictionary<string, List<CADObject>> Elements { get; private set; }
+
+        public void AddObject(CADObject cadObject)
+        {
+            m_Objects.Add(cadObject);
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="document"></param>
+        public void GroupElements()
+        {
+            var group = m_Objects.GroupBy(bim => bim.GetType().Name);
+            var dic = new Dictionary<string, List<CADObject>>();
+            foreach (var collection in group)
+            {
+                dic[collection.Key + "s"] = collection.ToList();
+            }
+            Elements = dic;
+        }
+    }
+}

+ 23 - 0
Model/Line.cs

@@ -0,0 +1,23 @@
+/* ==============================================================================
+ * 功能描述:Line  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:15:44
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    /// <summary>
+    /// Line
+    /// </summary>
+    class Line: CADObject
+    {
+        public XYZ Start { get; set; }
+
+        public XYZ End { get; set; }
+    }
+}

+ 29 - 0
Model/PolyLine.cs

@@ -0,0 +1,29 @@
+/* ==============================================================================
+ * 功能描述:Polygon  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:18:57
+ * ==============================================================================*/
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    public class PolyLine : CADObject
+    {
+        private List<XYZ> m_Coordinates;
+
+        public List<XYZ> Coordinates
+        {
+            get { return m_Coordinates; }
+            set { m_Coordinates = value; }
+        }
+        public PolyLine(List<XYZ> collection)
+        {
+            m_Coordinates = collection;
+        }
+    }
+}

+ 25 - 0
Model/XYZ.cs

@@ -0,0 +1,25 @@
+/* ==============================================================================
+ * 功能描述:XYZ  
+ * 创 建 者:Garrett
+ * 创建日期:2019/12/17 17:18:42
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad.Model
+{
+    public class XYZ
+    {
+        public double X { get; set; }
+        public double Y { get; set; }
+        public double Z { get; set; }
+
+        public override string ToString()
+        {
+            return $"{X},{Y},{Z}";
+        }
+    }
+}

+ 18 - 0
Program.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestCad
+{
+    class Program
+    {
+        [STAThread]
+        static void Main(string[] args)
+        {
+            WinMain win=new WinMain();
+            win.ShowDialog();
+        }
+    }
+}

+ 36 - 0
Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("TestCad")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("TestCad")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("a7f24e0a-8aae-4484-a5ea-5b7235d095ce")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 25 - 0
TestCad.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26730.3
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CadExport", "CadExport.csproj", "{A7F24E0A-8AAE-4484-A5EA-5B7235D095CE}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{A7F24E0A-8AAE-4484-A5EA-5B7235D095CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A7F24E0A-8AAE-4484-A5EA-5B7235D095CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A7F24E0A-8AAE-4484-A5EA-5B7235D095CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A7F24E0A-8AAE-4484-A5EA-5B7235D095CE}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {60BBB749-41E2-4967-86EF-058BC6BF2D88}
+	EndGlobalSection
+EndGlobal

+ 4 - 0
TestCad.sln.DotSettings.user

@@ -0,0 +1,4 @@
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+	<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
+  &lt;Assembly Path="C:\Users\SAGACLOUD\source\repos\TestCad\Dll\Autodesk.AutoCAD.Interop.Common.dll" /&gt;&#xD;
+&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>

+ 97 - 0
WinMain.Designer.cs

@@ -0,0 +1,97 @@
+namespace TestCad
+{
+    partial class WinMain
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.button1 = new System.Windows.Forms.Button();
+            this.button2 = new System.Windows.Forms.Button();
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.label1 = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(201, 84);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(75, 23);
+            this.button1.TabIndex = 0;
+            this.button1.Text = "导出";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(242, 46);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(34, 23);
+            this.button2.TabIndex = 1;
+            this.button2.Text = "选";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(11, 48);
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(225, 21);
+            this.textBox1.TabIndex = 2;
+            this.textBox1.Text = "D:\\安装包\\CAD\\CAD-Revit模型检查-测试模型\\F4测试.dwg";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(12, 19);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(155, 12);
+            this.label1.TabIndex = 3;
+            this.label1.Text = "请选择需要提取的CAD文件:";
+            // 
+            // WinMain
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(289, 122);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.button2);
+            this.Controls.Add(this.button1);
+            this.Name = "WinMain";
+            this.Text = "提取CAD";
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.Label label1;
+    }
+}

+ 36 - 0
WinMain.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace TestCad
+{
+    public partial class WinMain : Form
+    {
+        public WinMain()
+        {
+            InitializeComponent();
+        }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            ConnectToAcad.Connect(textBox1.Text);
+            this.Close();
+        }
+
+        private void button2_Click(object sender, EventArgs e)
+        {
+            OpenFileDialog dialog=new OpenFileDialog();
+            dialog.Filter = "CAD文件|*.dwg";
+            if (dialog.ShowDialog() == DialogResult.OK)
+            {
+                textBox1.Text = dialog.FileName;
+            }
+        }
+    }
+}

+ 120 - 0
WinMain.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 4 - 0
packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
+</packages>