- UID
- 739618
- 积分
- 526
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2014-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
目的:选择实体,自动求出选择集的包围盒,用户选择一个范围框,以包围盒与范围框的X、Y两个方向的缩放值的最小值(选择的对象缩放后在范围框中最大且不超出范围框),并使选择集图元的中心位于范围框的中心。现在的问题是对选择集进行复制的过程很慢,100多个图元时感到慢了,而且缩放与移动不执行。缩放和移动函数来自张帆的书。
static void YTMsupportWZZZ(void) {
////遍历所有实体
Acad::ErrorStatus es;
ads_name sset;////选择集名称
AcDbObjectIdArray entIds;
entIds.setLogicalLength(0);
//建议缓冲区链表
struct resbuf *rb;//结果缓冲表
//rb=acutBuildList(RTDXF0,TEXT("DIMENSION"),RTNONE);
rb=acutBuildList(-4,TEXT("<OR"),RTDXF0,TEXT("DIMENSION"),RTDXF0,TEXT("TOLERANCE"),RTDXF0,TEXT("INSERT"),-4,TEXT("OR>"),RTNONE);
//if(acedSSGet(_T("X"),NULL,NULL,rb,sset)==RTNORM)
if(acedSSGet(NULL,NULL,NULL,NULL,sset)==RTNORM)
{
long length=0;
acedSSLength(sset,&length);
acutPrintf(TEXT("\n实体数:%d"),length);
for(int i=0;i<length;i++)
{
ads_name ename;
acedSSName(sset,i,ename);
AcDbObjectId entId;
//获取图元ID
es=acdbGetObjectId(entId,ename);
if(es == Acad::eOk)
{
entIds.append(entId);
}
}
AcDbExtents extents;
extents=CCreatEnt::GetGeomExtents(entIds);
AcGePoint3d ssMidpt;
AcGePoint3d pt1=extents.minPoint();
AcGePoint3d pt2=extents.maxPoint();
ssMidpt=AcGePoint3d((pt2.x + pt1.x) / 2.0, (pt2.y + pt1.y) / 2.0, 0.0);
double lx=pt2.x - pt1.x;
double ly=pt2.y - pt1.y;
ads_point gopt1;
ads_point gopt2;
AcGePoint3d goMidpt;
if(acedGetPoint(NULL, _T("\n请选择左上角点:"), gopt1)==RTNORM)
{
if(acedGetCorner(gopt1, _T("\n请选择右下角点:"), gopt2)==RTNORM)
{
goMidpt.x=(gopt1[X]+gopt2[X])*0.5;
goMidpt.y=(gopt1[Y]+gopt2[Y])*0.5;
goMidpt.z=(gopt1[Z]+gopt2[Z])*0.5;
double xsc=abs((gopt1[X]-gopt2[X])/lx);
double ysc=abs((gopt1[Y]-gopt2[Y])/ly);
double sc=min(xsc,ysc);
for(int i=0;i<entIds.length();i++)
{
//打开实体
AcDbEntity *pEnt=NULL;
AcDbDimension *pDim=NULL;
AcDbFcf *pFcf=NULL;
//AcDbDimension *pFcf=NULL;
es=acdbOpenObject(pEnt,entIds[i],AcDb::kForRead);
if(es == Acad::eOk)
{
AcRxObject *pObject = pEnt->clone();
if (pObject != NULL)
{
AcDbEntity *pOtherEnt = AcDbEntity::cast(pObject);
if (pOtherEnt != NULL)
{
CCreatEnt::PostToModelSpace(pOtherEnt);
CCreatEnt::SetColor(entIds[i],1);
CCreatEnt::Scale(entIds[i],ssMidpt,10.0);
CCreatEnt::Move(entIds[i],ssMidpt,goMidpt);
}
}
}
//注意需要关闭实体
if (pEnt!=NULL)
{
pEnt->close();
}
}
acutPrintf(_T("\n中点X:%f"),goMidpt.x);
acutPrintf(_T("\n中点Y:%f"),goMidpt.y);
acutPrintf(_T("\n中点Z:%f"),goMidpt.z);
acutPrintf(_T("\n缩放X:%f"),xsc);
acutPrintf(_T("\n缩放Y:%f"),ysc);
acutPrintf(_T("\n最小缩放:%f"),sc);
acutPrintf(_T("\n中点X:%f"),ssMidpt[X]);
acutPrintf(_T("\n中点X:%f"),ssMidpt[Y]);
acutPrintf(_T("\n中点X:%f"),ssMidpt[Z]);
}
else
{
for(int i=0;i<entIds.length();i++)
{
CCreatEnt::Erase(entIds[i]);
}
}
}
else
{
for(int i=0;i<entIds.length();i++)
{
CCreatEnt::Erase(entIds[i]);
}
}
}
//关闭链表
acutRelRb(rb);
//关闭选择集
acedSSFree(sset);
}
Acad::ErrorStatus CCreatEnt::Move( AcDbObjectId entId, const AcGePoint3d &ptBase, const AcGePoint3d &ptDest )
{
// 设置变换矩阵的参数
AcGeMatrix3d xform;
AcGeVector3d vec(ptDest.x - ptBase.x, ptDest.y - ptBase.y,
ptDest.z - ptBase.z);
xform.setToTranslation(vec);
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId, AcDb::kForWrite, false);
if (es == Acad::eOk)
{
es = pEnt->transformBy(xform);
pEnt->close();
}
return es;
}
Acad::ErrorStatus CCreatEnt::Scale( AcDbObjectId entId, const AcGePoint3d &ptBase, double scaleFactor )
{
// 设置变换矩阵的参数
AcGeMatrix3d xform;
xform.setToScaling(scaleFactor, ptBase);
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId, AcDb::kForWrite, false);
if (es == Acad::eOk)
{
es = pEnt->transformBy(xform);
pEnt->close();
}
return es;
}
void CCreatEnt::Erase( AcDbObjectId entId )
{
AcDbEntity *pEnt = NULL;
if (acdbOpenObject(pEnt, entId, AcDb::kForWrite) == Acad::eOk)
{
pEnt->erase();
pEnt->close();
}
}
请问程序运行后为什么选择集的对象不会缩放并移动到新的位置呢?
|
|