明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1754|回复: 0

INTERSECTWITH函数的问题出在哪里?

[复制链接]
发表于 2005-10-20 12:26:00 | 显示全部楼层 |阅读模式

我在外部图纸中做了一个块,把它插入到当前图纸中,希望实现该块与直线相交获得焦点,删除旧直线,然后重画两条直线,实现"打断"功能.可是插入后却第一次插入后只能在块的最左边获得一个焦点,第二次以后就能实现预期的功能,这到底是什么原因啊?希望能由高手赐教!代码如下:
//搜索数据库中所有的直线
 AcDbObjectIdArray lineIdArray;
 AcGePoint3d pt1,pt2;
 AcDbBlockTableRecordIterator *pBlkItr;
 pCurDb->getSymbolTable(pBlockTable,AcDb::kForRead);
 pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForRead);
 pBlockTable->close();
 pBlockTableRecord->newIterator(pBlkItr);
 pBlockTableRecord->close();
 for(pBlkItr->start();!pBlkItr->done();pBlkItr->step())
 {
  AcDbEntity* pEntity;
  AcDbObjectId lineId;
  pBlkItr->getEntity(pEntity,AcDb::kForRead);
  //acedAlert(pEntity->isA()->name());
  ////
  /*if(!strcmp("_line",(pEntity->isA()->name())))
  {
   lineId=pEntity->objectId();
   lineIdArray.append(lineId);
  }
  pEntity->close();*/
  ////
  //if(!strcmp("AcDbLine",(pEntity->isA()->name())))
  if(pEntity->isKindOf(AcDbLine::desc()))
  {
   lineId=pEntity->objectId();
   lineIdArray.append(lineId);
  }
 
  pEntity->close();
 }
 delete pBlkItr;
 int nLineNumber=lineIdArray.length();
 AcDbEntity* pBlock;
 
 acdbOpenObject(pBlock,refId,AcDb::kForRead);
 for(int i=0;i<nLineNumber;i++)
 {
  AcDbLine* pLine;
  AcDbObjectId id=lineIdArray.at(i);
  AcGePoint3dArray pts;
  acdbOpenObject(pLine,id,AcDb::kForWrite);
 
  pBlock->boundingBoxIntersectWith(pLine,AcDb::kOnBothOperands,pts,0,0);
  //pLine->intersectWith(pBlock,AcDb::kOnBothOperands,pts);
  //AcGePoint3d pt1=points.first();
  //AcGePoint3d pt2=points.last();
  //AcGePoint2d pot1(pt1.x,pt1.y);
  //AcGePoint2d pot2(pt2.x,pt2.y);
  /*if (pts.length()==0)//直线与块没有交点
  {
   pLine->close();
   continue;
  }*/
  //pts.
  if(pts.length()>0)
  {
   double dis1 = pts.first().distanceTo(pLine->startPoint());
   double dis2 = pts.last().distanceTo(pLine->startPoint());
   acutPrintf("\nthe length is %0.6f",pts.length());
   //pts.
   //acutPrintf("the length is %0.6f",dis2);
   if (dis1 > dis2 )
   {
   
   
    pt1 = pts.last();
    pt2 = pts.first();
   }
   else
   {
    acutPrintf("\nthe length of two point is Longer than 12");
    pt1 = pts.first();
    pt2 = pts.last();
   }
  
   AcDbLine* line1=new AcDbLine(pLine->startPoint(), pt1);
   AcDbLine* line2=new AcDbLine(pt2, pLine->endPoint());
   pLine->erase();
  
  

   pCurDb->getSymbolTable(pBlockTable,AcDb::kForRead);
   pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
   pBlockTable->close();
   AcDbObjectId lineId1,lineId2;
   pBlockTableRecord->appendAcDbEntity(lineId1,line1);
   pBlockTableRecord->appendAcDbEntity(lineId2,line2);
   line1->close();
   line2->close();
   pBlockTableRecord->close();
  
  
   //continue;
  }
 pLine->close();
 
 }
 pBlock->close();
 //pBlockTableRecord->close();
 acDocManager->unlockDocument(curDoc());

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 03:28 , Processed in 0.153376 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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