天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 68|回复: 0

OBJECT ARX 插入块

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
添加块到块表中================
static void TESTaddblkcmd(){

AcDbBlockTable* pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
创建新块
AcDbBlockTableRecord* pBlkTblRcd;
pBlkTblRcd = new AcDbBlockTableRecord();


根据用户的输入设置块表记录的名称
TCHAR blkName[256];


if(acedGetString(Adesk::kFalse,_T("\n输入块名称"),blkName) != RTNORM){

pBlkTbl->close();
delete pBlkTblRcd;
return;
}


pBlkTblRcd->setName(blkName);


将块表记录添加到块表中


AcDbObjectId blkDefId;
pBlkTbl->add(blkDefId,pBlkTblRcd);
pBlkTbl->close();


向块表记录中添加实体
AcGePoint3d ptStart(-10,0,0),ptEnd(10,0,0);
AcDbLine* pLine1 = new AcDbLine(ptStart,ptEnd);
ptStart.set(0,-10,0);
ptEnd.set(0,10,0);
AcDbLine *pLine2 = new AcDbLine(ptStart,ptEnd);


AcGeVector3d vecNormal(0,0,1);
AcDbCircle *pCircle = new AcDbCircle(AcGePoint3d::kOrigin,vecNormal,6);
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId,pLine1);
pBlkTblRcd->appendAcDbEntity(entId,pLine2);
pBlkTblRcd->appendAcDbEntity(entId,pCircle);


关闭实体块表记录


pLine1->close();
pLine2->close();
pCircle->close();
pBlkTblRcd->close();


}


插入块参照
static void TESTaddblkrefcmd(){

获得用户输入的块定义名称
CString strBlkDef;

if(acedGetString(Adesk::kFalse,_T("\n输入块名称\n"),strBlkDef.GetBuffer()) != RTNORM){
return;
}
acutPrintf(strBlkDef);




获得当前数据库的块表
AcDbBlockTable* pBlkTbl;


acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);



查找用户指定的块定义是否存在



if(!pBlkTbl->has(strBlkDef)){
acutPrintf(_T("\n当前图形中未包含块定义"));
pBlkTbl->close();
return;


}


获得用户输入的块参照的插入点
ads_point pt;
if(acedGetPoint(NULL,_T("\n输入块参照的插入点"),pt) != RTNORM){

pBlkTbl->close();
return;
}


AcGePoint3d ptInsert = asPnt3d(pt);


获得用户制定的块表记录
AcDbObjectId blkDefId;
pBlkTbl->getAt(strBlkDef,blkDefId);


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


将块参照添加到模型空间


AcDbBlockTableRecord* pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkTblRcd,AcDb::kForWrite);

AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId,pBlkRef);


关闭数据库对象
pBlkTbl->close();
pBlkTblRcd->close();
pBlkTbl->close();
}


===================================================插入带有属性的块定义


static void TESTaddblk2cmd(){


获得当前图形的数据库块表
AcDbBlockTable* pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
创建新的块表记录


AcDbBlockTableRecord* pBlkTblRcd;


pBlkTblRcd = new AcDbBlockTableRecord();


根据用户的输入设置块表记录的名称


CString blkName;
if(acedGetString(Adesk::kFalse,_T("\n输入块表记录名称:"),blkName.GetBuffer()) != RTNORM){

pBlkTbl->close();
delete pBlkTblRcd;
return;
}
pBlkTblRcd->setName(blkName);


将块表记录添加到块表中
AcDbObjectId blkDefId;
pBlkTbl->add(blkDefId,pBlkTblRcd);
pBlkTbl->close();




向块表记录添加实体
AcGePoint3d ptStart(-10,0,0);
AcGePoint3d ptEnd(10,0,0);


AcDbLine* pLine1 = new AcDbLine(ptStart,ptEnd);
ptStart.set(0,-10,0);
ptEnd.set(0,10,0);
AcDbLine* pLine2 = new AcDbLine(ptStart,ptEnd);
AcGeVector3d vecNormal(0,0,1);
AcDbCircle* pCircle = new AcDbCircle(AcGePoint3d::kOrigin,vecNormal,6);
创建一个属性,输入直径
AcDbAttributeDefinition* pAttDef = new AcDbAttributeDefinition(ptEnd,_T("20"),_T("直径"),_T("输入直径"));
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId,pLine1);
pBlkTblRcd->appendAcDbEntity(entId,pLine2);
pBlkTblRcd->appendAcDbEntity(entId,pCircle);
pBlkTblRcd->appendAcDbEntity(entId,pAttDef);


关闭实体和块表记录
pLine1->close();
pLine2->close();
pCircle->close();
pAttDef->close();
pBlkTblRcd->close();
}

 

 

 

 

OBJECT ARX 插入块
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 12:29 , Processed in 0.119138 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表