找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1183|回复: 0

[每日一码] 转换同面的3DPOLYLINE到AcDb2dPolyline

[复制链接]

已领礼包: 13个

财富等级: 恭喜发财

发表于 2016-8-13 15:02:10 | 显示全部楼层 |阅读模式

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

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

×

Issue
How do I convert planar AcDb3dPolyline to AcDb2dPolyline? The coordinates
obtained from an existing 3D polyline are in WCS, and the AcDb2dPolyline needs
vertex coordinates in an Object Coordinate System

Solution
If the AcDb3dPolylines are in the current UCS, then it is easier to convert the
vertex points obtained from the WCS to an Object Coordinate System by getting
the normal of the current UCS, which will be subsequently used in
acdbWcs2Ecs().

The following sample code demonstrates the same; the new AcDb2dPolyLines are
drawn in a blue color on layer "0".


  1. void asdktest()
  2. {
  3.   ads_name ss;  
  4.   ACHAR* prompts[2]={L"\nSelect 3d polylines",L"\nUnselect objects"};
  5.   int res=acedSSGet(L":$",prompts,NULL,NULL,ss);  
  6.   if (RTNORM != res)  
  7.   {      
  8.    acutPrintf(L"\nNo objects selected");
  9.    return;  
  10.   }
  11.   long len;
  12.   res=acedSSLength(ss,&len);
  13.   if (RTNORM != res || len == 0)
  14.   {      
  15.    acutPrintf(L"\nNo objects selected");  
  16.    return;  
  17.   }
  18.   //get coordinate system from current UCS   
  19.   AcGeMatrix3d mat;   
  20.   acdbUcsMatrix(mat);   
  21.   AcGePoint3d  origin;  
  22.   AcGeVector3d xAxis;  
  23.   AcGeVector3d yAxis;  
  24.   AcGeVector3d norm;  
  25.   mat.getCoordSystem(origin,xAxis,yAxis,norm);
  26.   Acad::ErrorStatus es;  
  27.   for(int i=0 ; i < len ; i++)
  28.   {   
  29.    ads_name eName;  
  30.    acedSSName(ss,i,eName);
  31.    AcDbObjectId objId;
  32.    acdbGetObjectId(objId,eName);
  33.    AcDb3dPolyline *pPline=NULL;
  34.    es=acdbOpenObject(pPline, objId, AcDb::kForRead);      
  35.    if (Acad::eOk == es)      
  36.    {         
  37.     AcDbObjectIterator *pVertIter= pPline->vertexIterator();  
  38.     Adesk::Boolean isClosed=Adesk::kFalse;
  39.     isClosed=pPline->isClosed();      
  40.     pPline->close();
  41.     // Finished with the pline header.      
  42.     AcGePoint3d location;   
  43.     AcDbObjectId vertexObjId;
  44.     AcGePoint3dArray aPts;   

  45.     for (;!pVertIter->done();pVertIter->step())   
  46.     {           
  47.      AcDb3dPolylineVertex *pVertex;   
  48.      vertexObjId = pVertIter->objectId();   
  49.      acdbOpenObject(pVertex, vertexObjId,  AcDb::kForRead);         
  50.      aPts.append(pVertex->position());      
  51.      pVertex->close();           
  52.     }
  53.     delete pVertIter;
  54.     AcGePoint3dArray newPts;     
  55.     AcGePoint3d newPt;      
  56.     for (int i=0 ; i  < aPts.length() ; i++)   
  57.     {            
  58.      acdbWcs2Ecs(asDblArray(aPts),asDblArray(newPt), asDblArray(norm),Adesk::kFalse);
  59.      newPts.append( newPt);         
  60.     }                                       
  61.     AcDb2dPolyline *pPoly = new AcDb2dPolyline(AcDb::k2dSimplePoly /*poly type*/,
  62.                     newPts /* vertices */,
  63.                     newPts.at(0)[Z] /* elevation */,
  64.                     isClosed /* closed or open*/);   
  65.     pPoly->setNormal(norm);           
  66.     pPoly->setLayer(L"0");   
  67.     pPoly->setColorIndex(5); //blue color  
  68.     postToModelSpace(pPoly);
  69.     pPoly->close();  
  70.    }//if        
  71.   }//for   
  72.   acedSSFree(ss);
  73. }/* end of asktest*/


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-21 20:56 , Processed in 0.352133 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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