• 大小: 2.31MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-09
  • 语言: 其他
  • 标签: dwg  dxf  CAD  

资源简介

基于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.xml

     文件     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.xml

     文件       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.xml

     文件    1950668  2015-11-13 14:04  bin\WW.xml

     文件       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


评论

共有 条评论