累死了,可不可以这么写?
//添加层 AcDbObjectId CLjDwg::AddLayer(const char* LayerName, const Adesk::Int16 LayerColor, const char* Linetype, AcDbDatabase* pDb) { if(pDb==NULL) pDb=acdbCurDwg(); //装载线型 pDb->loadLineTypeFile(Linetype,LINETYPE_FILENAME); AcDbObjectId LineTypeId=AddLineType(pDb,Linetype);
AcDbLayerTable* pLayerTable=NULL; AcDbLayerTableRecord* pLayerRecord=NULL; AcDbObjectId LayerId=AcDbObjectId::kNull; pDb->getLayerTable(pLayerTable,AcDb::kForWrite); if(!pLayerTable) return FALSE; if(pLayerTable->has(LayerName)) { pLayerTable->getAt(LayerName,LayerId); } else { pLayerRecord=new AcDbLayerTableRecord; AcCmColor color; color.setColorIndex(LayerColor); pLayerRecord->setColor(color); pLayerRecord->setLinetypeObjectId(LineTypeId); pLayerRecord->setName(LayerName); pLayerTable->add(LayerId,pLayerRecord); pLayerRecord->close(); } pLayerTable->close(); return LayerId; }
|