如何修改对象颜色
1 Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex) 2 { 3 AcDbEntity *pEntity; //申明指向实体的指针 4 acdbOpenAcDbEntity(pEntity,entId,AcDb::kForWrite); //以写方式获取实体对象 5 pEntity->setColorIndex(colorIndex); //修改实体颜色 6 pEntity->close(); //关闭实体 7 8 return Acad::eOk; 9 }
1 static void CADShellCreateEntsUnmanaged_ChangeColor(void) 2 { 3 AcDbObjectId oId; 4 oId = CCreateEnt::CreateLine(); //创建直线,获取直线ObjectId 5 CModifyEnt::ChangeColor(oId,1); //修改直线颜色 6 }
acdbOpenAcDbEntity函数,打开继承AcDbEntity的数据库常驻对象,这些对象一般都可在窗口中显示,如直线,圆
acdbOpenAcDbObject函数,打开层表,线性表等
acdbOpenObject函数,打开继承AcDbEntity的数据库常驻对象。
打开的对象操作完成后需要close
CreateLine方法已在“创建直线”这篇文章中实现。
修改图层方法的实现函数:
1 Acad::ErrorStatus CModifyEnt::ChangeLayer(AcDbObjectId entId,CString strLayerName) 2 { 3 AcDbEntity *pEnt; 4 acdbOpenObject(pEnt,entId,AcDb::kForWrite); //打开对象 5 pEnt->setLayer(strLayerName); //修改图层 6 pEnt->close(); 7 return Acad::eOk; 8 }
strLayerName必须是已经存在的图层
修改对象线型的实现函数:
1 Acad::ErrorStatus CModifyEnt::ChangeLinetype(AcDbObjectId entId, CString strLineTypeName) 2 { 3 AcDbEntity *pEnt; 4 acdbOpenObject(pEnt,entId,AcDb::kForWrite); //打开对象 5 pEnt->setLinetype(strLineTypeName); //设置对象的线型名称 6 pEnt->close(); 7 ret
strLineTypeName必须是已经存在的线型的名称
提交对象到模型空间的实现函数
1 AcDbObjectId CCreateEnt::PostToModelSpace(AcDbEntity *pEnt) 2 { 3 AcDbBlockTable* pBlockTable; //申明块表对象 4 acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead); //获取块表对象 5 6 AcDbBlockTableRecord* pBlockTableRecord; //申明块表记录对象 7 pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); //以写的方式获取模型空间块表记录对象 8 9 AcDbObjectId oId; //什么对象ObjectId 10 pBlockTableRecord->appendAcDbEntity(oId,pEnt); //添加实体到模型空间 11 12 pBlockTable->close(); 13 pBlockTableRecord->close(); 14 pEnt->close(); 15 16 return oId; 17 }
步骤:
(1) 获取当前数据库的块表对象
(2) 获取当前数据库的模型空间块表记录对象
(3) 添加实体到模型空间
(4) 关闭块表指针,块表记录指针,实体指针
对上一节的创建直线函数的封装
1 AcDbObjectId CCreateEnt::CreateLine(AcGePoint3d ptStart, AcGePoint3d ptEnd) 2 { 3 AcDbLine* pLine = new AcDbLine(ptStart,ptEnd); 4 AcDbObjectId oId = CCreateEnt::PostToModelSpace(pLine); 5 return oId; 6 }