天气与日历 切换到窄版

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

CAD ObjectARX 插入块的代码

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]//获得要插入的块名
CString blockname;
m_listctrl.GetLBText(m_listctrl.GetCurSel(),blockname);

//blockname = "CHART-20";

//寻找是否已经定义
AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *pBlkTable;
AcDbObjectId blockId ;
pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);

if(!pBlkTable->has(blockname))
{
pBlkTable->close();
AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse) ;
char dir[MAX_PATH];
GetModuleFileName(NULL,dir,MAX_PATH);

dir[CString(dir).ReverseFind('\')]='\0';
//AfxMessageBox(CString(dir)+"\\survingpack\"+blockname+".dwg");
pDwg->readDwgFile (CString(dir)+"\\survingpack\"+blockname+".dwg") ;

Acad::ErrorStatus es = pCurDb->insert (blockId, blockname, pDwg);//, Adesk::kFalse) ; //
delete pDwg ;
if ( es != Acad::eOk )
{
acutPrintf ("\n插入块错误.") ;
return;
}
}

else
pBlkTable->getAt(blockname, blockId);


BeginEditorCommand();
//ShowWindow(SW_HIDE);
ads_point pt={0,0,0};
int rc=acedGetPoint(NULL,"\n选择插入点:",pt);
if (rc==RTCAN||rc==RTNONE)
{
acutPrintf("\n*取消了插入操作*");
CancelEditorCommand();
return;
}
CompleteEditorCommand();

//---- 设置插入点,旋转角度,比例等等
AcDbBlockReference *pBlkRef =new AcDbBlockReference(AcGePoint3d(pt[0],pt[1],pt[2]),blockId) ;
//pBlkRef->setBlockTableRecord (blockId) ;
pBlkRef->setScaleFactors(AcGeScale3d(m_scale,m_scale,1));
//pBlkRef->setPosition(AcGePoint3d(pt[0],pt[1],pt[2])) ;
pBlkRef->setRotation (m_angle) ;
pBlkRef->setLayer(NULL); //设置图层



//获得模型空间块表记录
AcDbBlockTable *pBlockTable ;
acdbHostApplicationServices()->workingDatabase()->getBlockTable (pBlockTable, AcDb::kForRead) ;
AcDbBlockTableRecord *pBlockTableRecord ;
pBlockTable->getAt (ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite) ;
pBlockTable->close () ;
pBlockTableRecord->appendAcDbEntity(pBlkRef);

//获得属性
AcDbBlockTableRecord *pBlkDefRecord;
acdbOpenObject(pBlkDefRecord, blockId, AcDb::kForRead);

if(pBlkDefRecord->hasAttributeDefinitions())
{
//AcDbObjectIterator* pBlkIterator = pBlkRef->attributeIterator(); //修改

AcDbBlockTableRecordIterator *pIterator;
pBlkDefRecord->newIterator(pIterator);

for(pIterator->start(); !pIterator->done();pIterator->step())
{
AcDbEntity *pEnt;
pIterator->getEntity(pEnt, AcDb::kForRead);
AcDbAttributeDefinition *pAttDef = AcDbAttributeDefinition::cast(pEnt);

if(pAttDef != NULL && !pAttDef->isConstant())
{
AcDbAttribute* pAtt = new AcDbAttribute();
pAtt->setPropertiesFrom(pAttDef);
pAtt->setInvisible( pAttDef->isInvisible() );

pAtt->setHorizontalMode(pAttDef->horizontalMode());
pAtt->setVerticalMode(pAttDef->verticalMode());

AcGePoint3d basePt = pAttDef->alignmentPoint();
basePt[0]+=pt[0];
basePt[1]+=pt[1];
basePt[2]+=pt[2];
pAtt->setAlignmentPoint(basePt);

pAtt->setHeight(pAttDef->height());
pAtt->setTextStyle(pAttDef->textStyle());

pAtt->setTag(pAttDef->tag());
pAtt->setTextString(m_attrib);
pAtt->setFieldLength(25);

pBlkRef->appendAttribute(pAtt);
pAtt->close();
pEnt->close();
}
}
delete pIterator;
}//end if pBlkDefRecord->hasAttributeDefinitions

pBlkDefRecord->close();
pBlockTableRecord->close();
pBlkRef->close();[/code]

 

 

 

 

CAD ObjectARX  插入块的代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-1 11:26 , Processed in 0.167469 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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