• 大小: 9.2MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-04-10
  • 语言: C#
  • 标签: C#  CAD  .NET  DWG  读取文件  

资源简介

由于公司需求,最近也是找了好久才终于找到C#.NET读取DWG格式的CAD文件信息方法,采用 DWGdirect_NET_3_02动态库里的方法,可以完美的读到DWG文件的信息,这里分享出来,压缩文件包括了DEMO和动态库文件,DEMO可以完美运行(VS2010测试通过,添加的自测的部分注释!)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using DWGdirect.DatabaseServices;
using DWGdirect.Geometry;
using DWGdirect.GraphicsInterface;
using DWGdirect.Colors;
using DWGdirect;
// note that Getobject doesn‘t work in Acad 2009 so we use “obsolete“ Open instead
#pragma warning disable 618

namespace OdReadExMgd
{
  class DbDumper
  {
    public DbDumper() { }

    static string toDegreeString(double val)
    {
      return (val * 180.0 / Math.PI) + “d“;
    }
    static string toHexString(int val)
    {
      return string.Format(“0{0:X}“ val);
    }
    static string toArcSymbolTypeString(int val)
    {
      switch (val)
      {
        case 0: return “Precedes text“;
        case 1: return “Above text“;
        case 2: return “None“;
      }
      return “???“;
    }
    /************************************************************************/
    /* Shorten a path with ellipses.                                        */
    /************************************************************************/
    static string shortenPath(string Inpath int maxPath)
    {
      string path = Inpath;
      /**********************************************************************/
      /* If the path fits just return it                                   */
      /**********************************************************************/
      if (path.Length <= maxPath)
      {
        return path;
      }
      /**********************************************************************/
      /* If there‘s no backslash just truncate the path                    */
      /**********************************************************************/
      int lastBackslash = path.LastIndexOf(‘\\‘);
      if (lastBackslash < 0)
      {
        return path.Substring(0 maxPath - 3) + “...“;
      }

      /**********************************************************************/
      /* Shorten the front of the path                                      */
      /**********************************************************************/
      int fromLeft = (lastBackslash - 3) - (path.Length - maxPath);
      // (12 - 3) - (19 - 10) = 9 - 9 = 0 
      if ((lastBackslash <= 3) || (fromLeft < 1))
      {
        path = “...“ + path.Substring(lastBackslash);
      }
      else
      {
        path = path.Substring(0 fromLeft) + “...“ + path.Substring(lastBackslash);
      }

      /**********************************************************************/
      /* Truncate the path                                                  */
      /**********************************************************************/
      if (path.Length > maxPath)
      {
        path = path.Substring(0 maxPath - 3) + “...“;
      }

      return path;
    }
    static string shortenPath(string Inpath)
    {
      return shortenPath(Inpath 40);
    }

    /****************

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-08-17 17:34  DWGdirect_NET_3_02\
     目录           0  2012-12-04 22:58  DWGdirect_NET_3_02\DWGdirect_NET_3_02\
     目录           0  2020-08-17 17:36  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\
     文件       98968  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\AcIdViewObj_3.02_8.drx
     文件       86680  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\AsdkSmileyDb_3.02_8.drx
     文件       90776  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\AutoSurfServices_3.02_8.drx
     文件      189080  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DbCommands_3.02_8.drx
     文件      709272  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_AcisBuilder_3.02_8.dll
     文件       14488  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Alloc_3.02_8.dll
     文件      311960  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Ave_3.02_8.drx
     文件       16024  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_BmpExport_3.02_8.dll
     文件      307864  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_BrepRenderer_3.02_8.dll
     文件       94872  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Br_3.02_8.dll
     文件      283288  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_DbRoot_3.02_8.dll
     文件     8172184  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Db_3.02_8.dll
     文件      328344  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Dwf7Export_3.02_8.dll
     文件      246424  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Dwf7Import_3.02_8.drx
     文件      123544  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_DwfUnderlay_3.02_8.drx
     文件      381592  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_DynBlocks_3.02_8.drx
     文件      369304  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_FtFontEngine_3.02_8.drx
     文件     1057432  2009-11-11 22:53  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Ge_3.02_8.dll
     文件      701080  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Gi_3.02_8.dll
     文件      475800  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Gs_3.02_8.dll
     文件     4432536  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Mgd_3.02_8.dll
     文件      238232  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_PdfExport_3.02_8.dll
     文件      565912  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Root_3.02_8.dll
     文件      381592  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_Sm_3.02_8.drx
     文件       37016  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_STLExport_3.02_8.drx
     文件      221848  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DD_SvgExport_3.02_8.drx
     文件      303768  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DWFCore.dll
     文件     1516184  2009-11-11 22:54  DWGdirect_NET_3_02\DWGdirect_NET_3_02\bin\DWFToolkit.dll
............此处省略229个文件信息

评论

共有 条评论