TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 2024-8-31 15:58 |
---|
签到天数: 89 天 [LV.6]常住居民II
管理员
- 积分
- 3366
|
楼主 |
发表于 2024-5-4 10:54:12
|
显示全部楼层
- #include "StdAfx.h"
- #include "Commands.h"
- #include "Editor.h"
- #include "MathUtil.h"
- #include "Block.h"
- #include "atlstr.h" // 需要这个,否则CString无法识别
- void AddCommands()
- { // 属性块定义
- Editor::AddCommand(采用T("AddAttBlk"), ACRX采用CMD采用MODAL, CreateAttBlk);
- // 插入属性块参照
- Editor::AddCommand(采用T("InsertAtt"), ACRX采用CMD采用MODAL, InsertAtt);
- }
- // 创建属性块定义
- void CreateAttBlk()
- { // 以下为创建块定义代码,同上一节
- AcDbBlockTable *pBlkTbl = NULL;
- acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,
- AcDb::kForWrite);
- AcDbBlockTableRecord *pBlkRcd = new AcDbBlockTableRecord();
- ACHAR blkName[40];
- if(acedGetString(Adesk::kFalse,采用T("\n 请输入块名(空格结束):"),blkName) != RTNORM)
- {
- pBlkTbl->close();
- delete pBlkRcd;
- return;
- }
- pBlkRcd->setName(blkName);
- AcDbObjectId blkDefId;
- pBlkTbl->add(blkDefId, pBlkRcd);
- pBlkTbl->close();
- AcGePoint3d pt1(0, 0, 0), pt2(100, 0, 0), pt3(0, 100, 0);
- AcDbLine *pL采用1 = new AcDbLine(pt1, pt2);
- AcDbLine *pL采用2 = new AcDbLine(pt1, pt3);
- // 创建属性定义对象指针:插入点、tag标签、text的value值、提示信息
- AcDbAttributeDefinition *pAttDef = new AcDbAttributeDefinition(pt3,
- 采用T("20"),
- 采用T("直径"),
- 采用T("请输入直径"));
- // 将对象指针添加进块表记录中,entId返回的是每次添加的对象返回的对象id
- AcDbObjectId entId;
- pBlkRcd->appendAcDbEntity(entId, pL采用1);
- pBlkRcd->appendAcDbEntity(entId, pL采用2);
- // 将属性定义添加进块定义中
- pBlkRcd->appendAcDbEntity(entId, pAttDef);
- pL采用1->close();
- pL采用2->close();
- pAttDef->close();
- pBlkRcd->close();
- }
- // 插入带属性的块参照
- void InsertAtt()
- {
- ACHAR blkName[40];
- if (acedGetString(Adesk::kFalse, 采用T("\n请输入带属性的块参照名:"), blkName) != RTNORM)
- {
- return;
- }
- // 调用函数获得 块定义的对象id
- AcDbObjectId blkDefId = Block::GetBlkDefId(blkName);
- if (blkDefId.isNull())
- {
- acutPrintf(采用T("查无此属性块定义"));
- return;
- }
- ads采用point pt;
- if (acedGetPoint(NULL, 采用T("\n请选择插入点:"), pt) != RTNORM)
- {
- return;
- }
- AcGePoint3d pInsert = asPnt3d(pt);
- // 插入带属性的块参照:块定义对象id、插入点、比例、旋转角度
- AcDbObjectId blkRefId = Block::InsertBlkRefWithAtt(blkDefId,
- pInsert,
- 2,
- MathUtil::PI()/2);
-
- AcDbBlockReference *pBlkRef = NULL;
- if (acdbOpenObject(pBlkRef, blkRefId, AcDb::kForWrite) == Acad::eOk)
- { // 调用函数 修改块参照 的 属性值:块参照、标签名、text的value新值
- Block::SetBlockRefAttribute(pBlkRef, 采用T("直径"), 采用T("600"));
- pBlkRef->close();
- }
- }
复制代码 |
|