【求助】如何修改图层名称
已知“图层1”存在,如何修改名称为“图层2”,我简单写了个命令,执行就死机,不知道什么情况?请各位不吝赐教。// - OperateLayer._ChangeLayer command (do not rename)
static void OperateLayer_ChangeLayer(void)
{
// Add your code for command OperateLayer._ChangeLayer here
AcDbLayerTable *pLayerTbl;
AcDbObjectId layerId;
AcDbLayerTableRecord *pLayerRecord;
ACHAR *layerName=new ACHAR;
if (acdbCurDwg()->getLayerTable(pLayerTbl,AcDb::kForRead)!=Acad::eOk)
{
pLayerTbl->close();
ads_printf(_T("\n错误:打开层表出错! \n"));
return;
}
//获取层表记录
layerName=_T("图层1");
if (pLayerTbl->getAt(layerName,pLayerRecord,AcDb::kForWrite) != Acad::eOk)
{
pLayerTbl->close();
ads_printf(_T("\n错误:获取层表记录出错! \n"));
return;
}
//修改层名
layerName=_T("图层2");
pLayerRecord->setName(layerName);
//获取层表记录ID
if (pLayerTbl->getAt(layerName,layerId,false) != Acad::eOk)
{
pLayerTbl->close();
ads_printf(_T("\n错误:获取层表记录出错! \n"));
return;
}
//设置当前层
acdbCurDwg()->setClayer(layerId);
delete layerName;
pLayerTbl->close();
pLayerRecord->close();
return;
}
//获取层表记录
layerName=_T("图层1");
这个是不对的
字符串的初始化,
_tcscpy( layerName, _T("...")); 谢谢,问题已经解决
页:
[1]