//------------------------------------------------------------------------------------------- // // 功能: 将从AcDbObject派生数据库对象保存到实体的扩展词典中 // // 作者:Qin H.X. // // 日期:200709 // // 历史: // 2007.10.08 修改 by Qin H.X. // //---------------------------------------------------------------------------------------------- // - CSCH081.AddAttribute command (do not rename) static void CSCH081AddAttribute(void) { AcDbObjectId dictObjId,eId, attId; AcDbDictionary* pDict; //选择管道(多义线) ads_name en; ads_point pt; if ( acedEntSel(_T("\n选择管道(多义线): "), en, pt)!= RTNORM) { acutPrintf(_T("\n选择失败,退出: ")); return ; } // 打开对象 acdbGetObjectId(eId, en); AcDbEntity * pEnt; acdbOpenObject(pEnt, eId, AcDb::kForWrite); if(!pEnt->isKindOf (AcDbPolyline::desc ())) { acutPrintf(_T("\n选择的不是管道(多义线),退出: " )); return ; } // 判断实体的扩展词典是否创建,如果没有则创建 dictObjId = pEnt->extensionDictionary(); if( dictObjId == AcDbObjectId::kNull ) { pEnt->createExtensionDictionary(); } // 获取实体的扩展词典 dictObjId = pEnt->extensionDictionary(); pEnt->close(); // 判断词典中的属性是否创建 CPipeAttribute* pAttribute; acdbOpenObject(pDict, dictObjId, AcDb::kForWrite); pDict->getAt (_T("属性"),attId); if(attId!= AcDbObjectId::kNull )//如果已经创建则输出数据 { acdbOpenObject(pAttribute, attId, AcDb::kForRead); acutPrintf(_T("\n管径:%4.2f " ),pAttribute->m_dRadius); acutPrintf(_T("\n壁厚:%4.2f " ),pAttribute->m_dThickness ); acutPrintf(_T("\n埋深:%4.2f " ),pAttribute->m_dDeep ); acutPrintf(_T("\n材质:%s " ),pAttribute->m_cMaterial ); } else { //没有则创建属性 pAttribute = new CPipeAttribute(); pDict->setAt(_T("属性"), pAttribute, attId); } //关闭对象 pDict->close(); pAttribute->close(); }
Acad::ErrorStatus CZhfPalette::Wblock(AcDbDatabase*& pDbFrom, AcDbDatabase*& pDbTo, /*const AcGePoint3d& pt_3d_base,*/ const AcGeMatrix3d & xform) { Acad::ErrorStatus es ; AcDbObjectIdArray objIdsOut; AcDbBlockTable* pBT = NULL ; pDbFrom->getBlockTable(pBT, AcDb::kForRead); AcDbBlockTableRecord* pBTR = NULL; es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForRead); pBT->close(); AcDbBlockTableRecordIterator* pIT; es = pBTR->newIterator(pIT) ; for (; !pIT->done(); pIT->step()) { AcDbEntity* pEnt = NULL ; if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForRead)) { // if (!pEnt->isKindOf(AcDbAttributeDefinition::desc())) // { AcDbObjectId objId; if (Acad::eOk == pIT->getEntityId(objId)) { objIdsOut.append(objId); } // } pEnt->close() ; } } delete pIT; pBTR->close(); if (!objIdsOut.isEmpty()) { for (int i=0; i<objIdsOut.length(); i++) { AcDbObjectId objId = objIdsOut.at(i); AcDbEntity *pEnt = NULL ; if(Acad::eOk==acdbOpenAcDbEntity(pEnt,objId, AcDb::kForRead)) { AcDbObjectId objIdDic ; if ((objIdDic = pEnt->extensionDictionary())!= AcDbObjectId::kNull) { AcDbDictionary *pDict = NULL; if (Acad::eOk==acdbOpenObject(pDict, objIdDic, AcDb::kForWrite)) { pDict->setTreatElementsAsHard(Adesk::kTrue); pDict->close(); } } pEnt->close() ; } } AcDbDatabase *pTempDb ; es = pDbFrom->wblock( pTempDb, objIdsOut, AcGePoint3d::kOrigin ) ; if (Acad::eOk != es ) { acedAlert( _T("wblock failed!") ); return es ; } es = pDbTo->insert( xform, pTempDb ) ; if (Acad::eOk != es) acedAlert( _T("insert failed!" )); if (pTempDb) { delete pTempDb; pTempDb = NULL ; } } else { acutPrintf(_T("\nNo entities found in model space of DWG")); } return es ; }