- UID
- 34921
- 积分
- 99
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-3-11
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
我在layer.cpp中建立的两个函数,一个是设置当前层,一个是关闭一个层;如下:
Adesk::Boolean setCurLayer(char *lpszLyrName)//设置当前层
{
assert(lpszLyrName != NULL);//防错
AcDbLayerTable *pLyrTable;
AcDbLayerTableRecord *pLyrTblRecord;//
AcDbObjectId lyrId;
Acad::ErrorStatus es;
AcDbDatabase *pCurDb = NULL;
pCurDb = acdbHostApplicationServices()->workingDatabase();
es = pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
if(pLyrTable->has(lpszLyrName))
{
es = pLyrTable->getAt(lpszLyrName, pLyrTblRecord, AcDb::kForWrite, Adesk::kFalse);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table record");
return Adesk::kFalse;
}
}
else
{
acutPrintf("\n 没有这样的图层");
return Adesk::kFalse;
}
lyrId = pLyrTblRecord->objectId();//取得图层的Id
pLyrTblRecord->close();
pLyrTable->close();
es = pCurDb->setClayer(lyrId);
if(es != Acad::eOk)
{
acutPrintf("\n 没有设为当前图层");
return Adesk::kFalse;
}
return Adesk::kTrue;
}
Adesk::Boolean closeLyrName(char *lpszLyrName)//关闭lpszLyrName
{
assert(lpszLyrName != NULL);//防错
//将lpszlyrName设为当前层,并且将其他的层关闭
AcDbLayerTable *pLyrTable;//不用释放,要关闭
AcDbLayerTableRecord *pLyrTblRecord;//不用释放,要关闭
AcDbObjectId lyrId;
Acad::ErrorStatus es;
AcDbDatabase *pCurDb = NULL;
//关闭其他的层
es = pCurDb->getSymbolTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
AcDbLayerTableIterator *pLyrIterator
es = pLyrTable->newIterator(pLyrIterator);
if(es != Acad::eOk)
{
acutPrintf("\n 没有创建一个新");
return Adesk::kFalse;
}
char *lpszTempLyrName;
for(; !pLyrIterator->done(); pLyrIterator->step())//关闭图层
{
es = pLyrIterator->getRecord(pLyrTblRecord, AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf("\n 没有打开图层表记录");
continue;
}
es = pLyrTblRecord->getName(lpszTempLyrName);
if(es != Acad::eOk)
{
acutPrintf("\n 没有取得层的名字");
continue;
}
int rc;
rc = stricmp(lpszLyrName,lpszTempLyrName);
if(rc = 0)
{
pLyrTblRecord->setIsFrozen(TRUE);
}
pLyrTblRecord->close();
}
delete pLyrIterator;
pLyrIterator = NULL;
pLyrTable->close();
return Adesk::kTrue;
}
我在layerCommands.cpp中调用这两个函数,先使一个图层成为当前层,在关闭另一个图层,如下:
char *lpszLyrName = "wall";
char *lpszWindow = "window";
setCurLayer(lpszLyrName);
closeLyrName(lpszWindow);
但是编译没有问题,但是在autocad中执行时出错,只能执行setCurLayer,而不能执行closeLyrname,why????
先谢了 |
|