- 积分
- 735
- 明经币
- 个
- 注册时间
- 2003-6-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2003-8-11 11:26:00
|
显示全部楼层
源程序的代码如下:
#include <rxregsvc.h>
#include <aced.h>
#include <dbidmap.h>
#include <dbltrans.h>
#include <dbmain.h>
#include <dbsymtb.h>
#include <dbents.h>
#include <dbapserv.h>
#include <adslib.h>
#include <math.h>
//提取属性
void
LineEdit()
{
AcDbObjectId transId;
AcDbDatabase* pDb;
char *fname;
struct resbuf *rb;
//提示让用户选择一个图形文件
rb = acutNewRb(RTSTR);
int stat = acedGetFileD("ick a drawing", NULL, "dwg", 0, rb);
//如果选择有误,则提示拥用户推出,命令
if ((stat != RTNORM) || (rb == NULL))
{
acutPrintf("\nYou must pick a drawing file.");
return;
}
//将获得的文件名转化为字符串
fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
strcpy(fname, rb->resval.rstring);
acutRelRb(rb);
// 打开前面选中的图形文件
pDb = new AcDbDatabase(Adesk::kFalse);
if (pDb->readDwgFile(fname) != Acad::eOk)
{
acutPrintf("\nSorry, that draing is probably already open.");
return;
}
acutPrintf("\nThe name of the draing is : %s",fname);
//获得这个图形文件数据库的块表
AcDbBlockTable *pBlockTable;
pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
//获得模型空间块表记录
AcDbBlockTableRecord *pOtherMsBtr;
pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead);
pBlockTable->close();
// delete pDb;
// pDb = NULL;
// acad_free(fname);
ads_name en;
ads_point pt;
AcDbEntity *pEnt;
AcDbObjectId pEntId;
//提示选择判断中心线
acedEntSel("\nPlease Select a center line which used to be tested.",en,pt);
//获得选中对象的ID
acdbGetObjectId(pEntId,en);
//打开对象
acdbOpenObject(pEnt,pEntId,AcDb::kForWrite);
//获取实体的长度
AcGePoint3d sPnt,ePnt;
double LineLength;
if (pEnt->isKindOf(AcDbLine::desc()))
{
sPnt=((AcDbLine *)pEnt)->startPoint();
ePnt=((AcDbLine *)pEnt)->endPoint();
LineLength=sqrt(((sPnt.x)-(ePnt.x))*((sPnt.x)-(ePnt.x))+((sPnt.y)-(ePnt.y))*((sPnt.y)-(ePnt.y)));
acutPrintf("\nThe length of the line is: %f",LineLength);
}
pOtherMsBtr->close();
pEnt->close();
}
void
initApp()
{
acedRegCmds->addCommand("test",
"CHECK",
"CHECK",
ACRX_CMD_MODAL,
LineEdit);
}
void unloadApp()
{
acedRegCmds->removeGroup("test");
}
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
break;
}
return AcRx::kRetOK;
} |
|