注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

信息 灵感 创新

I? =Information,Inspiration,Innovation

 
 
 

日志

 
 
关于我

we are 5. Mathematics, Computation, Programming, Engineering, and Making fun of life.

网易考拉推荐

AutoCAD 图层合并函数  

2014-04-08 22:00:12|  分类: ObjectARX |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
/*
 * 图层合并函数
 * 源图层下的对象将被合并到目标图层
 * 被移动的对象,颜色、线型、线宽等均被设置为ByLayer
 * 源图层将被删除
 *  可能引发异常:
 *  1.源图层是0层、Defpoints层或者当前图层
 *  2.源图层或目标图层名称不存在
 */
public static void LayerMerge(string destLayer, string sourceLayer)
{
    if (string.IsNullOrEmpty(destLayer) || string.IsNullOrEmpty(sourceLayer))
        return;
    if(sourceLayer=="0"||sourceLayer=="Defpoints")
        throw new System.Exception("Layer 0 or Defpoints could be as Source Layer ");
    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    DocumentLock dl = doc.LockDocument();
    Transaction trans = db.TransactionManager.StartTransaction();
    try
    {
        LayerTable lt = trans.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
        LayerTableRecord layer1 = trans.GetObject(lt[destLayer], OpenMode.ForWrite) as LayerTableRecord;
        if (layer1 == null)
            throw new System.Exception("Destination Layer not Exist");
        LayerTableRecord layer2 = trans.GetObject(lt[sourceLayer], OpenMode.ForWrite) as LayerTableRecord;
        if (layer2 == null)
            throw new System.Exception("Source Layer not Exist");
        if(layer2.Id==db.Clayer)
            throw new System.Exception("current layer could not be as Source Layer");
        //work chunk
        TypedValue[] tv = new TypedValue[] { new TypedValue((int)DxfCode.LayerName, sourceLayer) };
        SelectionFilter sf = new SelectionFilter(tv);
        SelectionSet ss = doc.Editor.SelectAll(sf).Value;
        if (ss != null && ss.Count != 0)
        {
            foreach (SelectedObject so in ss)
            {
                Entity ent = (Entity)trans.GetObject(so.ObjectId, OpenMode.ForWrite);
                ent.Layer = destLayer;
                ent.Linetype = "ByLayer";
                ent.ColorIndex = 256;
                ent.LineWeight = layer1.LineWeight;
            }
        }
        lt.GenerateUsageData();
        layer2.Erase(true);
        trans.Commit();
    }
    catch
    {
        throw;
        trans.Abort();
    }
    finally
    {
        trans.Dispose();
        dl.Dispose();
    }
}
  评论这张
 
阅读(672)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016