calmman 发表于 2004-12-17 20:42:00

奇怪了,高手指点一下,谢谢啦

ads_name entName;
ads_point ptres;
if( acedEntSel( "\nPlease pick a polyline:", entName, ptres ) != RTNORM )
{
    acdbFail( "\nFail to select!" );
    return;
}

AcDb2dPolyline* pPolyline = NULL;
AcDbObjectId objId;

if( acdbGetObjectId( objId, entName ) != Acad::eOk || !objId.isValid() )
{
    acdbFail( "\nCan not get object id of selected object!" );
    return;
}
// 不是派生类吗?这里为什么不能获取对象的指针
if( acdbOpenObject( pPolyline, objId,   AcDb::kForRead ) != Acad::eOk
            || pPolyline == NULL
            || !pPolyline->isKindOf( AcDb2dPolyline::desc() )
    )
{
    acdbFail( "\nCan not open open selected object!" );
    return;
}

王咣生 发表于 2004-12-17 22:54:00

回复

我试了,没问题,



确定你选择的是'POLYLINE', 而不是LWPOLYLINE


AcDb2dPolyline是POLYLINE类型;


AcDbPolyline是LWPOLYLINE类型.


注意适时关闭对象


        pPolyline->close();

calmman 发表于 2004-12-18 13:13:00

谢谢版主老大,不过还是不行啊完整的源代码如下:void IteraterPolyline()
{
ads_name entName;
ads_point ptres;
if( acedEntSel( "\nPlease pick a polyline:", entName, ptres ) != RTNORM )
{
    acdbFail( "\nFail to select!" );
    return;
}

AcDb2dPolyline* pPolyline = NULL;
AcDbObjectId objId;

if( acdbGetObjectId( objId, entName ) != Acad::eOk || !objId.isValid() )
{
    acdbFail( "\nCan not get object id of selected object!" );
    return;
}
// 不是派生类吗?这里为什么不能获取对象的指针
if( acdbOpenObject( pPolyline, objId,   AcDb::kForRead ) != Acad::eOk
            || pPolyline == NULL
            || !pPolyline->isKindOf( AcDb2dPolyline::desc() )
    )
{
    acdbFail( "\nCan not open open selected object!" );
    return;
}AcDb2dVertex* pVertex = NULL;
AcGePoint3d location;
AcDbObjectId vertexId;

AcDbObjectIterator *pVecIterator = pPolyline->vertexIterator();for( int vertexNum = 0; !pVecIterator->done(); pVecIterator->step(), vertexNum++ )
{
    vertexId = pVecIterator->objectId();
    acdbOpenObject( pVertex, vertexId, AcDb::kForRead );
    location = pVertex->position();
    acutPrintf( "\nVertex %d:X[%0.3f], Y[%0.3f], Z[%0.3f]", location, location, location );
    pVertex->close();
}pPolyline->close();
delete pVecIterator;
}我用pl命令在CAD里绘制了一些多段线,不过点选后检测内存发现打开对象的时候pPolyline指针被赋为空,如果我采用 AcDbEntity* pEnt来打开对象则能正常打开.当然,后面对于多段线的操作也就谈不上了.还请版主大哥多多指教,谢谢了!

王咣生 发表于 2004-12-18 13:48:00

reply

用acedEntSel选择到实体,如果成功entName被赋值;<BR>用acdbGetObjectId取得objId;


但是你没有判断你选择的实体是AcDb2dPolyline,你就直接用<BR>AcDb2dPolyline* pPolyline = NULL;<BR>acdbOpenObject(pPolyline, objId, AcDb::kForRead);


* 用pl命令画的线可能是AcDbPolyline("LWPolyline")<BR>       或者AcDb2dPolyline("Polyline");


       系统变量PLINETYPE=0时画AcDb2dPolyline,<BR>                                                                       PLINETYPE=2(or 1)时画AcDbPolyline.

calmman 发表于 2004-12-19 00:58:00

谢谢版主,果然是你说的这个问题。不过新的问题又出现了下面程序打印多段线的顶点,可是能够获取ID和迭代器(从迭代的数量上来看,是没有错误的)却不能够打开顶点对象,晕了,这是怎么回事?代码片断如下:// 作了简单多段线到2d多段线的转化
if( pPolyline->convertTo( p2dPolyline, FALSE ) != Acad::eOk )
{
    acutPrintf( "\nCan not convert simple polyline to 2dpolyline!" );
    return;
}AcDb2dVertex* pVertex = NULL;
AcGePoint3d location;
AcDbObjectId vertexId;

AcDbObjectIterator *pVecIterator = p2dPolyline->vertexIterator();for( int vertexNum = 0; !pVecIterator->done(); pVecIterator->step(), vertexNum++ )
{
    vertexId = pVecIterator->objectId();
    // 能够成功的获取顶点的ID,但是打不开顶点对象
    // 我尝试着用其他的顶点类型来打开,可是依然不行
    // 还请高手指点迷津,谢谢阿
    if( acdbOpenObject( pVertex, vertexId, AcDb::kForRead ) != Acad::eOk )
    {
      acutPrintf( "\nCan not open vertex object of selected polyline!" );
      return;
    }    location = pVertex->position();
    acutPrintf( "\nVertex %d:X[%0.3f], Y[%0.3f], Z[%0.3f]", location, location, location );
    pVertex->close();
}
页: [1]
查看完整版本: 奇怪了,高手指点一下,谢谢啦