- UID
- 83430
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-9-30
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2006-4-29 11:04:29
|
显示全部楼层
好了
放到后面也不行啊
这样就可以了,
void CAddBlock::OnOK()
{
CDialog::OnOK();
//获得要插入的块名
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->position();
basePt[0]+=pt[0];
basePt[1]+=pt[1];
basePt[2]+=pt[2];
pAtt->setPosition(basePt);
*/
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();
} |
|