如何把一个对象的颜色设置成 ByLayer
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;
}
.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }
作者:峻祁連
郵箱:junqilian@163.com
出處:http://junqilian.cnblogs.com
轉載請保留此信息。
總結
以上是生活随笔為你收集整理的如何把一个对象的颜色设置成 ByLayer的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 差异表达基因分析:差异倍数(fold c
- 下一篇: Android 9.0 添加预置第三方输