找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 674|回复: 0

[求助]:AcDbHatch求助

[复制链接]
发表于 2006-4-5 19:59:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Acad::ErrorStatus acqHatch2()
{
    AcDbHatch* pHatch = new AcDbHatch();

    // Set hatch plane
    //
    AcGeVector3d normal(0.0, 0.0, 1.0);
    pHatch->setNormal(normal);
    pHatch->setElevation(0.0);

    // Set hatch pattern to ANSI31 predefined type
    //
    pHatch->setPattern(AcDbHatch::kPreDefined, "ANSI31");

    // Set Associativity
    //
    pHatch->setAssociative(Adesk::kTrue);

    // Construct database AcDbLines
    //
    AcGePoint3d vertexPts[4];
    AcDbObjectId lineId, cirId, hatchId;
    AcDbObjectIdArray dbObjIds,dbObjId2;
    AcDbLine *line;

    vertexPts[0].set(2.0, 2.0, 0.0);
    vertexPts[1].set(20.0, 2.0, 0.0);
    vertexPts[2].set(20.0, 20.0, 0.0);
    vertexPts[3].set(2.0, 8.0, 0.0);
    int b;

    CreateLine(vertexPts[0],vertexPts[1],lineId);
    dbObjIds.append(lineId);
    CreateLine(vertexPts[1],vertexPts[2],lineId);
    dbObjIds.append(lineId);

    CreateLine(vertexPts[2],vertexPts[3],lineId);
    dbObjIds.append(lineId);
    CreateLine(vertexPts[3],vertexPts[0],lineId);
    b = dbObjIds.append(lineId);

    // Append an external rectangular loop to hatch boundary
    //
   pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds);
   b = pHatch->numLoops();

    // Create a AcDbCircle and post it to database

   
    //
    AcGePoint3d cenPt(5.0, 5.0, 0.0);

    AcDbCircle *circle = new AcDbCircle(cenPt,normal,2);
   
    AcDbBlockTable *pBlockTbale;
    Acad::ErrorStatus es = acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTbale, AcDb::kForRead);

    if (es != Acad::eOk)
    {
        //delete pLine;
        return es;
    }

    AcDbBlockTableRecord  *pBlockTbaleRecord;
    pBlockTbale->getAt(ACDB_MODEL_SPACE, pBlockTbaleRecord, AcDb::kForWrite);
    pBlockTbale->close();
    es = pBlockTbaleRecord->appendAcDbEntity(cirId, circle);

    dbObjIds.setLogicalLength(0);
    b = dbObjIds.append(cirId);
    b = dbObjIds.length();

    // Append an internal loop (circle) to hatch boundary
    //
   //在调用这里的时候,返回错误, 想问问为什么?
    if(Acad::eOk!=pHatch->appendLoop(AcDbHatch::kDefault ,dbObjIds))
    {
        AfxMessageBox("加入错误");
        return Acad::eOk;
    }

    b = pHatch->numLoops();

    // Elaborate hatch lines
    //
    pHatch->evaluateHatch();

    // Get all associative source boundary object Ids for later use.
    //
    dbObjIds.setLogicalLength(0);
    pHatch->getAssocObjIds(dbObjIds);

    b = dbObjIds.length();

    // Post hatch entity to database
    //
    //pHatch->postToDb(pHatch, hatchId);
    pBlockTbaleRecord->appendAcDbEntity(hatchId, pHatch);
   
    pBlockTbaleRecord->close();
    circle->close();


    // Attach hatchId to all source boundary objects for notification.
    //
    AcDbEntity *pEnt;
    int numObjs = dbObjIds.length();
    //Acad::ErrorStatus es;
    for (int i = 0; i < numObjs; i++)
    {
        es = acdbOpenAcDbEntity(pEnt, dbObjIds, AcDb::kForWrite);
        if (es == Acad::eOk)
        {
            pEnt->addPersistentReactor(hatchId);
            pEnt->close();
        }
    }
    return eOk;
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-22 02:01 , Processed in 0.397392 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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