mccad 发表于 2002-2-4 15:31:00

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

//我用两种方法都行不通,请高手指教
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;
--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,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,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,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,plid) != Acad::eOk )
--{
----ads_printf("Changing to AdsName error!");
--}
--objIds.append( plid );
--
--ads_point p;
--p = 30; p = 30; p = 0;
--//问题1:acedCommand()函数老是出现访问错,请指教!!!(Test.pat为自定义充填文件)
--acedCommand(RTSTR,"-BHatch",RTSTR,"P",
RTSTR,"Test",RTSTR,"1",RTSTR,"0",
----RTSTR,"a",RTSTR,"b",RTSTR,"n",
----RTENAME,objName,RTENAME,objName,
RTENAME,objName,RTENAME,objName,
----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");
}

mccad 发表于 2002-2-4 15:32:00

解答(由老何解答)...
1,在调用acedCommand:-BHatch这前应该将将AcDbBlockTableRecord关闭
pBlockTableRecord->close();
因为此时其打开为写,而-BHATCH会创建新实体,ACAD也会去打开AcDbBlockTableRecord为写,当然会出错了。
2,appendLoop既然是loop当然是首尾相接的,所以...
页: [1]
查看完整版本: [转帖]求教,在ObjectARX中如何进行充填编程?