ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

ObjectArx-C++实现设计起点里程绘制命令-选中图层中的线路实体

2020-11-20 16:50:58  阅读:300  来源: 互联网

标签:pEnt ads pt C++ mysys ObjectArx 图层 起点


ObjectArx-C++实现设计起点里程绘制命令-选中图层中的线路实体

C++实现设计起点里程绘制命令-选中图层中的线路实体。

主要思路是:

  1. 先选择设计起点公里标插入点。
  2. 打开图层列表,选中线路。
  3. 绘制设计起点公里标。

图例如下:

ObjectArx-C++实现设计起点里程绘制命令-选中图层中的线路实体

示例如下:

  1. 选择设计起点公里标插入点

```c++
//zhaoanan 设计起点绘制
// - zndraw_thdskmpost command (do not rename)
//自定义设计起点绘制
static void zndraw_thdskmpost(void)
{
AcDbDatabase m_pDb = acdbHostApplicationServices()->workingDatabase() ;
CUserSystem
mysys = new CUserSystem();
mysys->m_pDb = m_pDb;
acutPrintf(_T("\n设计起点绘制")) ;
//声明左边插入点
ads_point pt_insert;
AcGePoint3d pt_3d_insert;

ads_name en ;
ads_point pt ;
BOOL bReturn = false ;
while (bReturn == false) 
{
    int iReturn = acedGetPoint(NULL,_T("\n 指定设计起点的插入点:"),pt_insert) ;
    //int iReturn = acedEntSel(_T("\n选择实体对象"), en, pt) ;
    if(iReturn == RTNORM)
    {           
        bReturn = true ;
        pt_3d_insert =asPnt3d(pt_insert);

        acutPrintf(_T("\n设计起点插入点坐标:x坐标为:%f,y坐标为:%f"), pt_3d_insert.x, pt_3d_insert.y);
        //绘制设计起点公里标
        AcDbObjectId objectId = getThdsLineObjectId();
        // TODO: 在此添加设计起点绘制程序代码
        try{
            // 1.创建公里标
            CthDimension *dimensionEntity = new CthDimension();
            // 2.声明组件
            CthComponent *lineCp = new CthComponent();
            // 3.添加直线到组件中
            CthLine *pl = lineCp->addLine( AcGePoint3d(), AcGePoint3d(20, 0, 0));
            //添加文字
            AcGeVector3d offsetText(0, 2, 0);
            CthText *text = lineCp->addText(_T(""), offsetText, 2.5);
            text->setName(_T("里程"));
            text->setRotation(0);
            text->setAlign(AcDbMText::kMiddleLeft);
            //添加里程中的设备名称
            // 4.添加设计起点标注到组件中
            CString content = _T("设计起点");
            AcGeVector3d offsetTextName(25, 2, 0);
            text = lineCp->addText(content , offsetTextName, 2.5);
            text->setName(_T("内容"));
            text->setRotation(0);
            text->setAlign(AcDbMText::kMiddleLeft);
            dimensionEntity->appendComponent(lineCp);
            //添加插入基点
            dimensionEntity->setPosition(pt_3d_insert);
            //添加旋转角度
            dimensionEntity->setRotation(PI/2);
            //设置关联
            dimensionEntity->setDependencyId(objectId);
            // 5.添加线路的objectid到里程实体的DependencyId中
            // 6.保存新对象到数据库中   Save the new object to the database
            //保存当前图层,设置要绘制的图层
            AcDbObjectId ojbIdLayerOld = m_pDb->clayer() ;
            //将里程实体加入到块表记录中
            AcDbObjectId dimensionId = CDwgDatabaseUtil::PostToModelSpace(dimensionEntity, m_pDb);
        }
        catch (CMemoryException* e)
        {
            ads_printf(_T("CMemoryException in zhfzndraw_thdskmpost")) ;
        }
        catch (CFileException* e)
        {
            ads_printf(_T("CFileException in zhfzndraw_thdskmpost")) ;
        }
        catch (CException* e)
        {
            ads_printf(_T("CException in zhfzndraw_thdskmpost")) ;
        }
        catch (_com_error& e)
        {
            CString sBuff = CBlkUtility::GetErrorDescription(e) ;
            ads_printf(sBuff) ;  
        }
        catch (...)
        {
            ads_printf(_T("unknown CException in zhfzndraw_thdskmpost")) ;
        } 
        // return TRUE unless you set the focus to a control
        // 异常: OCX 属性页应返回 FALSE
    }
    else if (iReturn == RTERROR) 
    {
        bReturn = false ;
    }   
    else if (iReturn == RTCAN) {
        bReturn = true ;
    }
}
//保存当前图层,设置要绘制的图层
AcDbObjectId ojbIdLayerOld = m_pDb->clayer() ;

m_pDb->setClayer(ojbIdLayerOld) ; //恢复当前图层
//释放mysys空间
if (mysys != nullptr)
{
    delete mysys;
}

}


2. **打开图层列表,选中线路**

/****/
/-------------------------getThdsLine------------------------------------------/
/*日期:2020-11-19**/
/*
作者:zhaoanan****/
/*函数功能:绘制设计起点公里标**/
/*
输入参数:void****/
/*输出参数:void**/
/*
返回值: 无***/
/****/
static AcDbObjectId getThdsLineObjectId(){
//获取cad数据库对象地址
AcDbDatabase m_pDb = acdbHostApplicationServices()->workingDatabase();
//添加块定义
acutPrintf(_T("\n选择设计起点线路")) ;
//初始化CUserSystem
CUserSystem
mysys = new CUserSystem();
//赋值cad数据库对象地址
mysys->m_pDb = m_pDb;
//声明选择集名称
ads_name en ;
//声明选择集坐标
ads_point pt ;
//设置循环布尔值
BOOL bReturn = false ;
//选择实体对象
while (bReturn == false)
{
//单个选择集
int iReturn = acedEntSel(_T("\n选择线路"), en, pt) ;
//如果选中实体
if(iReturn == RTNORM)
{
AcDbEntity pEnt = NULL ;
//打开选中的实体
if(mysys->OpenAcDbEntity(en, pEnt, AcDb::kForRead))
{
//设置高亮
pEnt->highlight();
acedUpdateDisplay();
//如果选中线路实体
if(pEnt->isKindOf(CthRailLine::desc()))
{
//设置循环布尔值true
bReturn = true ;
//转换选择对象为实体对象
CthRailLine
pCthEnt = CthRailLine::cast(pEnt) ;
//返回实体地址
AcDbObjectId objectId = pCthEnt->id();
//返回之前关闭实体
if(pEnt!=NULL)
{
pEnt->unhighlight() ;
acedUpdateDisplay();
pEnt->close();
}
//返回之前关闭用户操作对象
if(mysys!=NULL)
{
delete mysys;
}
return objectId;
}
else
{
//如果选择的不是本工具支持的实体,重新选择
AfxMessageBox(_T("选择的不是本工具支持的实体!")) ;
//设置循环布尔值false
bReturn = false ;
}
//还原设置高亮
pEnt->unhighlight() ;
acedUpdateDisplay();
}
//关闭实体对象
if(pEnt!=NULL)
{
pEnt->close();
}
}
//其它错误按键
else if (iReturn == RTERROR)
{
bReturn = false ;
}
//按下ctrl+c按键
else if (iReturn == RTCAN) {
bReturn = true ;
}
}
if(mysys!=NULL)
{
delete mysys;
}
//返回空地址
return NULL;
}


3. **AcedCommand命令不能选中图层,修改命令调用方式,直接调用**

//zhaoanan 坡度编辑
DTEntityItem* pEntityItem = g_pGallery->GetCatalogByIndex(pPalette->m_iIndex)->GetEntityItemByIndex(g_pCtrlGsPreview->m_iIndex);
//设计起点需要选中图层中的线路,而acedCommand命令不能选中图层,add by zhao_anan 20201120 begin
if (pEntityItem->GetCommand() == _T("thdskmpost"))
{
zndraw_thdskmpost();
}
//设计起点需要选中图层中的线路,而acedCommand命令不能选中图层,add by zhao_anan 20201120 end
else
{
acedCommand(RTSTR, pEntityItem->GetCommand(), RTNONE);
}



4. 参考意见和网页地址:

   1. 无

标签:pEnt,ads,pt,C++,mysys,ObjectArx,图层,起点
来源: https://blog.51cto.com/zhaoanan/2552828

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有