zoukankan      html  css  js  c++  java
  • 向当前模型空间中插入带属性的块定义

    //其中blockName为插入的块表的名称, ptInsert为块表指定的插入点

    void InsertBlkToSpace(CString blockName, AcGePoint3d ptInsert)
    {
    //获得当前的数据库的块表
    AcDbBlockTable *pBlkTab;
    acdbHostApplicationServices()->workingDatabase()
    ->getBlockTable(pBlkTab, ZcDb::kForWrite);

    //判断插入的块定义是否存在
    if (!pBlkTab->has(blockName))
    {
    acutPrintf(_T(" 当前图纸中不包含此块表!"));
    pBlkTab->close();
    return;
    }
    //获得用户指定的块表记录
    AcDbObjectId blkDefId;
    pBlkTab->getAt(blockName, blkDefId);

    //创建一个块参照对象
    AcDbBlockReference *pBlkRef = new AcDbBlockReference(ptInsert, blkDefId);

    //将块参照插入到模型空间中
    AcDbBlockTableRecord *pBlkTabRcd;
    pBlkTab->getAt(ACDB_MODEL_SPACE, pBlkTabRcd, ZcDb::kForWrite);
    pBlkTab->close();
    AcDbObjectId objId;
    pBlkTabRcd->appendZcDbEntity(objId, pBlkRef);

    //判断指定的块表记录是否包含属性
    AcDbBlockTableRecord *pBlkDefRcd;
    acdbOpenObject(pBlkDefRcd, blkDefId, ZcDb::kForRead);
    if (pBlkDefRcd->hasAttributeDefinitions())
    {
    //创建一个遍历器用来遍历所有的属性
    AcDbBlockTableRecordIterator *pItr;
    pBlkDefRcd->newIterator(pItr);
    AcDbEntity *pEnt;

    //遍历块定义属性
    for (pItr->start(); !pItr->done(); pItr->step())
    {
    pItr->getEntity(pEnt, ZcDb::kForWrite);

    //检查是否是属性定义
    AcDbAttributeDefinition *pAttDef;
    pAttDef = AcDbAttributeDefinition::cast(pEnt);
    if (pAttDef != NULL)
    {
    AcDbAttribute *pAtt = new AcDbAttribute();
    //从属性定义获取属性对象的对象特征
    pAtt->setPropertiesFrom(pAttDef);
    //设置属性对象的其他特征
    pAtt->setInvisible(pAttDef->isInvisible());//属性是否不可见
    //设置属性对象插入点,根据块参照的插入点做相应的位移操作
    AcGePoint3d basePt = pAttDef->position();
    basePt += pBlkRef->position().asVector();
    pAtt->setPosition(basePt);
    pAtt->setHeight(pAttDef->height());//设置高
    pAtt->setRotation(pAttDef->rotation());//设置旋转角度

    //获取属性对象的Tag、 Prompt和TestString
    TCHAR *str;
    str = pAttDef->tag();
    pAtt->setTag(str);
    free(str);
    pAtt->setFieldLength(pAttDef->fieldLength());
    str = pAttDef->textString();
    pAtt->setTextString(str);
    free(str);

    //向块参照中追加属性对象
    pBlkRef->appendAttribute(pAtt);
    pAtt->close();
    }
    pEnt->close();
    }
    delete pItr;
    }
    //关闭数据库
    pBlkRef->close();
    pBlkDefRcd->close();
    pBlkTabRcd->close();
    }

  • 相关阅读:
    使用Node获取百度最新疫情信息,本地保存为json文件
    js实现将字符串首字母转换成大写
    egg实现登录鉴权(八):sequelize联表查询
    egg实现登录鉴权(七):权限管理
    egg实现登录鉴权(六):角色树的CRUD操作
    egg实现登录鉴权(五):mysql表中存储树形结构数据
    egg实现登录鉴权(四):人员新增和密码修改
    egg实现登录鉴权(三):密码的md5加密及验证
    egg实现登录鉴权(二):连接数据库(mysql)
    egg实现登录鉴权(一):生成token
  • 原文地址:https://www.cnblogs.com/pengjun-shanghai/p/4788159.html
Copyright © 2011-2022 走看看