今天接到一个文件,图形检测出现了无法判断的错误。看了一下图形,有点特别,使用pe指令显示该对象与UCS不平行,使用li指令显示:
LWPOLYLINE 图层: 功能分区
空间: 模型空间
句柄 = 23C1F3
闭合
固定宽度 0
相对于 UCS 的拉伸方向:
X= 0 Y= 0 Z= -1
面积 109295267
周长 42293
。。。。。。
跟踪代码后发现,在调用getPointAt获取顶点坐标时,返回的结果非常奇怪,仔细检查后,发现我在一些地方调用getPointAt这个方法时,传入了一个AcGePoint2d的变量用于获取坐标,问题正是出在这个AcGePoint2d上。查了一下帮助:
Acad::ErrorStatus getPointAt(unsigned int unnamed,AcGePoint3d& pt) const;
unnamed | Input the index (0 based) of the vertex |
pt | Output copy of point data at vertex index |
This function sets pt to the 3D location of the vertex index in World Coordinates.
Returns Acad::eOk if successful, or Acad::eInvalidIndex if index is not valid for the polyline.
Acad::ErrorStatus getPointAt(unsigned int index,AcGePoint2d& pt) const;
index | Input the index (0 based) of the vertex |
pt | Output copy of point data at vertex index |
This function sets pt to the 2D location of the vertex index in the polyline's own ojbect coordinate system (OCS).
Returns Acad::eOk if successful, or Acad::eInvalidIndex if index is not valid for the polyline.
终于找到问题所在了。
写代码的时候图方便(因为有些地方使用了不少类似AcGeLineSeg2d一类的对象),因此在使用变量时使用了AcGePoint2d,而不是AcGePoint3d,在尝试编译发现通过后就没有再管了。在多数情况下,传入AcGePoint2d也没问题,但在一些特殊情况下,问题就出现了。把相关的地方都改过来,问题解决了。
嗯,看来以后还是要更小心一些。自己以后设计函数重载的时候,也要尽量避免此类问题。这个陷阱确实不容易发现。