明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8597|回复: 12

[图元] [求助]如何设置块参照的颜色?

  [复制链接]
发表于 2009-10-20 15:25 | 显示全部楼层 |阅读模式

BlockReference 类型的br  用 br.Color = Color.FromColorIndex(ColorMethod.ByBlock, color.ColorIndex);

设置其颜色后br.Color显示正确了 但是没显示应有的颜色 

发表于 2009-10-20 15:33 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2009-10-20 15:42 | 显示全部楼层
不行的 刚试了下
发表于 2009-10-20 15:54 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2009-10-20 16:24 | 显示全部楼层
狐哥,您老在哪儿啊  呼唤。。。。。。。。。。
发表于 2009-10-20 19:21 | 显示全部楼层
本帖最后由 作者 于 2009-10-20 21:07:04 编辑

ColorMethod.ByAci
发表于 2009-10-20 19:48 | 显示全部楼层
快参照的颜色应该是在快定义中设定的,无法改变,除非你改变块定义的颜色,那么所有该块定义的块参照的颜色也就全部改变了。
发表于 2009-10-20 19:55 | 显示全部楼层

可以在块定义的实体设置Color为ByBlock,这样参照的颜色就可以随块改变

发表于 2009-10-20 20:20 | 显示全部楼层
这有两段代码,仅供参考。
  1. // 修改块参照的颜色——编辑块定义中的对象颜色为随块.
  2. [CommandMethod("test1")]
  3. public void MyTest1()
  4. {
  5.     Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  6.     Database db = HostApplicationServices.WorkingDatabase;
  7.     PromptEntityOptions opt = new PromptEntityOptions("\n请选择块参照");
  8.     opt.SetRejectMessage("您选择的不是块参照,请重新选择!");
  9.     opt.AddAllowedClass(typeof(BlockReference), true);
  10.     PromptEntityResult res = ed.GetEntity(opt);
  11.     if (res.Status != PromptStatus.OK)
  12.     {
  13.         return;
  14.     }
  15.     using (Transaction trans = db.TransactionManager.StartTransaction())
  16.     {
  17.         BlockReference ent = (BlockReference)trans.GetObject(res.ObjectId,
  18.             OpenMode.ForWrite);
  19.         BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
  20.             OpenMode.ForRead);
  21.         BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[ent.Name],
  22.             OpenMode.ForWrite);
  23.         BlockTableRecordEnumerator blkRefEnumerator = btr.GetEnumerator();
  24.         while (blkRefEnumerator.MoveNext())
  25.         {
  26.             Entity ee = (Entity)trans.GetObject(blkRefEnumerator.Current,
  27.                 OpenMode.ForWrite);
  28.             if (ee.ColorIndex != 0)
  29.             {
  30.                 ee.ColorIndex = 0;
  31.             }
  32.         }
  33.         ent.ColorIndex = 1;
  34.         trans.Commit();
  35.     }
  36. }
  37. // 修改块参照的颜色——编辑块定义中的对象颜色为新颜色.
  38. [CommandMethod("test2")]
  39. public void MyTest2()
  40. {
  41.     Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  42.     Database db = HostApplicationServices.WorkingDatabase;
  43.     PromptEntityOptions opt = new PromptEntityOptions("\n请选择块参照");
  44.     opt.SetRejectMessage("您选择的不是块参照,请重新选择!");
  45.     opt.AddAllowedClass(typeof(BlockReference), true);
  46.     PromptEntityResult res = ed.GetEntity(opt);
  47.     if (res.Status != PromptStatus.OK)
  48.     {
  49.         return;
  50.     }
  51.     using (Transaction trans = db.TransactionManager.StartTransaction())
  52.     {
  53.         BlockReference ent = (BlockReference)trans.GetObject(res.ObjectId,
  54.             OpenMode.ForRead);
  55.         BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
  56.             OpenMode.ForRead);
  57.         BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[ent.Name],
  58.             OpenMode.ForWrite);
  59.         BlockTableRecordEnumerator blkRefEnumerator = btr.GetEnumerator();
  60.         while (blkRefEnumerator.MoveNext())
  61.         {
  62.             Entity ee = (Entity)trans.GetObject(blkRefEnumerator.Current,
  63.                 OpenMode.ForWrite);
  64.             ee.ColorIndex = 1;
  65.         }
  66.         ed.Regen();
  67.         trans.Commit();
  68.     }
  69. }

评分

参与人数 1威望 +1 明经币 +2 金钱 +10 贡献 +10 激情 +10 收起 理由
雪山飞狐_lzh + 1 + 2 + 10 + 10 + 10 【好评】好程序

查看全部评分

发表于 2009-10-20 20:48 | 显示全部楼层

从功能上而言

ent.Color = Color.FromColorIndex(ColorMethod.ByAci, 0);

等效于

ent.ColorIndex = 0
即随块

不过老卢的写法要简洁些

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-13 19:26 , Processed in 0.170356 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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