mdh0530 发表于 2010-12-15 23:30:22

环形填充,非常实用

Acad::ErrorStatus postToModel(AcDbObjectId& objId, AcDbEntity* pEnt);
               // Add your code for command TestReadDWG.test3 here
                AcDbHatch* pHatch = new AcDbHatch();
                AcGeVector3d normal(0.0, 0.0, 1.0);
                pHatch->setNormal(normal);
                pHatch->setElevation(0.0);
               pHatch->setAssociative(Adesk::kTrue);
                pHatch->setPattern(AcDbHatch::kPreDefined, _T("SOLID"));
                // pHatch->setStyle(AcDbHatch::kNormal);
int a=1000;int b=1000;
//左墙高
AcGePoint3d start1(a,b,0);
AcGePoint3d end1(a,b+(m_fHight_L_HD),0);
AcDbLine*q2Line=new AcDbLine(start1,end1);
    AcDbObjectId idq2Line = AcDbObjectId::kNull;
    postToModel(idq2Line,q2Line);
//右墙高
AcGePoint3d start2(a+(m_fWidth_HD),b,0);
AcGePoint3d end2(a+(m_fWidth_HD),b+(m_fHight_R_HD),0);
AcDbLine*r2Line=new AcDbLine(start2,end2);
    AcDbObjectId idr2Line = AcDbObjectId::kNull;
    postToModel(idr2Line,r2Line);

int m_thinckness=100;
//左高
AcGePoint3d start21(a+m_thinckness,b,0);
AcGePoint3d end21(a+m_thinckness,b+m_fHight_L_HD,0);
AcDbLine*qLine=new AcDbLine(start21,end21);
    AcDbObjectId idqLine = AcDbObjectId::kNull;
    postToModel(idqLine,qLine);
//右高
AcGePoint3d start22(a+m_fWidth_HD-m_thinckness,b,0);
AcGePoint3d end22(a+m_fWidth_HD-m_thinckness,b+(m_fHight_R_HD),0);
AcDbLine*rLine=new AcDbLine(start22,end22);
    AcDbObjectId idrLine = AcDbObjectId::kNull;
    postToModel(idrLine,rLine);
///////////////////////////////
//半圆拱底部连线1
   AcGePoint3d start8(a,b+m_fHight_L_HD,0);
AcGePoint3d end8(a+m_thinckness,b+m_fHight_L_HD,0);
AcDbLine*dLine=new AcDbLine(start8,end8);
    AcDbObjectId iddLine = AcDbObjectId::kNull;
    postToModel(iddLine,dLine);
//半圆拱底部连线2
AcGePoint3d start9(a+m_fWidth_HD-m_thinckness,b+m_fHight_R_HD,0);
AcGePoint3d end9(a+m_fWidth_HD,b+(m_fHight_R_HD),0);
AcDbLine*cLine=new AcDbLine(start9,end9);
    AcDbObjectId idcLine = AcDbObjectId::kNull;
    postToModel(idcLine,cLine);
/////////////////////////////////////
//半圆拱外圆
AcDbArc*pSemiCircle=new AcDbArc(AcGePoint3d ((a+(m_fWidth_HD)/2), (b+(m_fHight_L_HD)/2+(m_fHight_R_HD)/2), 0), (m_fWidth_HD)/2, 0, PI );
   
AcDbObjectId idpSemiCircle = AcDbObjectId::kNull;
    postToModel(idpSemiCircle,pSemiCircle);
//半圆拱内圆
AcDbArc*p1SemiCircle=new AcDbArc(AcGePoint3d ((a+(m_fWidth_HD)/2), b+(m_fHight_L_HD)/2+(m_fHight_R_HD)/2, 0),
                (m_fWidth_HD-m_thinckness*2)/2, 0, PI );
AcDbObjectId idp1SemiCircle = AcDbObjectId::kNull;
    postToModel(idp1SemiCircle,p1SemiCircle);

//直墙厚度左连线
AcGePoint3d start23(a,b,0);
AcGePoint3d end23(a+m_thinckness,b,0);
AcDbLine*q1Line=new AcDbLine(start23,end23);
AcDbObjectId idq1Line = AcDbObjectId::kNull;
    postToModel(idq1Line,q1Line);

//直墙厚度右连线
AcGePoint3d start24(a+m_fWidth_HD-m_thinckness,b,0);
AcGePoint3d end24(a+m_fWidth_HD,b,0);
AcDbLine*r1Line=new AcDbLine(start24,end24);
AcDbObjectId idr1Line = AcDbObjectId::kNull;
    postToModel(idr1Line,r1Line);


               
                AcDbObjectIdArray objIds;
                objIds.append(idq2Line);
                objIds.append(idr2Line);
                objIds.append(idqLine);
                objIds.append(idrLine);
                objIds.append(idq1Line);
                objIds.append(idr1Line);
               objIds.append(iddLine);
                objIds.append(idcLine);

                objIds.append(idpSemiCircle);
                objIds.append(idp1SemiCircle);

                pHatch->appendLoop(AcDbHatch::kExternal, objIds);
                // Construct a circle
                // Elaborate solid fill
                pHatch->evaluateHatch();
                // Post hatch entity to database
                AcDbObjectId objId = AcDbObjectId::kNull;
                postToModel(objId,pHatch);
Acad::ErrorStatus postToModel(AcDbObjectId& objId, AcDbEntity* pEnt)
{
      Acad::ErrorStatus es = Acad::eOk;
      AcDbBlockTable *pBlockTable;
      acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
      AcDbBlockTableRecord *pBlockTableRecord;
      pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
      pBlockTable->close();
      AcDbObjectId objectId = AcDbObjectId::kNull;
      es = pBlockTableRecord->appendAcDbEntity(objectId, pEnt);
      objId = objectId;
      pBlockTableRecord->close();
      pEnt->close();

      return es;
}
找好心人帮助,解决了部分问题,图形绘出了,但是没有填充效果,就是没有填上,不知为何?

th_gsb 发表于 2010-12-16 16:19:59

你写的程序真成问题了,我认为你应该去看看帮助文档(关于AcDbHatch类的那部分)

th_gsb 发表于 2010-12-16 16:35:28

还有就是你的填充图形已经绘制出来了,你可以用LIST命令去查看一下当前图纸。
只不过它绘制的位置在原点,并且没有大小。
我认为造成这种问题的原因在于你设置的AcDbObjectIdArray

sanqima88 发表于 2014-12-3 16:11:43

不错,值得一看

jxy308 发表于 2014-12-23 08:49:23

刚路过,见一回顶一回

冷雨佳缘 发表于 2015-3-8 11:20:37

水一帖。。我顶。。。。
页: [1]
查看完整版本: 环形填充,非常实用