// This function creates a new AcDbLayerTableRecord, fills // it in, and adds it to the layer table // // THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT. // void addLayer() { AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTbl, AcDb::kForWrite); if (!pLayerTbl->has(_T("ASDK_TESTLAYER"))) { AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord; pLayerTblRcd->setName(_T("ASDK_TESTLAYER")); pLayerTblRcd->setIsFrozen(0);// layer to THAWED pLayerTblRcd->setIsOff(0); // layer to ON pLayerTblRcd->setVPDFLT(0); // viewport default pLayerTblRcd->setIsLocked(0);// un-locked AcCmColor color; color.setColorIndex(1); // set color to red pLayerTblRcd->setColor(color); // For linetype, we need to provide the object ID of // the linetype record for the linetype we want to // use. First, we need to get the object ID. // AcDbLinetypeTable *pLinetypeTbl; AcDbObjectId ltId; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLinetypeTbl, AcDb::kForRead); if ((pLinetypeTbl->getAt(_T("DASHED"), ltId)) != Acad::eOk) { acutPrintf(_T("\nUnable to find DASHED") _T(" linetype. Using CONTINUOUS")); // CONTINUOUS is in every drawing, so use it. // pLinetypeTbl->getAt(_T("CONTINUOUS"), ltId); } pLinetypeTbl->close(); pLayerTblRcd->setLinetypeObjectId(ltId); pLayerTbl->add(pLayerTblRcd); pLayerTblRcd->close(); pLayerTbl->close(); } else { pLayerTbl->close(); acutPrintf(_T("\nlayer already exists")); } }
Acad::ErrorStatus ArxDbgUtils::addNewLayer(LPCTSTR layerName, AcDbDatabase* db) { ASSERT(db != NULL); // if layer already exists, then just return AcDbLayerTable* layTbl; Acad::ErrorStatus es = db->getSymbolTable(layTbl, AcDb::kForRead); if (es != Acad::eOk) return es; if (layTbl->has(layerName)) { layTbl->close(); return Acad::eOk; } // upgrade to write es = layTbl->upgradeOpen(); if (es != Acad::eOk) { ASSERT(0); layTbl->close(); return es; } // make sure the name gets set ok AcDbLayerTableRecord* newRec = new AcDbLayerTableRecord; es = newRec->setName(layerName); if (es != Acad::eOk) { delete newRec; layTbl->close(); return Acad::eInvalidInput; } // look up value for default linetype CONTINUOUS, // AcDbLayerTableRecord doesn't set this automatically (at least it didn't in Sedona) newRec->setLinetypeObjectId(db->continuousLinetype()); es = layTbl->add(newRec); if (es != Acad::eOk) delete newRec; else newRec->close(); layTbl->close(); return es; }