資源簡介
基于CADlib 4.0.36.67三方庫,可以讀寫CAD的dwg和dxf文件,將其轉換為需要的格式。

代碼片段和文件信息
#region?(C)?Wout?Ware?2005-2007
//
//?File:?DxfExportExample.cs
//
//?(c)?2005-2007?Wout?Ware?All?Rights?Reserved.
//
#endregion
using?System;
using?System.Drawing;
using?System.Drawing.Printing;
using?System.IO;
using?WW.Cad.base;
using?WW.Cad.Drawing;
using?WW.Cad.Drawing.GDI;
using?WW.Cad.IO;
using?WW.Cad.Model;
using?WW.Math;
namespace?DxfExportExample
{
????class?DxfExportExample
????{
????????public?static?void?Main(string[]?args)
????????{
????????????string?format?=?“pdf“;//輸出格式為PDF格式
????????????string?filename?=?“..\\bin\\12.dwg“;//采用相對路徑
????????????//“C:\\Users\\Administrator\\Desktop\\12.dwg“;//?args[1];
????????????DxfModel?model?=?null;
????????????try?{
????????????????string?extension?=?Path.GetExtension(filename);
????????????????if?(string.Compare(extension?“.dwg“?true)?==?0)?{
????????????????????model?=?DwgReader.Read(filename);
????????????????}?else?{
????????????????????model?=?DxfReader.Read(filename);
????????????????}
????????????}?catch?(Exception?e)?{
????????????????Console.Error.WriteLine(“Error?occurred:?“?+?e.Message);
????????????????Environment.Exit(1);
????????????}
????????????string?outfile?=?Path.GetFileNameWithoutExtension(Path.GetFullPath(filename));
????????????Stream?stream;
????????????if?(format?==?“pdf“)?{
????????????????BoundsCalculator?boundsCalculator?=?new?BoundsCalculator();
????????????????boundsCalculator.GetBounds(model);
????????????????Bounds3D?bounds?=?boundsCalculator.Bounds;
????????????????PaperSize?paperSize?=?PaperSizes.GetPaperSize(PaperKind.Letter);
????????????????//?Lengths?in?inches.
????????????????float?pageWidth?=?(float)paperSize.Width?/?100f;
????????????????float?pageHeight?=?(float)paperSize.Height?/?100f;
????????????????float?margin?=?0.5f;
????????????????//?Scale?and?transform?such?that?its?fits?max?width/height
????????????????//?and?the?top?left?middle?of?the?cad?drawing?will?match?the?
????????????????//?top?middle?of?the?pdf?page.
????????????????//?The?transform?transforms?to?pdf?pixels.
????????????????Matrix4D?to2DTransform?=?DxfUtil.GetScaleTransform(
????????????????????bounds.Corner1
????????????????????bounds.Corner2
????????????????????new?Point3D(bounds.Center.X?bounds.Corner2.Y?0d)
????????????????????new?Point3D(new?Vector3D(margin?margin?0d)?*?PdfExporter.InchToPixel)
????????????????????new?Point3D(new?Vector3D(pageWidth?-?margin?pageHeight?-?margin?0d)?*?PdfExporter.InchToPixel)
????????????????????new?Point3D(new?Vector3D(pageWidth?/?2d?pageHeight?-?margin?0d)?*?PdfExporter.InchToPixel)
????????????????);
????????????????using?(stream?=?File.Create(outfile?+?“.pdf“))?{
????????????????????PdfExporter?pdfGraphics?=?new?PdfExporter(stream);
????????????????????pdfGraphics.DrawPage(
????????????????????????model?
????????????????????????GraphicsConfig.WhiteBackgroundCorrectForBackColor?
????????????????????????to2DTransform
????????????????????????paperSize
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5011??2010-07-10?11:12??DxfExportExampleCS?VS2010.csproj
?????文件????????939??2010-07-10?11:10??DxfExportExampleCS?VS2010.sln
?????文件??????34494??2008-04-13?18:41??Wout?Ware.ico
?????文件?????164248??2019-02-11?08:43??bin\12.dwg
?????文件?????633009??2019-02-11?09:16??bin\12.pdf
?????文件??????42496??2019-02-11?09:18??bin\DxfExportExample.exe
?????文件????????144??2010-07-10?11:12??bin\DxfExportExample.exe.config
?????文件??????13824??2019-02-11?09:18??bin\DxfExportExample.pdb
?????文件?????200704??2011-10-06?12:12??bin\ICSharpCode.SharpZipLib.dll
?????文件????3073536??2015-11-15?15:21??bin\WW.Cad.dll
?????文件????4249856??2015-11-13?14:04??bin\WW.Cad.xm
?????文件?????938496??2015-11-15?15:17??bin\WW.dll
?????文件??????84992??2015-11-15?15:15??bin\WW.GL.dll
?????文件??????63457??2015-11-13?14:04??bin\WW.GL.xm
?????文件???????7168??2015-11-15?15:09??bin\WW.License.dll
?????文件?????159232??2015-11-15?14:49??bin\WW.Pdf.dll
?????文件?????208289??2015-11-13?14:04??bin\WW.Pdf.xm
?????文件????1950668??2015-11-13?14:04??bin\WW.xm
?????文件???????1284??2008-04-13?18:41??Properties\AssemblyInfo.cs
?????文件????????144??2010-07-10?11:12??app.config
?????文件???????5053??2019-02-11?09:20??DxfExportExample.cs
?????目錄??????????0??2019-02-11?09:20??bin
?????目錄??????????0??2019-02-11?08:17??Properties
-----------?---------??----------?-----??----
?????????????11837044????????????????????23
評論
共有 條評論