admin 发表于 2024-2-15 16:33:55

JoinToPline 连接线段成多段线

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"

//-----------------------------------------------------------------------------
#define szRDS 采用RXST("")

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CJoinToPlineApp : public AcRxArxApp {

public:
CJoinToPlineApp () : AcRxArxApp () {}

virtual AcRx::AppRetCode On采用kInitAppMsg (void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kInitAppMsg (pkt) ;
    return (retCode) ;
}

virtual AcRx::AppRetCode On采用kUnloadAppMsg (void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kUnloadAppMsg (pkt) ;
    return (retCode) ;
}

virtual void RegisterServerComponents () {
}

static void JoinToPlineJoinToPline () {
    // Фильтр для выбора отрезков (LINE) и дуг (ARC)
    ACHAR* promptPtrs[] = {
      采用T("\nSelect lines and arcs for join in poyline (ENTER - exit): "),
      采用T("\nRemove lines and arcs from selection set: ")
    };

    ads采用name ss;
    resbuf *rbFilter = acutBuildList(RTDXF0,采用T("LINE,ARC"),RTNONE);
    int rc = acedSSGet(采用T(":$"),promptPtrs,NULL,rbFilter,ss);
    acutRelRb(rbFilter);

    if (rc != RTNORM) return;

    AcDbObjectIdArray ids;
    if (ObjectIdArrayFromSelSet(ss, ids) != Acad::eOk) return;
    while (ids.length() > 0)
    {
      AcDbEntity *p = MakeJonedPoly(ids);
      if (p) {
      AcDbBlockTableRecordPointer pSpace(acdbCurDwg()->currentSpaceId(), AcDb::kForWrite);
      if (pSpace.openStatus() != Acad::eOk) return;
      pSpace->appendAcDbEntity(p);
      p->close();
      } else {
      acutPrintf(采用T("\nError in data!"));
      return;
      }
    }

}

/// <summary>
/// AcDbObjectIdArray from SelectionSet
/// </summary>
/// <param name="sset">SelectionSet</param>
/// <param name="ids">AcDbObjectIdArray</param>
/// <returns></returns>
static Acad::ErrorStatus ObjectIdArrayFromSelSet(ads采用name sset, AcDbObjectIdArray &ids)
{
    Acad::ErrorStatus es = Acad::eOk;
    long nset = -1;
    if (acedSSLength(sset,&nset) != RTNORM) return Acad::eAmbiguousInput;
    ids.setLogicalLength(nset);
    ads采用name en;
    AcDbObjectId id;
    for (long i=0; i < nset; i++) {
      if (acedSSName(sset,i,en) == RTNORM) {
      if ((es = acdbGetObjectId(id,en)) != Acad::eOk) return es;
      ids = id;
      }
    }
    return Acad::eOk;
}

/// <summary>
/// Create polyline from lines and arcs.
/// Those ids will remove from input array
/// </summary>
/// <param name="ids">Array of id's</param>
/// <param name="FUZZ">The accuracy of determining the distance between points</param>
/// <returns></returns>
static AcDbPolyline* MakeJonedPoly(
    AcDbObjectIdArray &ids,
    double FUZZ = AcGeContext::gTol.equalPoint())
{
    AcDbPolyline *p = new AcDbPolyline();
    p->setDatabaseDefaults();
    AcDbObjectId idFirst = ids;
    AcGePoint3d nextPt = AcGePoint3d::kOrigin;
    AcGePoint3d prevPt = AcGePoint3d::kOrigin;

    AcDbObjectPointer<AcDbCurve> c(idFirst,AcDb::kForRead);
    if (c.openStatus() == Acad::eOk) {
      AcGePoint3d ptStart, ptEnd;
      c->getStartPoint(ptStart); c->getEndPoint(ptEnd);
      p->addVertexAt(0, asPnt2d(asDblArray(ptStart)), BulgeFromArc(c, false), 0, 0);
      p->addVertexAt(1, asPnt2d(asDblArray(ptEnd)), 0, 0, 0);
      nextPt = ptEnd;
      prevPt = ptStart;
    }

    ids.remove(idFirst);
    int prevCnt = ids.length() + 1;

    while (ids.length() > 0 && ids.length() < prevCnt)
    {
      prevCnt = ids.length();
      for (int i = 0; i < ids.length(); i++) {
      AcDbObjectId id = ids;
      AcDbObjectPointer<AcDbCurve> cv(id,AcDb::kForRead);
      if (cv.openStatus() == Acad::eOk) {
          AcGePoint3d ptStart, ptEnd;
          cv->getStartPoint(ptStart); cv->getEndPoint(ptEnd);
          if (ptStart.distanceTo(nextPt) < FUZZ || ptEnd.distanceTo(nextPt) < FUZZ) {
            double bulge = BulgeFromArc(cv, ptEnd.distanceTo(nextPt) < FUZZ);
            p->setBulgeAt(p->numVerts() - 1, bulge);
            if (ptStart.distanceTo(nextPt) < FUZZ)
            nextPt = ptEnd;
            else
            nextPt = ptStart;
            p->addVertexAt(p->numVerts(), asPnt2d(asDblArray(nextPt)), 0, 0, 0);
            ids.remove(id);
            break;
          } else if (ptStart.distanceTo(prevPt) < FUZZ || ptEnd.distanceTo(prevPt) < FUZZ) {
            double bulge = BulgeFromArc(cv, ptStart.distanceTo(prevPt) < FUZZ);
            if (ptStart.distanceTo(prevPt) < FUZZ)
            prevPt = ptEnd;
            else
            prevPt = ptStart;
            p->addVertexAt(0, asPnt2d(asDblArray(prevPt)), bulge, 0, 0);
            ids.remove(id);
            break;
          }
      }
      }
    }
    if (p->numVerts() == 0) {
      delete p;return NULL;
    }else{
      return p;
    }
}

/// <summary>
/// Getting bulge of curve
/// </summary>
/// <param name="c">AcDbCurve pointer</param>
/// <param name="clockwise">direction.</param>
/// <returns></returns>
static double BulgeFromArc(AcDbCurve *c, bool clockwise)
{
    double bulge = 0.0;
    AcDbArc *a = AcDbArc::cast(c);
    if (a == NULL) return bulge;

    double newStart =
      (a->startAngle() > a->endAngle()) ?
      (a->startAngle() - 8 * atan(1.0)) :
      (a->startAngle());

    bulge = tan((a->endAngle() - newStart) / 4.0);
    if (clockwise) bulge = -bulge;
    return bulge;
}
} ;

//-----------------------------------------------------------------------------
IMPLEMENT采用ARX采用ENTRYPOINT(CJoinToPlineApp)
ACED采用ARXCOMMAND采用ENTRY采用AUTO(CJoinToPlineApp, JoinToPline, JoinToPline, JoinToPline, ACRX采用CMD采用MODAL, NULL)

admin 发表于 2024-2-15 16:35:15

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "acedCmdNF.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS 采用RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CMyJoinApp : public AcRxArxApp {

public:
CMyJoinApp() : AcRxArxApp() {}
virtual AcRx::AppRetCode On采用kInitAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kInitAppMsg(pkt);
    return (retCode);
}
virtual AcRx::AppRetCode On采用kUnloadAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kUnloadAppMsg(pkt);
    return (retCode);
}
virtual void RegisterServerComponents() {}

static void RivilisMyJoin() {
    ads采用name en1;ads采用point p;
    while (acedEntSel(采用T("\nSelect first segment: "), en1, p) == RTNORM)
    {
      bool bConvertToPoly = false;
      AcDbObjectId id1; acdbGetObjectId(id1, en1);
      if (id1.objectClass() == AcDbLine::desc() ||
          id1.objectClass() == AcDbArc::desc())
      {
      bConvertToPoly = true;
      }
      ads采用name en2;
      if (acedEntSel(采用T("\nSelect next segment: "), en2, p) == RTNORM)
      {
      if (bConvertToPoly)
          acedCommandS(RTSTR, 采用T("采用PEDIT"), RTENAME, en1, RTSTR, 采用T("采用YES"), RTSTR, 采用T("采用Join"),
            RTENAME, en2, RTSTR, 采用T(""), RTSTR, 采用T(""), RTNONE);
      else
          acedCommandS(RTSTR, 采用T("采用PEDIT"), RTENAME, en1, RTSTR, 采用T("采用Join"),
            RTENAME, en2, RTSTR, 采用T(""), RTSTR, 采用T(""), RTNONE);
      }
    }
}
};

//-----------------------------------------------------------------------------
IMPLEMENT采用ARX采用ENTRYPOINT(CMyJoinApp)

ACED采用ARXCOMMAND采用ENTRY采用AUTO(CMyJoinApp, Rivilis, MyJoin, MyJoin, ACRX采用CMD采用MODAL, NULL)

admin 发表于 2024-2-15 16:35:39

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "acedCmdNF.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS 采用RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CMyJoinApp : public AcRxArxApp {

public:
CMyJoinApp() : AcRxArxApp() {}
virtual AcRx::AppRetCode On采用kInitAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kInitAppMsg(pkt);
    return (retCode);
}
virtual AcRx::AppRetCode On采用kUnloadAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kUnloadAppMsg(pkt);
    return (retCode);
}
virtual void RegisterServerComponents() {}

static void RivilisMyJoin() {
    // Check PEDITACCEPT sysvar
    resbuf rb = { 0, RTSHORT, 0 };
    acedGetVar(采用T("PEDITACCEPT"), &rb);
    bool bPeditAccept = (rb.resval.rint == 1) ? true : false;
    ads采用name en1;ads采用point p;
    while (acedEntSel(采用T("\nSelect first segment: "), en1, p) == RTNORM)
    {
      // if PEDITACCEPT == 1 then PEDIT no ask about converting
      bool bConvertToPoly = false;
      if (!bPeditAccept)
      {
      AcDbObjectId id1; acdbGetObjectId(id1, en1);
      if (id1.objectClass() == AcDbLine::desc() ||
          id1.objectClass() == AcDbArc::desc())
      {
          bConvertToPoly = true;
      }
      }
      ads采用name en2;
      if (acedEntSel(采用T("\nSelect next segment: "), en2, p) == RTNORM)
      {
      if (bConvertToPoly)
          acedCommandS(RTSTR, 采用T("采用PEDIT"), RTENAME, en1, RTSTR, 采用T("采用YES"), RTSTR, 采用T("采用Join"),
            RTENAME, en2, RTSTR, 采用T(""), RTSTR, 采用T(""), RTNONE);
      else
          acedCommandS(RTSTR, 采用T("采用PEDIT"), RTENAME, en1, RTSTR, 采用T("采用Join"),
            RTENAME, en2, RTSTR, 采用T(""), RTSTR, 采用T(""), RTNONE);
      }
    }
}
};

//-----------------------------------------------------------------------------
IMPLEMENT采用ARX采用ENTRYPOINT(CMyJoinApp)

ACED采用ARXCOMMAND采用ENTRY采用AUTO(CMyJoinApp, Rivilis, MyJoin, MyJoin, ACRX采用CMD采用MODAL, NULL)

admin 发表于 2024-2-15 16:36:19

//------------------------------------------------------------------------------
class SubentityOverrule : public AcDbSubentityOverrule
//------------------------------------------------------------------------------
{
public:
static SubentityOverrule* 采用pTheOverrule;
ACRX采用DECLARE采用MEMBERS(SubentityOverrule);

//--------------------------------------------------------------------------
bool isApplicable(const AcRxObject* pOverruledSubject) const
//--------------------------------------------------------------------------
{
    if (pOverruledSubject->isA() == MyClass::desc())
    {
      MyClass* pMine = MyClass::cast(pOverruledSubject);
      if (pMine != NULL)
      {
      return true;
      }
    }
    return false;
}

//--------------------------------------------------------------------------
static void SubentityOverrule::AddOverrule()
//--------------------------------------------------------------------------
{
    if (采用pTheOverrule != NULL)
    {
      return;
    }

    采用pTheOverrule = new SubentityOverrule();

    Acad::ErrorStatus es = AcRxOverrule::addOverrule(MyClass::desc(), 采用pTheOverrule, true);

    SubentityOverrule::setIsOverruling(true);
}

//--------------------------------------------------------------------------
static void SubentityOverrule::RemoveOverrule()
//--------------------------------------------------------------------------
{
    if (采用pTheOverrule == NULL)
    {
      return;
    }

    SubentityOverrule::setIsOverruling(false);

    Acad::ErrorStatus es = AcRxOverrule::removeOverrule(MyClass::desc(), 采用pTheOverrule);
    delete 采用pTheOverrule;

    采用pTheOverrule = NULL;
}

//--------------------------------------------------------------------------
Acad::ErrorStatus SubentityOverrule::getSubentPathsAtGsMarker(const AcDbEntity* pSubject, AcDb::SubentType type, Adesk::GsMarker gsMark, const AcGePoint3d& pickPoint,
                  const AcGeMatrix3d& viewXform, int& numPaths, AcDbFullSubentPath*& subentPaths, int numInserts = 0, AcDbObjectId* entAndInsertStack = NULL)
//--------------------------------------------------------------------------
{
    returnAcad::eOk;
}

//--------------------------------------------------------------------------
AcDbEntity* SubentityOverrule::subentPtr(const AcDbEntity* pSubject, const AcDbFullSubentPath& id)
//--------------------------------------------------------------------------
{
    return NULL;
}
};

SubentityOverrule* SubentityOverrule::采用pTheOverrule = NULL;
ACRX采用NO采用CONS采用DEFINE采用MEMBERS(SubentityOverrule, AcDbSubentityOverrule);

admin 发表于 2024-2-15 16:36:51

//------------------------------------------------------------------------------
Acad::ErrorStatus MyClass::subGetSubentPathsAtGsMarker(AcDb::SubentType type, Adesk::GsMarker gsMark, const AcGePoint3d& pickPoint,
                                                                const AcGeMatrix3d& viewXform, int& numPaths, AcDbFullSubentPath*& subentPaths, int numInserts, AcDbObjectId* entAndInsertStack) const
//------------------------------------------------------------------------------
{
    BOOL bCtrl = KEY采用DOWN(VK采用CONTROL);

    if (bCtrl)
    {
      return Acad::eNotImplementedYet;
    }
    else
    {
      return AcDbPolyline::subGetSubentPathsAtGsMarker(type, gsMark, pickPoint, viewXform, numPaths, subentPaths, numInserts, entAndInsertStack);
    }
}

//------------------------------------------------------------------------------
AcDbEntity* MyClass::subSubentPtr(const AcDbFullSubentPath& id) const
//------------------------------------------------------------------------------
{
    BOOL bCtrl = KEY采用DOWN(VK采用CONTROL);

    if (bCtrl)
    {
      return NULL;
    }
    else
    {
      return AcDbPolyline::subSubentPtr(id);
    }
}

admin 发表于 2024-2-15 17:29:13

acedCommandS(RTSTR, 采用T("PEDIT"),
                RTSTR, 采用T("M"),
                RTPICKS, result,
                RTSTR, 采用T(""),
                RTSTR, 采用T("Y"),
                RTSTR, 采用T("J"),
                RTSTR, 采用T("1"),//表示模糊距离
                RTSTR, 采用T(""),
                RTSTR, 采用T(""),
                RTNONE);
解释:RTPICKS 是你要转变为多段线的选择集,它的类型是ads采用name的。

acedCommandS(RTSTR, 采用T("PEDIT"),
            RTENAME, entName,
            RTSTR, 采用T("Y"),
            RTSTR, 采用T("J"),
            RTPICKS, result,//选择集,表示需要转换的实体集合。
            RTSTR, 采用T(""), RTSTR, 采用T(""), RTNONE);
解释:RTENAME ,entName 表示选择一个需要转换为多段线的实体,只能是一个,它应该是属于集合resut的。

admin 发表于 2024-2-15 17:44:00

PEDITACCEPT(系统变量)
自动将选定对象转换为多段线,而在使用 PEDIT 时不显示提示。

类型:        整数

保存位置:        注册表

初始值:        0


0      将显示提示,允许用户选择将选定对象转换为多段线

1      自动将选定对象转换为多段线,而不显示提示




CAD 编辑多段线PEDIT命令使用
PEDIT命令的使用:

在CAD的命令行中,输入PEDIT命令空格,选择要编辑的多段线,一定要是多段线。空格就可以进行修改了。

定义和用法:

PEDIT编辑多段线,编辑多段线和三维多边形网格。PEDIT的常见用途包含合并二维多段线、将线条和圆弧转换为二维多段线以及将多段线转换为近似B样条曲线的曲线(拟合多段线)。

nkmjg 发表于 2024-2-22 16:19:08

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "dbJoinEntityPE.h"

//-----------------------------------------------------------------------------
#define szRDS 采用RXST("")

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CJoinEntitiesApp : public AcRxArxApp {

public:
CJoinEntitiesApp() : AcRxArxApp() {}

virtual AcRx::AppRetCode On采用kInitAppMsg(void* pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kInitAppMsg(pkt);
    return (retCode);
}

virtual AcRx::AppRetCode On采用kUnloadAppMsg(void* pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On采用kUnloadAppMsg(pkt);
    return (retCode);
}

virtual void RegisterServerComponents() {}

static void RivilisJoinEnts()
{
    // filter for selectin lines and arcs
    ACHAR* promptPtrs[] = {
      采用T("\nSelect lines, arcs, polylines for getting polyline (ENTER - exit): "),
      采用T("\nRemove lines, arcs, polylines from selection set: ")
    };

    ads采用name ss;
    resbuf* rbFilter = acutBuildList(RTDXF0, 采用T("LINE,ARC,LWPOLYLINE"), RTNONE);
    int rc = acedSSGet(采用T(":$"), promptPtrs, NULL, rbFilter, ss);
    acutRelRb(rbFilter);

    if (rc != RTNORM) return;

    AcDbObjectIdArray ids;
    if (ObjectIdArrayFromSelSet(ss, ids) != Acad::eOk) return;

    AcDbObjectPointer<AcDbPolyline> pPoly; pPoly.create();
    pPoly->setDatabaseDefaults();
    AcArray<AcDbEntity*> ents; ents.setPhysicalLength(ids.length());

    AcDbObjectPointer<AcDbCurve> c(ids, AcDb::kForRead);
    if (c.openStatus() == Acad::eOk) {
      AcGePoint3d ptStart, ptEnd;
      c->getStartPoint(ptStart); c->getEndPoint(ptEnd);
      pPoly->addVertexAt(0, asPnt2d(asDblArray(ptStart)), BulgeFromArc(c, false), 0, 0);
      pPoly->addVertexAt(1, asPnt2d(asDblArray(ptEnd)), 0, 0, 0);
    }

    for (int i = 1; i < ids.length(); i++)
    {
      AcDbObjectPointer<AcDbCurve> c(ids, AcDb::kForRead);
      if (c.openStatus() == Acad::eOk)
      ents.append(c);
    }

    if (ents.length() > 0)
    {
      AcDbJoinEntityPE* pPE = AcDbJoinEntityPE::cast(pPoly->queryX(AcDbJoinEntityPE::desc()));

      AcGeIntArray aInts;

      Acad::ErrorStatus es = pPE->joinEntities(pPoly, ents, aInts);

      if (es != Acad::eOk)
      {
      acutPrintf(采用T("\nError pPE->joinEntities(pPoly, ents, aInts) = %s"), acadErrorStatusText(es));
      return;
      }
    }
    AcDbBlockTableRecordPointer pSpace(acdbCurDwg()->currentSpaceId(), AcDb::kForWrite);
    if (pSpace.openStatus() != Acad::eOk) return;
    pSpace->appendAcDbEntity(pPoly);
}

/// <summary>
/// Getting AcDbObjectIdArray from SelectionSet
/// </summary>
/// <param name="sset">SelectionSet</param>
/// <param name="ids">AcDbObjectIdArray</param>
/// <returns></returns>
static Acad::ErrorStatus ObjectIdArrayFromSelSet(ads采用name sset, AcDbObjectIdArray& ids)
{
    Acad::ErrorStatus es = Acad::eOk;
    Adesk::Int32 nset = -1;
    if (acedSSLength(sset, &nset) != RTNORM) return Acad::eAmbiguousInput;
    ids.setLogicalLength(nset);
    ads采用name en;
    AcDbObjectId id;
    for (long i = 0; i < nset; i++) {
      if (acedSSName(sset, i, en) == RTNORM) {
      if ((es = acdbGetObjectId(id, en)) != Acad::eOk) return es;
      ids = id;
      }
    }
    return Acad::eOk;
}
/// <summary>
/// Getting bulge for curve
/// </summary>
/// <param name="c">curve pointer</param>
/// <param name="clockwise">clockwise or counterclockwise.</param>
/// <returns></returns>
static double BulgeFromArc(AcDbCurve* c, bool clockwise)
{
    double bulge = 0.0;
    AcDbArc* a = AcDbArc::cast(c);
    if (a == NULL) return bulge;

    double newStart =
      (a->startAngle() > a->endAngle()) ?
      (a->startAngle() - 8 * atan(1.0)) :
      (a->startAngle());

    bulge = tan((a->endAngle() - newStart) / 4.0);
    if (clockwise) bulge = -bulge;
    return bulge;
}
};

//-----------------------------------------------------------------------------
IMPLEMENT采用ARX采用ENTRYPOINT(CJoinEntitiesApp)

ACED采用ARXCOMMAND采用ENTRY采用AUTO(CJoinEntitiesApp, Rivilis, JoinEnts, JoinEnts, ACRX采用CMD采用MODAL | ACRX采用CMD采用USEPICKSET, NULL)
页: [1]
查看完整版本: JoinToPline 连接线段成多段线