您的位置:网站首页 > CAD新闻

MapControl加载CAD数据的示例代码

时间:2011-08-21 16:57:00 来源:未知

MapControl加载CAD数据的示例代码

cadFile代表AutoCad文件的路径

private void btnLoadCAD_Click(object sender, EventArgs e)
        
{
            
string cadFile = @"F:AEStudyzxgTest.dwg";
            
string workspacePath = System.IO.Path.GetDirectoryName(cadFile);
            
string fileName = System.IO.Path.GetFileName(cadFile);

            
//Add passed file to MapControl
            ICadDrawingDataset cadDrawingDataset = GetCadDataset(workspacePath, fileName);
            
if (cadDrawingDataset == nullreturn;
            ICadLayer cadLayer 
= new#p#分页标题#e# CadLayerClass();
            cadLayer.CadDrawingDataset 
= cadDrawingDataset;
            cadLayer.Name 
= fileName;
            mapMain.AddLayer(cadLayer, 
0);
        }


        
private ICadDrawingDataset GetCadDataset(string cadWorkspacePath, string cadFileName)
        
{
            
//Create a WorkspaceName object
            IWorkspaceName workspaceName = new WorkspaceNameClass();
            workspaceName.WorkspaceFactoryProgID 
= "esriDataSourcesFile.CadWorkspaceFactory";
            workspaceName.PathName 
= cadWorkspacePath;

            
//Create a CadDrawingName object
            IDatasetName cadDatasetName #p#分页标题#e#= new CadDrawingNameClass();
            cadDatasetName.Name 
= cadFileName;
            cadDatasetName.WorkspaceName 
= workspaceName;

            
//Open the CAD drawing
            IName name = (IName)cadDatasetName;
            
return (ICadDrawingDataset)name.Open();
        }


            比较困惑的是AutoCAD和地图文件的坐标怎么匹配。