- UID
- 306377
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-8-10
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2005-10-16 15:55:34
|
显示全部楼层
给出我的成果!大家给点意见!
达到功能:
选择在0层的所有pline线,选出闭合的并且扩展应用程序名字为"xlgis"扩展数据为“居住”的pline线求出其面积和,对于不闭合的并且扩展应用程序名字为"xlgis"扩展数据为“居住”的pline线高亮显示!
程序编译通过,功能还有一些需要完善的!希望能得到大家的意见!谢谢!
#include "StdAfx.h"
#include "StdArx.h"
#include <string.h>
#include "dbidar.h"
#include "acutmem.h"
#include <dbsymtb.h>
char*data, *data1,*data2,*num;
bool readxdata1(AcDbPolyline* ppline,CString appName,char* caption);
Acad::ErrorStatus
getselectpolyarea(const char* szLayerName);
double allarea;
Acad::ErrorStatus
getselectpolyarea(const char* szLayerName)
{
Acad::ErrorStatus es = Acad::eOk;
// 判断是否存在层名szLayerName
AcDbLayerTable *pLayerTable = NULL;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTable, AcDb::kForRead);
if (es != Acad::eOk) return es;
AcDbLayerTableRecord *pLayerTableRecord = NULL;
es = pLayerTable->getAt(szLayerName, pLayerTableRecord,
AcDb::kForRead);
if (es != Acad::eOk)
{
pLayerTable->close();
acutPrintf("层'%s'不存在!", szLayerName);
return es;
}
pLayerTableRecord->close();
// 得到模型空间的块表记录,并遍历它得到所需要的实体
AcDbBlockTable *pBlockTable = NULL;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk) {
acutPrintf("\n以读方式打开块表操作失败!");
return es;
}
AcDbBlockTableRecord *pBlockTableRecord = NULL;
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForRead);
if (es != Acad::eOk) {
pBlockTable->close();
acutPrintf("\n以读方式打开块表记录操作失败!");
return es;
}
pBlockTable->close();
AcDbBlockTableRecordIterator *pBlockIterator = NULL;
pBlockTableRecord->newIterator(pBlockIterator);
AcDbBlockTableRecordIterator *pBlkTblRcdItr; //生成块表记录的迭代器
pBlockTableRecord->newIterator(pBlkTblRcdItr);
AcDbEntity *pEnt; //遍历法获得并打印每一个实体的类名
int n=0,m=0;
allarea=0;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done(); pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(pEnt, AcDb::kForRead);
acutPrintf("\npEnt is: %s\n", (pEnt->isA())->name());
if (pEnt->isKindOf(AcDbPolyline::desc()))
{
acutPrintf("\n存在AcDbPolyline!");
AcDbPolyline *pPLine;
pPLine=AcDbPolyline::cast(pEnt);
double area1=0;
pPLine->getArea(area1);
acutPrintf("\n该不确定pline线的面积为: '%.3f'平方米", area1);
if (readxdata1(pPLine,"xlgis","居住")==0)
{
if(pPLine->isClosed()!=0)
{
m=m++;
acutPrintf("\n该pline线是闭合的!");
allarea=allarea+area1;
}
else
{
acutPrintf("\n该pline线不是闭合的!");
pEnt->highlight();
}
}
pPLine->close();
pEnt->close();
}
else{pEnt->close();
}
n=n++;
}
acutPrintf("\n总面积为: '%.3f'平方米", allarea);
acutPrintf("有'%d'个对象存在!",n);
acutPrintf("有'%d'个Xdata匹配成功闭合pline线存在!",m);
pBlockTableRecord->close();
//删除块表记录迭代器及数据库指针
delete pBlkTblRcdItr;
return Acad::eOk;
}
bool readxdata1(AcDbPolyline* ppline,CString appName,char* caption)
{ // 获取指定对象的扩展实体数据
char appName1[40];//应用程序名
strcpy(appName1,appName);
struct resbuf *pRb;
if(pRb = ppline->xData(appName1))
{
// acedAlert("appName匹配成功!");
if(pRb!=NULL)
{
pRb=pRb->rbnext;
int n=1;
for(;pRb!=NULL;pRb=pRb->rbnext)
{
if(pRb->restype==1000)
{
if (n==1) data1=pRb->resval.rstring;//得到data1
if (n==2) data2=pRb->resval.rstring;//得到data2
if (n==3) num=pRb->resval.rstring;//得到num
n++;
}
if(*data1==*caption)//判断扩展数据
{
acutPrintf("\nxdata匹配成功!!!!!!");
}
else{
acutRelRb(pRb);
return 1;
}
}
}
else{
acutPrintf("\n该闭合pline扩展数据为空!");
acutRelRb(pRb);
return 1;
}
}
else
{
acutPrintf("\nappName匹配不成功!");
acutRelRb(pRb);
return 1;
}
acutRelRb(pRb);
return 0;
} |
|