[CommandMethod("Hiddenlayer")]
public static void Hiddenlayer()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId idLayer = ObjectId.Null;
// Здесь мы создаём анонимный слой
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
LayerTableRecord ltr = new LayerTableRecord();
ltr.Name = "Test";
ltr.IsHidden = true;
idLayer = lt.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);
tr.Commit();
}
// Здесь мы используем этот слой для добавления полилинии
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Polyline pline = new Polyline();
pline.SetDatabaseDefaults();
pline.AddVertexAt(0, new Point2d(-35, 40), 0, 0, 0);
pline.AddVertexAt(1, new Point2d(-45, 20), 0, 0, 0);
pline.AddVertexAt(2, new Point2d(-75, 20), 0, 0, 0);
pline.AddVertexAt(3, new Point2d(-95, 20), 0, 0, 0);
pline.LineWeight = LineWeight.LineWeight060;
LayerTableRecord ltr = tr.GetObject(idLayer, OpenMode.ForWrite) as LayerTableRecord;
ltr.IsHidden = false; // Убираем признак анонимности
pline.LayerId = idLayer;
ltr.IsHidden = true; // Возвращаем признак анонимности
btr.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
tr.Commit();
}
}