I cut and paste the code from the help file but it has some words underlined.
void line 12
and LayerTableRecord? line 30
Does anyone else have problems with the AutoCAD help file?
1>------ Build started: Project: AutoCAD CSharp plug-in23, Configuration: Debug Any CPU ------
1> AutoCAD CSharp plug-in23 -> W:\AcadCode\_Projects\AutoCAD CSharp plug-in23\AutoCAD CSharp plug-in23\bin\Debug\AutoCAD CSharp plug-in23.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
if (acLyrTbl.Has("M-ANNO-TEXT-NEWW") != true)
{
acLyrTbl.UpgradeOpen();
using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
{
acLyrTblRec.Name = "M-ANNO-TEXT-NEWW";
acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
public class newlayertest
{
[CommandMethod("AddMyLayer")]
public static void AddMyLayer()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
if (acLyrTbl.Has("M-ANNO-TEXT-NEWW") != true)
{
acLyrTbl.UpgradeOpen();
using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
{
acLyrTblRec.Name = "M-ANNO-TEXT-NEWW";
acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
acCurDb.Clayer = acLyrTbl["M-ANNO-TEXT-NEWW"];
}
if (acLyrTbl.Has("MyLayer") != true)
{
acLyrTbl.UpgradeOpen();
using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
{
acLyrTblRec.Name = "MyLayer";
acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
acCurDb.Clayer = acLyrTbl["MyLayer"];
}
acTrans.Commit();
}
}
}
}
}
}
if (acLyrTbl.Has("M-HVAC-EQPM-NEWW") != true)
{
// Open the Layer Table for write
acLyrTbl.UpgradeOpen();
// Create a new layer table record and name the layer "MyLayer"
using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
{
acLyrTblRec.Name = "M-HVAC-EQPM-NEWW";
acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
// Add the new layer table record to the layer table and the transaction
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
acCurDb.Clayer = acLyrTbl["M-HVAC-EQPM-NEWW"];
}