天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 73|回复: 0

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

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
//拷贝,移动,旋转 ,镜像,缩放


选择一个对象
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[X] - ptFrom[X],ptTo[Y] - ptFrom[Y],
ptTo[Z] - ptFrom[Z]);


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();


}

}

 

 

 

 

OBJECT ARX 移动,拷贝 旋转,镜像,缩放
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 12:26 , Processed in 0.133193 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表