明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3636|回复: 1

[转帖]求教,在ObjectARX中如何进行充填编程?

[复制链接]
发表于 2002-2-4 15:31:00 | 显示全部楼层 |阅读模式
//我用两种方法都行不通,请高手指教
void CDocData:rawLine()
{
acutPrintf("\nBegin drawing!\n");

--AcGePoint3d startPt;
--AcGePoint3d endPt;

--AcDbBlockTable* pBlockTable;
--acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead);

--AcDbBlockTableRecord* pBlockTableRecord;
--pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
--pBlockTable->close();

--//Create hatch
AcDbObjectIdArray objIds;
--ads_name objName[4];
--AcDbObjectId plid;
--AcDbPolyline *pPl = new AcDbPolyline();
--pPl->addVertexAt( 0,AcGePoint2d(0,10) );
--pPl->addVertexAt( 1,AcGePoint2d(2,30) );
--pPl->addVertexAt( 2,AcGePoint2d(7,68) );
--pPl->addVertexAt( 3,AcGePoint2d(10,100) );
--pBlockTableRecord->appendAcDbEntity(plid,pPl);
--pPl->close();
--if( acdbGetAdsName(objName[0],plid) != Acad::eOk )
--{
----ads_printf("Changing to AdsName error!");
--}
--objIds.append( plid );

--pPl = new AcDbPolyline();
--pPl->addVertexAt( 0,AcGePoint2d(0,98) );
--pPl->addVertexAt( 1,AcGePoint2d(200,130) );
--pBlockTableRecord->appendAcDbEntity(plid,pPl);
--pPl->close();
--acdbGetAdsName(objName[1],plid);
--objIds.append( plid );

--pPl = new AcDbPolyline();
--pPl->addVertexAt( 0,AcGePoint2d(180,150) );
--pPl->addVertexAt( 1,AcGePoint2d(180,-10) );
--pBlockTableRecord->appendAcDbEntity(plid,pPl);
--pPl->close();
--acdbGetAdsName(objName[2],plid);
--objIds.append( plid );

--pPl = new AcDbPolyline();
--pPl->addVertexAt( 0,AcGePoint2d(188,0) );
--pPl->addVertexAt( 1,AcGePoint2d(0,10) );
--pBlockTableRecord->appendAcDbEntity(plid,pPl);
--pPl->close();
--if( acdbGetAdsName(objName[3],plid) != Acad::eOk )
--{
----ads_printf("Changing to AdsName error!");
--}
--objIds.append( plid );
--
--ads_point p;
--p[X] = 30; p[Y] = 30; p[Z] = 0;
--//问题1:acedCommand()函数老是出现访问错,请指教!!!(Test.pat为自定义充填文件)
--acedCommand(RTSTR,"-BHatch",RTSTR,"",
RTSTR,"Test",RTSTR,"1",RTSTR,"0",
----RTSTR,"a",RTSTR,"b",RTSTR,"n",
----RTENAME,objName[0],RTENAME,objName[1],
RTENAME,objName[2],RTENAME,objName[3],
----RTSTR,"",RTSTR,"",RTPOINT, p,RTSTR,"",0);


--//问题2:本想用AcDbHatch创建一个充填,但有问题
--//add hatch
--AcDbHatch* pHatch = new AcDbHatch();
--pHatch->setPatternAngle(0);
--pHatch->setPatternSpace(1);
--pHatch->setPatternDouble(Adesk::kFalse);
--pHatch->setAssociative( Adesk::kTrue );
--pHatch->setHatchStyle(AcDbHatch::kNormal );
--if( pHatch->setPattern(AcDbHatch::kCustomDefined, "Test") != Acad::eOk)
--{
----ads_printf("Create hatch pattern error!");
----delete pHatch;
--}
--else
--{
----Acad::ErrorStatus es;
----//此处出错
----if ( ( es = pHatch->appendLoop(AcDbHatch::kDefault, objIds)) != Acad::eOk )
    {
      ads_printf("hatch appendLoop error!");
      delete pHatch;
    }
    else
      if( pHatch->evaluateHatch() != Acad::eOk )
      {
        ads_printf("EvaluateHatch hatch pattern error!");
        delete pHatch;
      }
      else
      {
        pBlockTableRecord->appendAcDbEntity(pHatch);
        pHatch->close();
      }
  }

  pBlockTableRecord->close();
acutPrintf("\nEnd drawing!\n");
}
 楼主| 发表于 2002-2-4 15:32:00 | 显示全部楼层
解答(由老何解答)...
1,在调用acedCommand:-BHatch这前应该将将AcDbBlockTableRecord关闭
pBlockTableRecord->close();
因为此时其打开为写,而-BHATCH会创建新实体,ACAD也会去打开AcDbBlockTableRecord为写,当然会出错了。
2,appendLoop既然是loop当然是首尾相接的,所以...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 04:29 , Processed in 0.153664 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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