在图层中添加直线
//将直线添加到指定的图层AcDbObjectId CLayerUtil::CreateLine(AcGePoint3d& ptStart,AcGePoint3d& ptEnd,
AcDbObjectId layer)
{
AcDbLine* pLine = new AcDbLine(ptStart,ptEnd);
//获取当前图形数据库的符号表
AcDbBlockTable* pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable,AcDb::kForRead);
//获取符号表中的模型空间块表记录指针,用于添加对象
AcDbBlockTableRecord* pBlockTblRcd;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTblRcd,AcDb::kForWrite);
pBlockTable->close();
//将直线添加到模型空间块表记录中
AcDbObjectId lineId;
pLine->setLayer(layer,Adesk::kTrue); //设置直线所在的图层
pBlockTblRcd->appendAcDbEntity(lineId,pLine);
//关闭块表记录和直线记录
pBlockTblRcd->close();
pLine->close();
//返回直线的ID号
return lineId;
}
//注册一个Newlayer命令,用测试“直线是否添加到图层中”
// This is command 'NEWLAYER'
void WhCHAP6NEWLAYER()
{
// TODO: Implement the command
TCHAR layerName="钢筋";
//新建图层
AcDbObjectId layerId = CLayerUtil::GetLayerId(layerName);
if (layerId.isValid())
{
acutPrintf(TEXT("\n图形中已经存在同名的图层!"));
}
else
{
CLayerUtil::Add(layerName);
CLayerUtil::SetColor(layerName,1);
CLayerUtil::SetWeight(layerName,35);
acutPrintf(TEXT("\n图层创建成功!"));
}
AcGePoint3d pa(10,10,0),pb(100,100,0);
AcDbObjectId layerId2 = CLayerUtil::GetLayerId("钢筋");
CLayerUtil::CreateLine(pa,pb,layerId2);
}
值得一看,学校ObjectARX的图层操作 新手路过,感谢分享!
页:
[1]