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
转载请保留此信息。