想要快捷轻巧的转换矢量图形?CAD .NET基础操作示例演示来啦!

CAD .NET本身就是一款快捷方便的CAD文档浏览转换控件,为了让大家更快上手使用,小编为大家整理了CAD .NET基础操作指南,希望对大家有所帮助。

CAD .NET本身就是一款快捷方便的CAD文档浏览转换控件,为了让大家更快上手使用,小编为大家整理了CAD .NET基础操作指南,希望对大家有所帮助。

有兴趣尝试最新版CAD .NET v14吗即下载试用版吧:

CAD .NET v14最新版下载>>>

  • 读取DWG文件

     using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage;           
     private void Read_DWG_Click(object sender, EventArgs e)        {            //DWGImage class is used only for reading DWG. To read otherformatsuse the corresponding classes.            //E.g. for DXF: CADImage class, for PLT/HPGL: HPGLImage class.            DWGImage vDrawing = new DWGImage();            vDrawing.LoadFromFile(@"......FilesGasket.dwg");            vDrawing.Draw(Image1.CreateGraphics(), new RectangleF(0, 0,(float)vDrawing.AbsWidth, (float)vDrawing.AbsHeight));            // zooming and panning of the drawing are implemented in the demoViewer            // via a special viewing control class CADPictureBox        }  
  • 加载文档

     using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage;           
       private void Load_file_Click(object sender, EventArgse)        {            if ((OpenFileDialog1.ShowDialog() != DialogResult.OK)) return;            //CADImage.CreateImageByExtension detects format by the extensionspecified in the argument.            //The correct class for any supported format will be usedautomatically. We recommend to            //create a new drawing object with CADImage.CreateImageByExtensionif import from the existed            //file/stream is required.            CADImage vDrawing =CADImage.CreateImageByExtension(OpenFileDialog1.FileName);            vDrawing.LoadFromFile(OpenFileDialog1.FileName);            // adjusting of the visualization sizes to the control area:            RectangleF vRect;            double vRatio = (double)(vDrawing.AbsHeight * Image1.ClientSize.Width)/ (vDrawing.AbsWidth * Image1.ClientSize.Height);            if (vRatio > 1)                vRect = new RectangleF(0, 0, (float)(Image1.ClientSize.Width /vRatio), (float)Image1.ClientSize.Height);            else                vRect = new RectangleF(0, 0, (float)Image1.ClientSize.Width,(float)(Image1.ClientSize.Height * vRatio));            //-----------------------------------------------            vDrawing.Draw(Image1.CreateGraphics(), vRect);        }             
  • 存取线条

     using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage;           
     private void Access_line_data_Click(object sender, EventArgs e){    //CADImage.CreateImageByExtension detects format with by the extension specified in the argument.    //The correct class for any supported format will be used automatically. We recommend to    //create a new drawing object with CADImage.CreateImageByExtension if import from the existed    //file/stream is required.    CADImage vDrawing = CADImage.CreateImageByExtension(@"......FilesEntities.dxf");    vDrawing.LoadFromFile(@"......FilesEntities.dxf");    for (int i = 0; i < vDrawing.CurrentLayout.Count; i++) { if (vDrawing.CurrentLayout.Entities[i].EntType == EntityType.Line) { CADLine vLine = (CADLine)vDrawing.CurrentLayout.Entities[i]; MessageBox.Show("Line is found. Handle = " + vLine.Handle + "; X: " + vLine.Point.X + "; Y: " + vLine.Point.Y + "; X1: " + vLine.Point1.X + "; Y1: " + vLine.Point1.Y); break; } } } 
  • 换层

     using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage;           
    private void Change_layers_Click(object sender, EventArgs e){    //CADImage.CreateImageByExtension detects format by the extension specified in the argument.    //The correct class for any supported format will be used automatically. We recommend to    //create a new drawing object with CADImage.CreateImageByExtension if import from the existed    //file/stream is required.    CADImage vDrawing = CADImage.CreateImageByExtension(@"......FilesEntities.dxf");    vDrawing.LoadFromFile(@"......FilesEntities.dxf");    // Changes color for Layer '0'    vDrawing.Converter.LayerByName("0").Color = Color.Red;    // If Layer2 doesn't exist, it will be created    CADLayer vLayer = vDrawing.Converter.LayerByName("Layer2");    vLayer.Visible = false; //Changes layer visibility    // Adjusting visualization sizes to the control area:    RectangleF vRect;    double vRatio = (double)(vDrawing.AbsHeight * Image1.ClientSize.Width) / (vDrawing.AbsWidth * Image1.ClientSize.Height);    if (vRatio > 1)        vRect = new RectangleF(0, 0, (float)(Image1.ClientSize.Width / vRatio), (float)Image1.ClientSize.Height);    else        vRect = new RectangleF(0, 0, (float)Image1.ClientSize.Width, (float)(Image1.ClientSize.Height * vRatio));    //-----------------------------------------------    vDrawing.Draw(Image1.CreateGraphics(), vRect);}                          
  • 添加,更改,删除

     ... using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage; ...           private void Add_change_delete_Click(object sender, EventArgs e)         {             //CADImage.CreateImageByExtension detects format by the extension specified in the argument.             //The correct class for any supported format will be used automatically. We recommend to             //create a new drawing object with CADImage.CreateImageByExtension if import from the existed             //file/stream is required.             CADImage vDrawing = CADImage.CreateImageByExtension(@"......FilesEntities.dxf");             vDrawing.LoadFromFile(@"......FilesEntities.dxf");             // Changes color             vDrawing.CurrentLayout.Entities[1].Color = Color.Blue;             vDrawing.CurrentLayout.Entities[1].LineWeight = 2;             vDrawing.Converter.Loads(vDrawing.CurrentLayout.Entities[1]);             //Removes the circle entity from the Entities.dxf drawing             vDrawing.CurrentLayout.Entities.RemoveAt(2);             // Creating a new entity - line             CADLine vLine = new CADLine();             vLine.Point = new DPoint(50, 0, 0);             vLine.Point1 = new DPoint(50, 70, 10);             vLine.LineWeight = 1;             vDrawing.Converter.Loads(vLine);             vDrawing.CurrentLayout.AddEntity(vLine);             // Recalculates the extents of the drawing             vDrawing.GetExtents();             // Adjusting visualization sizes to the control area:             RectangleF vRect;             double vRatio = (double)(vDrawing.AbsHeight * Image1.ClientSize.Width) / (vDrawing.AbsWidth * Image1.ClientSize.Height);             if (vRatio > 1)                 vRect = new RectangleF(0, 0, (float)(Image1.ClientSize.Width / vRatio), (float)Image1.ClientSize.Height);             else                 vRect = new RectangleF(0, 0, (float)Image1.ClientSize.Width, (float)(Image1.ClientSize.Height * vRatio));             //-----------------------------------------------             vDrawing.Draw(Image1.CreateGraphics(), vRect);         }                          
  • CAD转换为BMP

    ... using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage; ...          private void CAD_to_BMP_Click(object sender, EventArgs e)         {             if ((OpenFileDialog1.ShowDialog() != DialogResult.OK)) return;             //CADImage.CreateImageByExtension detects format by the extension specified in the argument.             //The correct class for any supported format will be used automatically. We recommend to             //create a new drawing object with CADImage.CreateImageByExtension if import from the existed             //file/stream is required.             CADImage vDrawing = CADImage.CreateImageByExtension(OpenFileDialog1.FileName);             vDrawing.LoadFromFile(OpenFileDialog1.FileName);             // The bitmap will have 1000 px width, height will be calulated automatically             Bitmap vBitmap = new Bitmap(1000, (int)(1000 * vDrawing.AbsHeight / vDrawing.AbsWidth));             Graphics vGr = Graphics.FromImage(vBitmap);             RectangleF vRect = new RectangleF(0, 0, (float)1000, (float)(vBitmap.Width * vDrawing.AbsHeight / vDrawing.AbsWidth));             vDrawing.Draw(vGr, vRect);             vBitmap.Save(OpenFileDialog1.FileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);         }                              
  • 查找块

    ... using CADImport; using CADImport.DWG; using CADImport.DXF; using CADImport.RasterImage; ...          private void Find_block_Click(object sender, EventArgs e)         {             //CADImage.CreateImageByExtension detects format by the extension specified in the argument.             //The correct class for any supported format will be used automatically. We recommend to             //create a new drawing object with CADImage.CreateImageByExtension if import from the existed             //file/stream is required.             CADImage vDrawing = CADImage.CreateImageByExtension(@"......FilesEntities.dxf");             vDrawing.LoadFromFile(@"......FilesEntities.dxf");              string BlockName = "Block1"; //The block name is Block1             for (int i = 0; i < vDrawing.Converter.Blocks.Count; i++) if (((CADBlock)vDrawing.Converter.Blocks[i]).Name.ToLower() == BlockName.ToLower()) { //found MessageBox.Show("Block with name '" + BlockName + "' has found.nIndex of the block is " + i); break; } } 

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年3月18日
下一篇 2020年3月18日

相关推荐

发表回复

登录后才能评论