• AutoCAD.Net/C#.Net QQ群:193522571 深度克隆 deepclone


    废话不多说,上个例子。更多讨论请加我的QQ群:193522571

    [CommandMethod("copyEnt")]
            public void copyEnt()
                {
                Document doc = AcApp.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;
    
                PromptEntityOptions options = new PromptEntityOptions("
    Select entity to copy");
    
                PromptEntityResult acSSPrompt = ed.GetEntity(options);
    
                if (acSSPrompt.Status != PromptStatus.OK)
                    return;
    
                ObjectIdCollection collection = new ObjectIdCollection();
                collection.Add(acSSPrompt.ObjectId);
    
                //make model space as owner for new entity
                ObjectId ModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
    
                IdMapping mapping = new IdMapping();
                //db.DeepCloneObjects(collection, ModelSpaceId, mapping, false);
    
                //now open the new entity and change the color...
                using (Transaction Tx = db.TransactionManager.StartTransaction())
                    {
                    Entity oldEnt = (Entity)Tx.GetObject(acSSPrompt.ObjectId, OpenMode.ForRead);
                    Entity newEnt = (Entity)oldEnt.DeepClone(oldEnt, mapping, true);
    
    
                    //get the map.
                    IdPair pair1 = mapping[acSSPrompt.ObjectId];
    
                    //new object
                    Entity ent = Tx.GetObject(pair1.Value, OpenMode.ForWrite) as Entity;
    
                    
                    //change the color to red
                    ent.ColorIndex = 1;
                    ent.Highlight();
                    BlockTableRecord btr = (BlockTableRecord)Tx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    btr.AppendEntity(newEnt);
                    Tx.AddNewlyCreatedDBObject(newEnt, true);
    
                    Tx.Commit();
                    }
    
                }
  • 相关阅读:
    SOJ 1035 DNA matching
    SOJ 1027 MJ,Nowhere to Hide
    SOJ 1021 Couples
    SOJ 1020 Big Integer
    C#中正则表达式的简单使用
    根据HTTP header收集客户端相关信息 --- tornado demo
    IIS7配置Gzip压缩
    网站性能工具Yslow的使用方法
    配置ETags
    细说ETags以及如何在 IIS6和 IIS7下取消ETags
  • 原文地址:https://www.cnblogs.com/swtool/p/14491092.html
Copyright © 2020-2023  润新知