找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1411|回复: 0

[分享] Creating block from selection set

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2013-5-25 02:54:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Creating block from selection setBy Virupaksha Aithal
Below code shows the procedure to create a new block table record from entities selected on screen.  The important function used is “DeepCloneObjects” which takes collections of object ids to be copy. The second parameter is the “owner” of the copied entities. In the below code, the block table record (“test”) is passed as owner, so that the selected entities clone objects are copied to block table record
  1. [CommandMethod("CreateBlock")]
  2. public void CreateBlock()
  3. {
  4.     Document doc = Application.DocumentManager.MdiActiveDocument;
  5.     Database db = doc.Database;
  6.     Editor ed = doc.Editor;
  7.     TypedValue[] filterlist = new TypedValue[1];
  8.     filterlist[0] = new TypedValue(0, "CIRCLE,LINE");
  9.     SelectionFilter filter = new SelectionFilter(filterlist);
  10.     PromptSelectionOptions opts = new PromptSelectionOptions();
  11.     opts.MessageForAdding = "Select entities: ";
  12.     PromptSelectionResult selRes = ed.GetSelection(opts, filter);
  13.     if (selRes.Status != PromptStatus.OK)
  14.     {
  15.         return;
  16.     }
  17.     ObjectId[] ids = selRes.Value.GetObjectIds();
  18.     ObjectId blockId = ObjectId.Null;
  19.     //add a block table record with name test...
  20.     using (Transaction Tx = db.TransactionManager.StartTransaction())
  21.     {
  22.         BlockTable bt = (BlockTable)Tx.GetObject(db.BlockTableId,
  23.                                                    OpenMode.ForRead);
  24.         if (!bt.Has("Test"))
  25.         {
  26.             bt.UpgradeOpen();
  27.             //create new
  28.             BlockTableRecord record = new BlockTableRecord();
  29.             record.Name = "Test";
  30.             bt.Add(record);
  31.             Tx.AddNewlyCreatedDBObject(record, true);
  32.         }
  33.         blockId = bt["Test"];
  34.         Tx.Commit();
  35.     }
  36.     //copy the select entities to block by using deepclone.
  37.     ObjectIdCollection collection = new ObjectIdCollection(ids);
  38.     IdMapping mapping = new IdMapping();
  39.     db.DeepCloneObjects(collection, blockId, mapping, false);
  40. }


评分

参与人数 1D豆 +2 收起 理由
ScmTools + 2 很给力!资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-17 19:28 , Processed in 0.165399 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表