- UID
- 215174
- 积分
- 286
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-1-29
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2005-5-30 15:47:13
|
显示全部楼层
//多谢各位大哥的帮助,让我增长了不少知识,我从网上找了这样一个例子,大家看看还有什么不妥之处,希望能起到抛砖引玉的效果。
#include "StdAfx.h"
#include "StdArx.h"
#include "dbents.h"
#include "actrans.h"
void indrag();
// This is command 'JINGTEST'
void ZzpCommand()
{
indrag();
}
//-----------------------------------------------------------------------------
void ident_init(ads_matrix id)
{
int i, j;
for (i=0; i<=3; i++)
for (j=0; j<=3; j++)
id[j] = 0.0;
for (i=0; i<=3; i++)
id = 1.0;
}
int sample_fcn(ads_point usrpt,ads_matrix matrix)
{
ident_init(matrix);
matrix[0][T] = usrpt[X];
matrix[1][T] = usrpt[Y];
matrix[2][T] = usrpt[Z];
return RTNORM;
}
int Draggen(ads_name ssname,CString strPrompt,ads_point pt,ads_point ptRet,int nCursor)
{
LONG sslength;
if(ads_sslength(ssname,&sslength)!=RTNORM)
{
AfxMessageBox("ads_sslength is faile!");
return -1;
}
return ads_draggen(ssname,strPrompt,nCursor,sample_fcn,ptRet);
}
void indrag()
{
AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse) ;
Acad::ErrorStatus es;
es=pDwg->readDwgFile ("C:\\c.dwg") ;
if(es==Acad::eOk)
{
AfxMessageBox("readDwgFile Successful!");
//return;
}
AcDbObjectId blockId ;
es = acdbHostApplicationServices()->workingDatabase()->insert(blockId, LPCTSTR(""), pDwg);
if ( es != Acad::eOk )
AfxMessageBox ("插入块错误.") ;
delete pDwg ;
AcDbObjectId idBlock;
AcDbBlockReference* pBlock=new AcDbBlockReference;
AcGePoint3d ptCenter=AcGePoint3d(0,0,0);
pBlock->setPosition(ptCenter);
pBlock->setBlockTableRecord(blockId);
AcDbDatabase* pDb=NULL;
AcDbObjectId idNew=AcDbObjectId::kNull;
if(pDb==NULL)
pDb=acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *pTable=NULL;
Acad::ErrorStatus Error=pDb->getBlockTable(pTable, AcDb::kForRead);
if(pTable==NULL)
{
AfxMessageBox("块表打开错误!");
return;
}
AcDbBlockTableRecord *pRecord=NULL;
Error=pTable->getAt(ACDB_MODEL_SPACE,pRecord,AcDb::kForWrite);
pTable->close();
if(pRecord==NULL)
{
AfxMessageBox("块纪录打开错误!");
return;
}
Error=pRecord->appendAcDbEntity(idBlock,pBlock);
pRecord->close();
pBlock->close();
actrTransactionManager->flushGraphics();
ads_name dragname;
ads_ssadd(NULL,NULL,dragname);
ads_name locname;
es=acdbGetAdsName(locname,idBlock);
ads_redraw(locname,2);
ads_ssadd(locname,dragname,dragname);
ads_ssfree(locname);
if(es!=Acad::eOk)
AfxMessageBox("acedGetAdsName fail!");
ads_point pt,ptRet;
pt[X]=ptCenter.x;
pt[Y]=ptCenter.y;
pt[Z]=ptCenter.z;
int nReturn=Draggen(dragname,"请选择插入点:",pt,ptRet,0);
if(nReturn!=RTNORM)
{
ads_ssfree(dragname);
}
AcGeMatrix3d xform;
xform.setToTranslation(AcGeVector3d(ptRet[X]-pt[X],ptRet[Y]-pt[Y],ptRet[Z]-pt[Z]));
ads_xformss(dragname,xform.entry);
ads_ssfree(dragname);
} |
|