乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 89|回复: 6

如何替换块?

[复制链接]

10

主题

25

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2009-9-18 09:10:00 | 显示全部楼层 |阅读模式
原来图里的符号要替换成新符号,仅仅是符号替换,而不改变xdata和attribute,如何实现?谢谢
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-9-18 09:48:00 | 显示全部楼层
在BlockTable中找到对应的记录,打开
遍历,删除属性定义外的实体
然后加入新实体
回复

使用道具 举报

10

主题

25

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2009-9-18 11:30:00 | 显示全部楼层
有没有代码示例?谢谢
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-9-18 12:31:00 | 显示全部楼层
今天一天都在外面飘,简单描述下吧
获取BlockTable->bt
btr = bt[yourblockname]
foreach(ObjectId id in btr)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite)
if(!(ent is AttDef))
{
ent.earse
}
}
然后加入实体,这部分简化:)
回复

使用道具 举报

10

主题

25

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2009-9-18 14:59:00 | 显示全部楼层
是blockreference
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-9-18 18:36:00 | 显示全部楼层
以为是替换全部呢:)
  1.         [CommandMethod("ts1")]
  2.         public static void tt1()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Editor ed = doc.Editor;
  6.             PromptEntityOptions optsEnt = new PromptEntityOptions("\nSelect a Block:");
  7.             optsEnt.SetRejectMessage("\nNot a Block!");
  8.             optsEnt.AddAllowedClass(typeof(BlockReference), false);
  9.             PromptEntityResult resEnt = ed.GetEntity(optsEnt);
  10.             if (resEnt.Status == PromptStatus.OK)
  11.             {
  12.                 PromptResult resStr = ed.GetString("\nInput BlockName:");
  13.                 if(resStr.Status == PromptStatus.OK)
  14.                 {
  15.                     Database db = doc.Database;
  16.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  17.                     {
  18.                         BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  19.                         BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  20.                         string blkname = resStr.StringResult;
  21.                         if(bt.Has(blkname))
  22.                         {
  23.                             BlockReference blkref = (BlockReference)tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite);
  24.                             BlockReference blkrefnew = new BlockReference(blkref.Position, bt[blkname]);
  25.                             blkrefnew.BlockTransform = blkref.BlockTransform;
  26.                             btr.AppendEntity(blkrefnew);
  27.                             tr.AddNewlyCreatedDBObject(blkrefnew, true);
  28.                             foreach(ObjectId attid in blkref.AttributeCollection)
  29.                             {
  30.                                 AttributeReference att = (AttributeReference)tr.GetObject(attid, OpenMode.ForRead);
  31.                                 AttributeReference attnew = (AttributeReference)att.Clone();
  32.                                 blkrefnew.AttributeCollection.AppendAttribute(attnew);
  33.                                 tr.AddNewlyCreatedDBObject(attnew, true);
  34.                             }
  35.                             blkrefnew.XData = blkref.XData;
  36.                             blkref.Erase();
  37.                             tr.Commit();
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.         }
回复

使用道具 举报

10

主题

25

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2009-9-18 19:50:00 | 显示全部楼层
试试,谢谢先
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 13:19 , Processed in 0.402598 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表