AutoCAD  .net API中可以用如下代码来设置entity的颜色为bylayer,请注意 BYLAYER的colorIndex为256。很简单,光贴代码。

 [CommandMethod("SetColorByLayer")]
public void SetColorByLayer()
{
ObjectId objId = GetSelectEntity();
using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
Entity ent = trans.GetObject(objId, OpenMode.ForWrite) as Entity;
//the corlor index of "BYLAYER" is 256, "BYBLOCK" is 0
ent.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, 256);
trans.Commit();
}
}
private ObjectId GetSelectEntity()
{
ObjectId oid = ObjectId.Null;
using (DocumentLock docLoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
PromptEntityOptions selectionOp = new PromptEntityOptions("\nselect entity");
PromptEntityResult prRes = ed.GetEntity(selectionOp);
if (prRes.Status == PromptStatus.OK)
{
oid = prRes.ObjectId;
}
}
return oid;
}

相关文章:

  • 2022-01-06
  • 2021-07-02
  • 2021-12-22
  • 2021-08-11
  • 2021-04-20
  • 2021-12-25
  • 2022-02-14
猜你喜欢
  • 2022-02-02
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案