明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1987|回复: 2

[求助]请帮忙把这段代码转成*.ARX

[复制链接]
发表于 2010-1-30 10:25:00 | 显示全部楼层 |阅读模式

ads_name ents;
 if(ads_ssget(NULL,NULL,NULL,NULL,ents) == RTNORM)
 {
  AcDbExtents ext;
  long nLen = 0;
  ads_sslength(ents,&nLen);
  long i = 0;
  for (; i < nLen; i++)
  {
   ads_name curEnt;
   ads_ssname(ents,i,curEnt);
   AcDbObjectId curId;
   if(acdbGetObjectId(curId,curEnt) != Acad::eOk)
    continue;
   AcDbEntity * pEnt = NULL;
   acdbOpenAcDbEntity(pEnt,curId,AcDb::kForRead);
   if (pEnt == NULL)
    continue;
   AcDbExtents curExt;
   pEnt->getGeomExtents(curExt);
   ext.addExt(curExt);
  }
  ads_ssfree(ents);
  AcDbDatabase * pDb = acdbCurDwg();
  if (pDb == NULL)
   return;
  AcDbBlockTable * pBlock = NULL;
  pDb->getBlockTable(pBlock,AcDb::kForWrite);
  if (pBlock == NULL)
   return;
  AcDbBlockTableRecord * pRecord = NULL;
  pBlock->getAt(ACDB_MODEL_SPACE,pRecord,AcDb::kForWrite);
  if (pRecord == NULL)
  {
   pBlock->close();
   return;
  }
  pBlock->close();
 
  //绘制矩形
  AcDbPolyline *pPolyExt = new AcDbPolyline;
  pPolyExt->addVertexAt(0,AcGePoint2d(ext.minPoint().x,ext.minPoint().y));
  pPolyExt->addVertexAt(1,AcGePoint2d(ext.minPoint().x,ext.maxPoint().y));
  pPolyExt->addVertexAt(2,AcGePoint2d(ext.maxPoint().x,ext.maxPoint().y));
  pPolyExt->addVertexAt(3,AcGePoint2d(ext.maxPoint().x,ext.minPoint().y));
  pPolyExt->setClosed(Adesk::kTrue);
  //绘制中心线
  AcDbLine * pVLn = new AcDbLine,* pHLn = new AcDbLine;
  pVLn->setStartPoint(AcGePoint3d((ext.minPoint().x+ext.maxPoint().x)*0.5,ext.minPoint().y,0));
  pVLn->setEndPoint(AcGePoint3d((ext.minPoint().x+ext.maxPoint().x)*0.5,ext.maxPoint().y,0));
  pHLn->setStartPoint(AcGePoint3d(ext.minPoint().x,(ext.minPoint().y+ext.maxPoint().y)*0.5,0));
  pHLn->setEndPoint(AcGePoint3d(ext.maxPoint().x,(ext.minPoint().y+ext.maxPoint().y)*0.5,0));
  pRecord->appendAcDbEntity(pPolyExt);
  pRecord->appendAcDbEntity(pVLn);
  pRecord->appendAcDbEntity(pHLn);
  pPolyExt->close();
  pVLn->close();
  pHLn->close();
  pRecord->close();
 }

发表于 2010-1-30 15:48:00 | 显示全部楼层

貌似可以在ARX下运行的,如果真的要转,把ads函数改为arx对应的函数吧。

发表于 2010-4-29 15:56:00 | 显示全部楼层

  ads_name ents;
  if(acedSSGet(NULL,NULL,NULL,NULL,ents) == RTNORM)
  {
    AcDbExtents ext;
    long nLen = 0;
    acedSSLength(ents,&nLen);

    for ( long i = 0; i < nLen; i++)
    {
      ads_name curEnt;
      acedSSName(ents,i,curEnt);

      AcDbObjectId curId;
      if(acdbGetObjectId(curId,curEnt) != Acad::eOk)
        continue;

      AcDbEntity * pEnt = NULL;
      acdbOpenAcDbEntity(pEnt,curId,AcDb::kForRead);
      if (pEnt == NULL)
        continue;

      AcDbExtents curExt;
      pEnt->getGeomExtents(curExt);
      ext.addExt(curExt);
    }
   
    acedSSFree(ents);
    AcDbDatabase * pDb = acdbCurDwg();
    if (pDb == NULL)
      return 1;
    AcDbBlockTable * pBlock = NULL;
    pDb->getBlockTable(pBlock,AcDb::kForWrite);
    if (pBlock == NULL)
      return 1;

    AcDbBlockTableRecord * pRecord = NULL;
    pBlock->getAt(ACDB_MODEL_SPACE,pRecord,AcDb::kForWrite);
    if (pRecord == NULL)
    {
      pBlock->close();
      return 1;
    }
    pBlock->close();

// ...

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

本版积分规则

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

GMT+8, 2024-11-25 12:32 , Processed in 0.168032 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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