admin 发表于 2024-5-2 22:49:29

OBJECT ARX 移动,拷贝 旋转,镜像,缩放

//拷贝,移动,旋转 ,镜像,缩放


选择一个对象
static BOOL SelObj(ads采用point& pt,AcDbObjectId& objId){
ads采用name en;
if(acedEntSel(采用T("\n选择对象"),en,pt) != RTNORM){
return false;
}
Acad::ErrorStatus es = acdbGetObjectId(objId,en);
return es == Acad::ErrorStatus::eOk ? true : false;
}


//选择一个点
static BOOL SelPoint(ads采用point& ptEnd){
if(acedGetPoint(NULL,采用T("\n选择一个点"),ptEnd) != RTNORM){
return false;
}
return true;
}



拷贝函数测试


static void TESTcopycmd(){
AcDbObjectId objId;
ads采用point ptStart;
ads采用point ptEnd;


if(!SelObj(ptStart,objId)){
acutPrintf(采用T("选择对象失败"));
};


if(!SelPoint(ptEnd)){
acutPrintf(采用T("选择点失败"));
}


CopyTo(objId,ptStart,ptEnd);


}


拷贝函数


static BOOL CopyTo(AcDbObjectId entId,const ads采用point& ptFrom,
const ads采用point& ptTo){


AcDbEntity* pEnt = NULL;
if(acdbOpenObject(pEnt,entId,AcDb::kForRead) != Acad::eOk){
return FALSE;
}


AcDbEntity* pCopyEnt = AcDbEntity::cast(pEnt->clone());
AcDbObjectId copyEntId;
if(pCopyEnt){
copyEntId = LoadEntity(pCopyEnt);
}


Move(copyEntId,ptFrom,ptTo);




}


移动函数测试============
static void TESTmovecmd(){
AcDbObjectId objId;
ads采用point ptStart;
ads采用point ptEnd;


if(!SelObj(ptStart,objId)){
acutPrintf(采用T("选择对象失败"));
};


if(!SelPoint(ptEnd)){
acutPrintf(采用T("选择点失败"));
}


Move(objId,ptStart,ptEnd);


}

移动函数
static Acad::ErrorStatus Move(AcDbObjectId entId,const ads采用point& ptFrom,const ads采用point& ptTo){

AcGeVector3d vec(ptTo - ptFrom,ptTo - ptFrom,
ptTo - ptFrom);


AcGeMatrix3d mat;
mat.setToTranslation(vec);
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt,entId,AcDb::kForWrite);
if(es!=Acad::eOk){
return es;
}


es=pEnt->transformBy(mat);
pEnt->close();


}


缩放
static void TESTsccmd()
{
ads采用name name;
ads采用point ptEnt;
AcDbObjectId id;
if(acedEntSel(采用T("选择要扩大的实体"),name,ptEnt) != RTNORM)
{
acutPrintf(采用T("\nno obj select"));
return;
}
if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
{
return;
}
AcDbEntity* pEnt;


if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
{
acutPrintf(采用T("\n打开实体失败"));
return;
}


ads采用real num;
if(acedGetReal(采用T("\n输入扩展倍数"),&num) != RTNORM)
{
pEnt->close();
return;
}


ads采用point pt;
if(acedGetPoint(NULL,采用T("\n选择基点"),pt) != RTNORM)
{
pEnt->close();
return;
}


AcGePoint3d pt3d = asPnt3d(pt);
AcGeMatrix3d mat;
mat.setToScaling(num,pt3d);


pEnt->transformBy(mat);
pEnt->close();




}


旋转
static void TESTrtcmd()
{
ads采用name name;
ads采用point ptEnt;
AcDbObjectId id;
if(acedEntSel(采用T("选择要旋转的实体"),name,ptEnt) != RTNORM)
{
acutPrintf(采用T("\nno obj select"));
return;
}
if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
{
return;
}
AcDbEntity* pEnt;


if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
{
acutPrintf(采用T("\n打开实体失败"));
return;
}


ads采用point ptBase;
if(acedGetPoint(NULL,采用T("\n选择旋转的基点"),ptBase) != RTNORM)
{
pEnt->close();如果不及时关闭,会导致内存泄漏
return;
}


ads采用real angle;
if(acedGetAngle(ptBase,采用T("\n输入旋转角度"),&angle) != RTNORM)
{
pEnt->close();
return;
}
AcDbCurve* pCurve;
pCurve = (AcDbCurve*)pEnt;

AcGePoint3d ptCenter;
pCurve->getStartPoint(ptCenter);


AcGeMatrix3d mat;
acutPrintf(采用T("angle is %.2f"),angle);
mat.setToRotation(angle,AcGeVector3d::kZAxis,ptCenter);
//mat.rotation(angle,AcGeVector2d::kXAxis,ptCenter);


pEnt->transformBy(mat);
pEnt->close();
}


镜像
static void TESTmrcmd()
{
ads采用name name;
ads采用point ptEnt;
AcDbObjectId id;
if(acedEntSel(采用T("选择要镜像的实体"),name,ptEnt) != RTNORM)
{
acutPrintf(采用T("\nno obj select"));
return;
}
if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
{
return;
}
AcDbEntity* pEnt;


if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
{
acutPrintf(采用T("\n打开实体失败"));
return;
}


ads采用point ptDis1;
if(acedGetPoint(NULL,采用T("\n选择镜像点1"),ptDis1) !=RTNORM)
{
acutPrintf(采用T("\nno point select"));
pEnt->close();
return;
}
ads采用point ptDis2;
if(acedGetPoint(NULL,采用T("\n选择镜像点2"),ptDis2) !=RTNORM)
{
acutPrintf(采用T("\nno point select"));
pEnt->close();
return;
}


AcGePoint3d ptDis3d1 = asPnt3d(ptDis1);
AcGePoint3d ptDis3d2 = asPnt3d(ptDis2);
AcGeLine3d line(ptDis3d1,ptDis3d2);


AcGeMatrix3d mat ;
mat.setToMirroring(line);

acedInitGet(NULL,采用T("Y N"));
CString strKW;


if(acedGetKword(采用T("删除原对象?Y/N"),strKW.GetBuffer(1)) != RTNORM)
{
return;
}
strKW.ReleaseBuffer();
if(strKW.CompareNoCase(采用T("N")) == 0)
{
AcDbEntity* pEnt2 = AcDbEntity::cast(pEnt->clone());
LoadEntity(pEnt2);
pEnt2->close();
}


pEnt->transformBy(mat);
pEnt->close();


}

}
页: [1]
查看完整版本: OBJECT ARX 移动,拷贝 旋转,镜像,缩放