zoukankan      html  css  js  c++  java
  • 2021年1月1日 AutoCAD.Net/C#.Net QQ群:193522571 按顺序等距排列平行直线

    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[i].distanceTo(pts[j]);
    if (dist1>dist)
    {
    dist=dist1;
    pt1=pts[i];
    pt2=pts[j];
    }
    }
    }
    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[i].distanceTo(pt1);
    if (dist1<dist)
    {
    dist=dist1;
    m=i;
    }
    }
    AcGeVector3d vec=pt1-pts[m]-(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[i]);
    AcGePoint3d ptclose;
    pLine->getClosestPointTo(pts[m],ptclose,Adesk::kTrue);

    if (pts[m].distanceTo(ptclose)<0.001)
    {
    pLine->transformBy(max);
    }
    }
    pts.remove(pts[m]);
    n++;
    }
    for (int i=0;i<ents.length();i++)
    {
    AcDbLine* pLine1=static_cast<AcDbLine*>(ents[i]);
    pLine1->close();
    }
    }

  • 相关阅读:
    JetBrains Rider 在 Mac 环境下将 cs 文件生成 exe
    Unity3d 控制物体移动、旋转、缩放
    Unity3d 脚本使用规则
    Unity3D 脚本模板修改方法
    Intelli IDEA 设置项目编码(Mac)
    搭建LayaBox的生产环境,并helloWorld
    unity Lighting
    流畅度测试
    Failure [INSTALL_FAILED_USER_RESTRICTED: Install canceled by user]
    Unity GUI(uGUI)使用心得与性能总结
  • 原文地址:https://www.cnblogs.com/NewAutoMan/p/6464081.html
Copyright © 2011-2022 走看看