Creating a anonymous Layer

By Virupaksha Aithal

To create anonymous Layer, you need to call “AcDbLayerTable::setIsHidden()” API as shown in below code. Anonymous layers are not shown in layer manager and hence users can not edit/delete the setting of anonymous layers.

void CreateAnonymousLayer()
{
    AcDbObjectId layerId = AcDbObjectId::kNull;
    AcDbLayerTable* lTable = NULL;
 
    AcDbDatabase *pDb = acdbHostApplicationServices()->
                                        workingDatabase();
 
    Acad::ErrorStatus es = 
                pDb->getSymbolTable(lTable, AcDb::kForWrite);
 
    if(Acad::eOk == es && lTable)
    {
          AcDbLayerTableRecord* lTblRec = 
                new AcDbLayerTableRecord();
          lTblRec->setName(ACRX_T("TEST"));
 
          lTblRec->setIsHidden(true);
 
          if (lTable->add(layerId, lTblRec) != Acad::eOk)
              ::acutPrintf(_T("ERROR Creating Layern"));
          else
            lTblRec->close();
 
          lTable->close();
    }
 
}
.NET
[CommandMethod("Hiddenlayer")]
public void Hiddenlayer()
{
 Document doc = Application.DocumentManager.MdiActiveDocument;
 Database db = doc.Database;
 Editor ed = doc.Editor;
 
 using (Transaction tr =
        db.TransactionManager.StartTransaction())
 {
     LayerTable table =
     tr.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
 
     LayerTableRecord Anonymous = new LayerTableRecord();
     Anonymous.Name = "Test";
     Anonymous.IsHidden = true;
 
 
     table.Add(Anonymous);
     tr.AddNewlyCreatedDBObject(Anonymous, true);
     tr.Commit();
 
 }
}

Comments

One response to “Creating a anonymous Layer”

  1. Documentation on this topic is broken in the Managed Class Reference Guide. For the properties IsHidden and IsLoked, the description is “Assesses if the layer is frozen.”

Leave a Reply to Maxence DELANNOYCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading