zoukankan      html  css  js  c++  java
  • 根据块名删除块和根据块名删除块引用 的区别

    ** 删除块后,块引用如果有那么依然存在,打开文件时会报错
    ** 删除块引用后块一定存在
     最好的办法是先全部删除块引用,然后再删除块,这样在打开图纸时才不会报错
     以下是写好的现成的两个方法

    //根据块名删除块引用
            internal static void DeleteBlockRefByBlockName(Database db, string strBlockName, string strBlockName1)
            {
                Transaction tr = db.TransactionManager.StartTransaction();
                using (tr)
                {
                    BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    foreach (ObjectId objId in btr)
                    {
                        DBObject dbObj = tr.GetObject(objId, OpenMode.ForWrite);
                        if (dbObj is BlockReference )
                        {
                            BlockReference refEnt=dbObj as BlockReference ;
                            BlockTableRecord mtbtr = (BlockTableRecord)tr.GetObject(refEnt.BlockTableRecord , OpenMode.ForWrite);
                            if (mtbtr.Name.Equals(strBlockName) || (mtbtr.Name.Equals(strBlockName1)))
                            {
                                refEnt.Erase();
                            }
                        }
                    }
                    tr.Commit();
                }
            }

     


            //根据块名删除块
            internal static void DeleteBlockByBlockName(Database db,string strBlockName, string strBlockName1)
            {
                Transaction tr = db.TransactionManager.StartTransaction();
                using (tr)
                {
                    BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    foreach (ObjectId objId in bt)
                    {
                        BlockTableRecord bbtr = tr.GetObject(objId, OpenMode.ForWrite) as BlockTableRecord;
                        if (bbtr.Name.Equals(strBlockName) || (bbtr.Name.Equals(strBlockName1)))
                        {
                            bbtr.Erase();
                        }
                    }
                    tr.Commit();
                }
            }

  • 相关阅读:
    查看MAC系统JRE和JDK版本
    【转】频点CTO张成:基于Cocos2d的MMORPG开发经验
    Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
    常见android手机分辨率(xxhdpi,xhdpi)
    Android市场官方的统计信息
    【转】腾讯分析移动设备屏幕分辨率分析报告-(数据基于2012年12月至2013年1月上半月)
    error “base class has incomplete type”
    Eclipse 各种包说明
    怎么鉴别五帝钱真假
    【jzoj 6276】树(线段树)(扫描线)
  • 原文地址:https://www.cnblogs.com/houlinbo/p/1563210.html
Copyright © 2011-2022 走看看