想要快捷輕巧的轉換矢量圖形?CAD .NET基礎操作示例演示來啦!

CAD .NET一款在CAD領域被廣泛應用的控件,可以快速準確的閱讀DWG和DXF文件,並且通過Windows GDI+方法繪製件,支持多種文件格式,包括DWG、DXF、Gerber、光柵圖像等,並支持部分編輯功能。

CAD .NET本身就是一款快捷方便的CAD文檔瀏覽轉換控件,為了讓大家更快上手使用,小編為大家整理了CAD .NET基礎操作指南,希望對大家有所幫助。

有興趣下載嘗試CAD .NET v14最新版嗎?點擊文末“瞭解更多”下載體驗


想要快捷輕巧的轉換矢量圖形?CAD .NET基礎操作示例演示來啦!


  • 讀取DWG文件
<code> using CADImport;
using CADImport.DWG;
using CADImport.DXF;
using CADImport.RasterImage; /<code>
<code> 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
} /<code>
  • 加載文檔
<code> using CADImport;
using CADImport.DWG;
using CADImport.DXF;
using CADImport.RasterImage; /<code>
<code>   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);
}
/<code>
  • 存取線條
<code> using CADImport;
using CADImport.DWG;
using CADImport.DXF;
using CADImport.RasterImage; /<code>
<code> 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; } } } /<code>
  • 換層
<code> using CADImport;
using CADImport.DWG;

using CADImport.DXF;
using CADImport.RasterImage;
/<code>
<code>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);
}
/<code>
  • 添加,更改,刪除
<code>... 
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);
} /<code>
  • CAD轉換為BMP
<code>... 
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);
} /<code>
  • 查找塊
<code>... 
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; } }/<code>


分享到:


相關文章: