void insertblock() { AcGePoint3d pt1; CString blk_name="testblock"; CString Fname=blk_name+".dwg"; char sFileName[160]; const char *dwgName=(LPSTR)(LPCTSTR)Fname; acedFindFile(dwgName,sFileName); AcDbDatabase *pNewDb =new AcDbDatabase(Adesk::kFalse); int es=pNewDb->readDwgFile(sFileName ,_SH_DENYNO,false); if (es!=Acad::eOk) { acutPrintf("\nThe file %s cannot be opend",sFileName); return; } ///////////////////////////////////////////////////////////////// AcDbDatabase *pDb; pDb =acdbHostApplicationServices ()->workingDatabase () ; AcDbObjectId blockId; if((es=pDb->insert(blockId, blk_name,pNewDb, true))==Acad::eOk) { acutPrintf("\ninsert ok\n"); } else { AfxMessageBox("Insert failed"); delete pNewDb; return; } if(RTNORM!=acedGetPoint(NULL,"\n请输入插入点:",asDblArray(pt1))) { return; } AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pBlockTableRecord; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->getAt(blk_name, blockId); pBlockTable->add(blockId,pBlockTableRecord); pBlockTable->close();
AcDbBlockReference *pBlkRef = new AcDbBlockReference; pBlkRef->setBlockTableRecord(blockId);//指向blockId; pBlkRef->setPosition(pt1);//设定位置 pBlkRef->setRotation(0);//设定转角 AcDbObjectId newEntId; pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef); pBlockTableRecord->close(); pBlkRef->close(); //////////////////////////////////////////////////////////////////////////// AcDbBlockTableRecord *pblockrec; acdbOpenObject(pblockrec,blockId,AcDb::kForWrite); AcDbAttributeDefinition *pAttriDef=new AcDbAttributeDefinition; pAttriDef->setPrompt("aa"); pAttriDef->setTextString("a"); pAttriDef->setTag("Tag"); pAttriDef->setInvisible(Adesk::kFalse); pAttriDef->setPreset(Adesk::kFalse); pAttriDef->setConstant(Adesk::kFalse); pblockrec->appendAcDbEntity(newEntId,pAttriDef); pAttriDef->close(); pblockrec->close();
} 插入一个外部块,然后给这个块加块属性,但是属性却看不到,炸开却有块属性在。这是什么问题? |