原创|使用教程|编辑:李显亮|2020-04-21 11:47:45.367|阅读 307 次
概述:CAD .NET本身就是一款快捷方便的CAD文档浏览转换控件,为了让大家更快上手使用,小编为大家整理了CAD .NET基础操作指南,希望对大家有所帮助。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
CAD .NET一款在CAD领域被广泛应用的控件,可以快速准确的阅读DWG和DXF文件,并且通过Windows GDI+方法绘制件,支持多种文件格式,包括DWG、DXF、Gerber、光栅图像等,并支持部分编辑功能。
CAD .NET本身就是一款快捷方便的CAD文档浏览转换控件,为了让大家更快上手使用,小编为大家整理了CAD .NET基础操作指南,希望对大家有所帮助。
有兴趣尝试最新版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 other
formatsuse the corresponding classes.
//E.g. for DXF: CADImage class, for PLT/HPGL: HPGLImage class.
DWGImage vDrawing = new DWGImage();
vDrawing.LoadFromFile(@"..\..\..\Files\Gasket.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 demo
Viewer
// 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, 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);
// 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(@"..\..\..\Files\Entities.dxf");
vDrawing.LoadFromFile(@"..\..\..\Files\Entities.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(@"..\..\..\Files\Entities.dxf");
vDrawing.LoadFromFile(@"..\..\..\Files\Entities.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(@"..\..\..\Files\Entities.dxf");
vDrawing.LoadFromFile(@"..\..\..\Files\Entities.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(@"..\..\..\Files\Entities.dxf");
vDrawing.LoadFromFile(@"..\..\..\Files\Entities.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; } }
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn