C++ ARX CAD二次开发实体操作

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yunyouxy/article/details/83042031

得到选中的实体,修改实体如等分线段
AcGeVector3d是点阵的集合,通过等分点的差集得到。
新的点可以通过点与点阵相差得到。

static void ArxProject2partLine(void)
{
    ads_name entName;
    ads_point pt;
    acedEntSel( _T("\n选择:"),entName,pt);//得到选中的实体
    AcDbObjectId ObjId;//得到实体ID
    if( acdbGetObjectId(ObjId,entName) != Acad::eOk )//如果没有选中的实体则返回
    {
        acutPrintf( _T("\nno"));
        return;
    }
    AcDbEntity* pEnt;//得到实体
    if( acdbOpenObject(pEnt,ObjId,AcDb::kForRead) == Acad::eOk)
    {
        acutPrintf( _T("\nok"));
        AcDbLine* pLine = (AcDbLine* )pEnt;//强制转换
        AcGePoint3d ptStart = pLine->startPoint();//得到起点
        AcGePoint3d ptEnd = pLine->endPoint();
        pEnt->close();
        //根据点和线的方向生成点组,绘制线段
        int nPart = 5;//五等分
        AcGeVector3d Vect = (ptEnd - ptStart)/nPart;//矩阵,点与点的差集平分可得到
        for (int n=0; n<nPart; n++)
        {
            AcDbObjectId ObjIdNew;
            MakeLine(ptStart+n*Vect,ptStart+(n+1)*Vect,ObjIdNew);//等分线段的方法
        }
        //将选中的线段删除,
        if( acdbOpenObject(pEnt,ObjId,AcDb::kForWrite) == Acad::eOk )
        {
            pEnt->erase();
            pEnt->close();
        }
    }
}
**将实体添加到数据库**
static Acad::ErrorStatus AddToDb(AcDbEntity* ent, AcDbObjectId& objId)
{    
    Acad::ErrorStatus      es;
    AcDbBlockTable*        pBlockTable;
    AcDbBlockTableRecord*  pSpaceRecord;
    if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))
        != Acad::eOk) {
            return es;
    }
    if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, 
        pSpaceRecord,
        AcDb::kForWrite)) != Acad::eOk) {
            return es;
    }
    if ((es = pBlockTable->close()) != Acad::eOk) {
        return es;
    }
    if ((es = pSpaceRecord->appendAcDbEntity(objId, ent)) != Acad::eOk) {
        return es;
    }
    return pSpaceRecord->close();
}
  static void MakeLine(AcGePoint3d ptStart,AcGePoint3d ptEnd,AcDbObjectId lineId)
    {
        AcDbLine *pLine = new AcDbLine(ptStart,ptEnd);
        if(AddToDb(pLine,lineId)!=Acad::eOk)//传入指针,传出id
            AfxMessageBox( _T("加入实体到数据库失败!"));
        pLine->close();
    }
展开阅读全文

没有更多推荐了,返回首页