http://bbs.mjtd.com/thread-180964-1-1.html可以参考这个,加点判断就可以了
感谢大咖:handshake 666SHUN 发表于 2021-12-24 17:51
ChangeEntityColor()那这个就是自定义方法了,官方文件没有。这个方法代码可以贴来不?
/// <summary>
/// 改变图形颜色
/// </summary>
/// <param name="c1Id">图形的ObjectId</param>
/// <param name="colorIndex">颜色索引</param>
public static void ChangeEntityColor(this ObjectId c1Id, short colorIndex)
{
//图形数据库
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//打开块表
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
//打开块表记录
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForRead);
//获取图形对象
Entity ent1 = (Entity)c1Id.GetObject(OpenMode.ForWrite);
ent1.ColorIndex = colorIndex;
trans.Commit();
}
} wang2006zhi 发表于 2021-12-30 13:47
///
/// 改变图形颜色
///
李小科写法,不推荐 psr.Value.GetEntities<Entity>().ForEach(x => x.ForWrite(e =>
{
if (e is BlockReference brf)
{
using var tr = new DBTrans();
var btr = tr.BlockTable.GetRecord(brf.BlockTableRecord, OpenMode.ForRead);
foreach (ObjectId id in btr)
{
var e1 = tr.GetObject<Entity>(id, OpenMode.ForWrite);
if (e1 is BlockReference brf1)
{
var btr1 = tr.BlockTable.GetRecord(brf1.BlockTableRecord, OpenMode.ForRead);
foreach (ObjectId id1 in btr1)
{
var ent1 = tr.GetObject<Entity>(id1, OpenMode.ForWrite);
ent1.ColorIndex = colorI;
}
}
else
{
e1.ColorIndex = colorI;
}
}
}
if (e is Entity ent)
{
ent.ColorIndex = colorI;
}
})); wang2006zhi 发表于 2022-4-13 16:43
psr.Value.GetEntities().ForEach(x => x.ForWrite(e =>
{
...
感谢指导:hug:
页:
1
[2]