明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2630|回复: 5

环形填充,非常实用

[复制链接]
发表于 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;
}
找好心人帮助,解决了部分问题,图形绘出了,但是没有填充效果,就是没有填上,不知为何?
发表于 2010-12-16 16:19:59 | 显示全部楼层
你写的程序真成问题了,我认为你应该去看看帮助文档(关于AcDbHatch类的那部分)
发表于 2010-12-16 16:35:28 | 显示全部楼层
还有就是你的填充图形已经绘制出来了,你可以用LIST命令去查看一下当前图纸。
只不过它绘制的位置在原点,并且没有大小。
我认为造成这种问题的原因在于你设置的AcDbObjectIdArray
发表于 2014-12-3 16:11:43 | 显示全部楼层
不错,值得一看
发表于 2014-12-23 08:49:23 | 显示全部楼层
刚路过,见一回顶一回
发表于 2015-3-8 11:20:37 | 显示全部楼层
水一帖。。我顶。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 06:38 , Processed in 0.152658 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表