以下示例演示如何获取当前数据库的图层表并将其打开以进行写入。它创建一个新的图层表记录 () 并设置图层的某些属性(名称、冻结属性、开/关、视口和锁定)。然后,它创建一个颜色类对象,并将图层的颜色设置为红色。AcDbLayerTableRecord 要设置图层的线型,本示例将打开线型表进行读取,并获取所需线型的线型记录的对象 ID(此处为“虚线”)。获得线型的对象 ID 后,将关闭线型表并为新图层表记录设置线型。此示例使用函数将图层表记录添加到图层表中。最后,它关闭图层表记录和图层表本身。add() void addLayer() { AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTbl, AcDb::kForWrite); if (!pLayerTbl->has("ASDK_TESTLAYER")) { AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord; pLayerTblRcd->setName("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("DASHED", ltId)) != Acad::eOk) { acutPrintf("\nUnable to find DASHED" " linetype. Using CONTINUOUS"); // CONTINUOUS is in every drawing, so use it. // pLinetypeTbl->getAt("CONTINUOUS", ltId); } pLinetypeTbl->close(); pLayerTblRcd->setLinetypeObjectId(ltId); pLayerTbl->add(pLayerTblRcd); pLayerTblRcd->close(); pLayerTbl->close(); } else { pLayerTbl->close(); acutPrintf("\nlayer already exists"); } } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:23
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.