admin 发表于 2024-5-4 18:42:08

按顺序等距排列平行直线

static void zffObjectARX采用MyCommand17(void)
{
ads采用name ss;
AcDbVoidPtrArray ents;
if (acedSSGet(NULL,NULL,NULL,NULL,ss)!=RTNORM)
{
acedAlert(采用T("选择实体失败!"));
return;
}
AcGePoint3dArray pts;
long num;
acedSSLength(ss,&num);
if (num<3)
{
acedAlert(采用T("无需均分!"));
return;
}
for (int i=0;i<num;i++)
{
AcDbObjectId entId;
AcDbEntity* pEnt=NULL;
ads采用name name;
AcGePoint3d pt;

acedSSName(ss,i,name);
acdbGetObjectId(entId,name);
if (acdbOpenObject(pEnt,entId,AcDb::kForWrite)!=Acad::eOk)
{
acedAlert(采用T("部分实体打开失败,无法均分!"));
pEnt->close();
return;
}
if (pEnt->isKindOf(AcDbLine::desc()))
{
AcDbLine* pLine=AcDbLine::cast(pEnt);
pLine->getClosestPointTo(AcGePoint3d::kOrigin,pt,Adesk::kTrue);
pts.append(pt);
ents.append(static采用cast<void*>(pLine));
}
else
{
pEnt->close();
}
}
acedSSFree(ss);
AcGePoint3d pt1,pt2;
double dist=0,dist1;
long len=pts.length();
for (int i=0;i<len;i++)
{
for (int j=i+1;j<len;j++)
{
dist1=pts.distanceTo(pts);
if (dist1>dist)
{
dist=dist1;
pt1=pts;
pt2=pts;
}
}
}
pts.remove(pt1);
pts.remove(pt2);
int m,n=0;
for (int j=0;j<pts.length();)
{
dist=pt1.distanceTo(pt2);
for (int i=0;i<pts.length();i++)
{
dist1=pts.distanceTo(pt1);
if (dist1<dist)
{
dist=dist1;
m=i;
}
}
AcGeVector3d vec=pt1-pts-(pt1-pt2)*(n+1)/(len-1);
AcGeMatrix3d max;
max.setToTranslation(vec);
for (int i=0;i<ents.length();i++)
{
AcDbLine* pLine=static采用cast<AcDbLine*>(ents);
AcGePoint3d ptclose;
pLine->getClosestPointTo(pts,ptclose,Adesk::kTrue);

if (pts.distanceTo(ptclose)<0.001)
{
pLine->transformBy(max);
}
}
pts.remove(pts);
n++;
}
for (int i=0;i<ents.length();i++)
{
AcDbLine* pLine1=static采用cast<AcDbLine*>(ents);
pLine1->close();
}
}
页: [1]
查看完整版本: 按顺序等距排列平行直线