- 积分
- 11674
- 明经币
- 个
- 注册时间
- 2008-5-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2020-7-18 08:19:57
|
显示全部楼层
块遍历,与图层内实体遍历等都是collection遍历,基本上都使用foreach。
PromptEntityResult blockSelected = AutoCadDatabaseOperate.m_ed.GetEntity("请选择一个块参考");
using Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
BlockReference blockReference = trans.GetObject(blockSelected.ObjectId, OpenMode.ForWrite) as BlockReference;
BlockTableRecord btr = trans.GetObject(blockReference.BlockTableRecord, OpenMode.ForWrite) as BlockTableRecord;
foreach (var id in btr)
{
Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;
if (ent is null)
{
continue;
}
else
{
ent.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 3);
}
}
trans.Commit();
|
|