LoveArx 发表于 2016-8-5 11:40:19

ARX实例代码 -- 重建填充的边界

本帖最后由 LoveArx 于 2016-8-5 11:52 编辑


//-----------------------------------------------------------------------------
// This is command 'RESTOREHATCHBOUNDARY, by Bill Zhang , DevTech, Autodesk
void BzhRestoreHatchBoundary()
{
// TODO: Implement the command
// create a resbuf which is filled with filter conditions.
struct resbuf *filter = acutBuildList(RTDXF0, _T("HATCH"), RTNONE);
ads_name ss;
// ask users to select hatch entities.
int res = acedSSGet(NULL, NULL, NULL, filter, ss);
// release filter resbuf.
acutRelRb (filter);
if( res != RTNORM )
{
   acutPrintf(_T("\nNo hatch entities selected!"));
   return;
}


long length=0l;
acedSSLength (ss, &length);
for(long indexSS=0l; indexSS<length; indexSS++)
{
ads_name eName;
res = acedSSName(ss, indexSS, eName);
    if( res != RTNORM )
continue;


AcDbObjectId id;
acdbGetObjectId(id, eName );
AcDbHatch*pHatch=NULL;
acdbOpenObject(pHatch, id, AcDb::kForRead );
if( pHatch == NULL )
      continue;


// For each loop, draw the boundary.
int nLoops = pHatch->numLoops();
for( int i=0;i<nLoops; i++ )
{
long loopType;
if( pHatch->loopTypeAt( i ) & AcDbHatch::kPolyline )
{      
   AcGePoint2dArray vertices;
   AcGeDoubleArray bulges;
   pHatch->getLoopAt( i, loopType, vertices, bulges );   
   int nVertices = vertices.length();
   AcDbPolyline *pPoly = new AcDbPolyline(nVertices);
   for( int vx=0;vx<nVertices;vx++ )
   {
    double bulge = bulges.length() < nVertices ? 0.0: bulges;
    pPoly->addVertexAt( vx, vertices, bulge );
   }
   // append it to the current space of AutoCAD database
   pPoly->setColorIndex(1);
   addAEntToTheCurrentSpaceAndClose(pPoly);
}   
else
{      
   AcGePoint2dArray vertices;
   AcGeDoubleArray bulges;
   AcGeVoidPointerArray edgePtrs;
   AcGeIntArray edgeTypes;
   pHatch->getLoopAt(i, loopType,edgePtrs, edgeTypes );
   for(int j=0; j<edgePtrs.length(); j++)
   {
    switch (edgeTypes){
    case AcDbHatch::kLine:
   {
      AcGeLineSeg3d *pGeLine3d = (AcGeLineSeg3d*)edgePtrs;
      AcGePoint3d geP1, geP2;
      geP1 = pGeLine3d->startPoint();
      geP2 = pGeLine3d->endPoint();
      AcDbLine *pLine = new AcDbLine(geP1, geP2);
      pLine->setColorIndex(1);
      addAEntToTheCurrentSpaceAndClose(pLine);
   }
   break;
    case AcDbHatch::kCirArc:
   {
      AcGePoint3d geCenter;
      double dRadius, dStartAng, dEndAng;
      AcGeCircArc3d *pGeArc = (AcGeCircArc3d*)edgePtrs;
      geCenter = pGeArc->center();
      dRadius = pGeArc->radius();
      dStartAng = pGeArc->startAng();
      dEndAng = pGeArc->endAng();
      double dAngDiff;
      dAngDiff = fabs( dEndAng - dStartAng - atan(double(1))*8 );
      if( dAngDiff > 1e-5 ) // It's an ARC.
      {
       AcDbArc *pArc = new AcDbArc(geCenter, dRadius, dStartAng, dEndAng);
       pArc->setColorIndex(1);
       addAEntToTheCurrentSpaceAndClose(pArc);
      }
      else // It's a circle.
      {
       AcGeVector3d geNorm = pGeArc->normal();
       AcDbCircle *pCir = new AcDbCircle(geCenter, geNorm, dRadius);
       pCir->setColorIndex(1);
       addAEntToTheCurrentSpaceAndClose(pCir);
      }
   }
   break;
    case AcDbHatch::kEllArc:
   {
      AcGePoint3d geCenter;
      AcGeVector3d geNorm,dMajorAxis, dMinorAxis;
      double dMajorRadius, dMinorRadius;
      double dStartAng, dEndAng;
      AcGeEllipArc3d *pGeEllip = (AcGeEllipArc3d*)edgePtrs;
      geCenter = pGeEllip->center();
      dStartAng = pGeEllip->startAng();
      dEndAng = pGeEllip->endAng();
      geNorm = pGeEllip->normal();
      dMajorAxis = pGeEllip->majorAxis();
      dMinorAxis = pGeEllip->minorAxis();
      dMajorRadius = pGeEllip->majorRadius();
      dMinorRadius = pGeEllip->minorRadius();
      AcDbEllipse *pEllip = new AcDbEllipse();
      // Note: radiusRatio = dMinorRadius/dMajorRadius (must be within )
      pEllip->set(geCenter,geNorm,dMajorAxis*dMajorRadius,dMinorRadius/dMajorRadius);
      pEllip->setStartParam(dStartAng);
      pEllip->setEndParam(dEndAng);
      if( pEllip->isNull() == Adesk::kTrue)
      {
       acutPrintf(_T("\nFailed to create an ellipse."));
       break;
      }
      else
      {
       pEllip->setColorIndex(1);
       addAEntToTheCurrentSpaceAndClose(pEllip);
      }
   }
   break;
    case AcDbHatch::kSpline:
   {
      Adesk::Boolean bIsFixSpline;
      AcGePoint3dArray fitPoints;
      AcGeTol fitTol;
      Adesk::Boolean bTangent**ist;
      AcGeVector3d startTangent, endTangent;
      int deg;
      AcGeNurbCurve3d*pGeSpline=(AcGeNurbCurve3d *)edgePtrs;
      assert(pGeSpline);
      deg = pGeSpline->degree();
      bIsFixSpline = pGeSpline->getFitData(fitPoints,
               fitTol,
               bTangent**ist,
               startTangent,
               endTangent);
      if( bIsFixSpline == Adesk::kTrue )
      {
       AcDbSpline *pSpline=new AcDbSpline();
       pSpline->setFitData(fitPoints,
            deg,
            fitTol.equalVector(),
            startTangent,
            endTangent);
       if( pSpline->isNull() == Adesk::kTrue)
       {
      acutPrintf(_T("\nFailed to create a spline."));
      break;
       }
       else
       {
      pSpline->setColorIndex(1);
      addAEntToTheCurrentSpaceAndClose(pSpline);
       }
      }
      else
      {
       Adesk::Boolean rational,closed,periodic;
       AcGePoint3dArray gePoints;
       AcGeDoubleArray geWeights;
       AcGePoint3d gePoint;
       AcGeKnotVector geKnots;
       AcGeDoubleArray dKnots;


       rational = pGeSpline->isRational();
       closed = pGeSpline->isClosed();
       periodic = Adesk::kFalse;
       for(int k=0; k<pGeSpline->numControlPoints(); k++)
       {
      gePoints.append(pGeSpline->controlPointAt(k));
       }
       for(int k=0; k<pGeSpline->numWeights(); k++)
       {
      geWeights.append(pGeSpline->weightAt(k));
       }
       geKnots = pGeSpline->knots();      
       for(int k=0; k<geKnots.length(); k++)
       {
      dKnots.append(geKnots);
       }


       AcDbSpline *pSpline=new AcDbSpline(deg,
         rational,
         closed,
         periodic,
         gePoints,
         dKnots,
         geWeights);
       if( pSpline->isNull() == Adesk::kTrue)
       {
      acutPrintf(_T("\nFailed to create a spline."));
      break;
       }
       else
       {
      pSpline->setColorIndex(1);
      addAEntToTheCurrentSpaceAndClose(pSpline);
       }
      }
   }
   break;
    default:
   break;
    }
   }
}
}
pHatch->close();
}


// free up the selection set
acedSSFree (ss);
}


**** Hidden Message *****


819534890 发表于 2016-8-5 16:51:57

good good。

ABC2016 发表于 2016-8-5 17:06:04

学习专业知识了

aeo 发表于 2016-8-5 21:40:19

:curse::curse::curse::dizzy::dizzy::dizzy::lol:lol:Q:Q:P:P:D:D:(:(:):):@:@:@:@:loveliness::loveliness:

稻草人i 发表于 2016-8-10 18:18:42

我要看贴 快快开门

革天明 发表于 2016-8-10 21:55:11

谢谢楼主分享,学习一下

zjy2999 发表于 2016-10-23 14:59:45

学习!!!!!!!!!!!!!!!

hyt520 发表于 2016-10-26 19:13:35

ARX实例代码 -- 重建填充的边界

Urings 发表于 2016-12-11 05:05:56

谢谢分享.

qq564837358 发表于 2016-12-24 21:37:15

??还有隐藏的?

qq564837358 发表于 2016-12-24 21:53:29

objectarx2012+CAD2012+vs2010 测试崩溃?

w15994259099 发表于 2016-12-25 10:40:42

代码写得真好,谢谢作者!

fu000000 发表于 2016-12-27 16:20:39

膜拜{:soso__10169062262133571330_1:}正需要,支持楼主大人了!

用途 发表于 2016-12-31 11:30:47

谢谢分享.

lhg 发表于 2017-1-8 13:52:06

正需要,支持楼主大人了!
页: [1] 2 3 4
查看完整版本: ARX实例代码 -- 重建填充的边界