Nico 发表于 2010-7-18 21:07:05

使用ARX缩短一组AutoCAD线条


//...
template inline void destroy(T*& p) { delete p; p = 0; }
//...
    static AcGeVector3d delta (AcGePoint3d sp,AcGePoint3d ep)
{
    acdbWcs2Ucs(asDblArray(sp),asDblArray(sp),false);
    acdbWcs2Ucs(asDblArray(ep),asDblArray(ep),false);
    return AcGeVector3d(ep.x - sp.x,ep.y - sp.y,ep.z - sp.z);
}
static Acad::ErrorStatus selectLines(AcDbObjectIdArray &ids)
{
    Acad::ErrorStatus es = Acad::eOk;
    // ssname
    ads_name ssname = {0,0};
    //build our filter on the stack so we don't have a ptr to free
    resbuf filter = {NULL,RTDXF0};
    filter.resval.rstring = _T("LINE");
    // a nice happy message
    const TCHAR *msg[] = {_T("\nSelect Lines: "), _T("\nRemove Lines: ")};
    // get set, note the :$
    if(acedSSGet(_T(":$"),msg,0,&filter,ssname)!= RTNORM)
      return Acad::eNullObjectPointer;
    // get the ids
    es = acedGetCurrentSelectionSet(ids);
    acedSSFree(ssname);
    return es;
}
// - ArxExLine._exl command (do not rename)
static void ArxExLine_exl(void)
{
    AcDbObjectIdArray objectIds;
    if(selectLines(objectIds) != eOk)
      return;
    AcGePoint3d startPoint,endPoint;
    //Paul this is a loop of objectIds
    for(int idx = 0; idxpLn(objectIds, AcDb::kForWrite);
      if(pLn.openStatus() == eOk)
      {
      // get the start and end points
      pLn->getStartPoint(startPoint);
      pLn->getEndPoint(endPoint);
      // We'll extend our line by a quarter of the
      // existing length in each direction
      AcGeVector3d vext = delta(startPoint,endPoint) / 4;
      // extend the line
      pLn->extend(true, startPoint - vext);
      // extend the line, but don't extend the start
      pLn->extend(false, endPoint + vext);
      }
    }
}
// - ArxExLine._shl command (do not rename)
static void ArxExLine_shl(void)
{
    AcDbObjectIdArray objectIds;
    if(selectLines(objectIds) != eOk)
      return;
    double startParam=0;
    double endParam=0;
    double delta=0;
    AcGeDoubleArray paramArray;
    AcGeVoidPointerArray entPtrArray;
    //Paul this is a loop of objectIds
    for(int idx = 0; idxpCurve(objectIds, AcDb::kForWrite);
      if(pCurve.openStatus() == eOk)
      {
      // get the start and end params
      pCurve->getStartParam(startParam);
      pCurve->getEndParam(endParam);
      delta = (endParam-startParam) * 0.25;
      // add the params to our array for getSplitCurves
      paramArray.append(startParam + delta);
      paramArray.append(endParam - delta);
      if(pCurve->getSplitCurves(paramArray,entPtrArray)== eOk)
      {
          if (entPtrArray.length() == 3)
          {
            // See the arx docs for handOverTo
            AcDbEntity *newent = (AcDbEntity*)entPtrArray;
            pCurve->handOverTo(newent, true, true);
            newent->close();
            // delete the other new entities we don't need
            AcDbEntity *tmpent = (AcDbEntity*)entPtrArray;
            destroy(tmpent);
            tmpent = (AcDbEntity*)entPtrArray;
            destroy(tmpent);
            pCurve.release((AcDbLine*&)tmpent);
            destroy(tmpent);
          }
          else
          {
            // just-in-case do clean up
            for(int i = 0; i : "), rStr);
        int rVal;
        acedInitGet(RSG_NOZERO + RSG_NONEG, _T(""));
        rVal = acedGetDist(NULL, prompt, &perc);
        switch (rVal)
        {
        case RTNORM:
                acdbRToS(perc, -1, -1, rStr);
                defPerc = perc;
                break;
        case RTNONE:
                perc = defPerc;
                acdbRToS(perc, -1, -1, rStr);
                break;
        case RTCAN:
                return;
                break;
        }
        for (int i = 0; ipLine(objId, AcDb::kForWrite);
                if (pLine.openStatus() != Acad::eOk) continue;
                AcGePoint3d sp, ep;
                sp = pLine->startPoint();
                ep = pLine->endPoint();
                AcGeLineSeg3d line(sp, ep);
                AcGePoint3d midPt = sp + 0.5 * (ep - sp);
                line.scaleBy(perc, midPt);
                pLine->setStartPoint(line.startPoint());
                pLine->setEndPoint(line.endPoint());
        }
        acedSSFree(ss);
}
和类似的东西

Kerry 发表于 2010-7-19 02:07:39

不错!
页: [1]
查看完整版本: 使用ARX缩短一组AutoCAD线条