Acad::ErrorStatus CTwArxDictionary::CreateSubDictionaryID( IN const AcDbObjectId& IdRoot, IN const CString& strKey, OUT AcDbObjectId& IdSubDic, IN AcRxClass* pRxObjType /*= AcDbDictionary::desc() */ ) const { if( pRxObjType == NULL ) return Acad::eNullObjectPointer; Acad::ErrorStatus es = Acad::eOk; AcDbDictionary* pDicRoot = NULL; AcDbDatabase* pWdb = acdbCurDwg(); if( IdRoot.isNull() ) es = pWdb->getNamedObjectsDictionary( pDicRoot, AcDb::kForRead ); else es = acdbOpenObject( pDicRoot, IdRoot, AcDb::kForRead ); if( es != Acad::eOk ) return es; if( pDicRoot->has(strKey) ) { pDicRoot->getAt( strKey, IdSubDic ); pDicRoot->close(); return es; } pDicRoot->upgradeOpen(); AcDbObject* pObj = (AcDbObject*)pRxObjType->create(); es = pDicRoot->setAt( strKey, pObj, IdSubDic ); pObj->close(); pDicRoot->close(); return es; }
void Additional_Class::SetLayerIsOff( CString strLayerName) { AcDbLayerTable *pLayTbl = NULL; acdbCurDwg()->getLayerTable(pLayTbl, AcDb::kForWrite); if(!pLayTbl->has(strLayerName)) { pLayTbl->close(); //该图层不存在 return; } AcDbLayerTableRecord *pLayTblRec = NULL; AcDbObjectId objId; pLayTbl->getAt(strLayerName, pLayTblRec, AcDb::kForWrite); pLayTbl->close(); //pLayTblRec->isInUse(); if (pLayTblRec==NULL) { return; } bool tempBool = pLayTblRec->isOff(); if (tempBool == false) { pLayTblRec->setIsOff(true); } else { pLayTblRec->setIsOff(false); } pLayTblRec->close(); return; }
//把一层设置为OFF or ON void CArxHelper::SetOneLayer(const TCHAR *name,int flag,bool YN) //flag 1:isoff 2:isfrozen 3:islocked { AcDbLayerTable *pLayerTable; acdbCurDwg()->getLayerTable(pLayerTable,AcDb::kForRead); if(!pLayerTable->has(name)) { pLayerTable->close(); return; } AcDbObjectId id; pLayerTable->getAt(name,id); AcDbLayerTableRecord *pLayerTableRecord; acdbOpenObject(pLayerTableRecord,id,AcDb::kForWrite); switch(flag) { case 1: pLayerTableRecord->setIsOff(YN); break; case 2: pLayerTableRecord->setIsFrozen(YN); break; case 3: pLayerTableRecord->setIsLocked(YN); break; } pLayerTableRecord->close(); pLayerTable->close(); }
AcDbObjectId CArxHelper::SetLayer(TCHAR* layerName) { AcDbObjectId layerId = NULL; AcDbLayerTable *pLayerTbl; acdbCurDwg()->getLayerTable(pLayerTbl,AcDb::kForWrite); AcDbLayerTableIterator *pItr; pLayerTbl->newIterator(pItr); for(;!pItr->done();pItr->step()) { AcDbLayerTableRecord *pLayer; pItr->getRecord(pLayer,AcDb::kForRead); TCHAR *str=NULL; pLayer->getName(str); if(_tcscmp(layerName,str)==0) layerId=pLayer->id(); if(str!=NULL) delete []str; pLayer->close(); if(layerId!=NULL) break; } delete pItr; pItr = NULL; if(layerId==NULL) { AcDbLayerTableRecord *pLayerTblRcd=new AcDbLayerTableRecord(); Acad::ErrorStatus es = pLayerTblRcd->setName(layerName); if (es != Acad::eOk) pLayerTblRcd->setName(_T("0")); pLayerTbl->add(layerId,pLayerTblRcd); pLayerTblRcd->close(); } pLayerTbl->close(); acdbCurDwg() ->setClayer(layerId); return layerId; }
AcDbObjectId CArxHelper::GetBlockId(const CString& strName) { AcDbBlockTable* pBlockTable = NULL; acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead); AcDbBlockTableRecord* pBTR = NULL; AcDbObjectId blockId = AcDbObjectId::kNull; if (pBlockTable) { pBlockTable->getAt(strName, blockId, AcDb::kForRead); pBlockTable->close(); } return blockId; }
Acad::ErrorStatus CTwArxDictionary::GetSubDictionaryID( IN const AcDbObjectId& IdRoot, IN const CString& strKey, AcDbObjectId& IdSub, AcDbDatabase* pCurDB ) const { Acad::ErrorStatus es = Acad::eOk; AcDbDictionary* pDicRoot = NULL; AcDbDatabase* pWdb = pCurDB; if( pWdb == NULL ) pWdb = acdbCurDwg(); if( IdRoot.isNull() ) es = pWdb->getNamedObjectsDictionary( pDicRoot, AcDb::kForRead ); else es = acdbOpenObject( pDicRoot, IdRoot, AcDb::kForRead ); if( pDicRoot == NULL ) return es; pDicRoot->close(); es = pDicRoot->getAt( strKey, IdSub ); return es; }
BOOL ElevationObjectPick::PickElevationObjects( OUT vector<AcDbObjectId>& vIsoHeight, OUT vector<AcDbObjectId>& vElePoint ) const { AcDbObjectId IdSpace = acdbCurDwg()->currentSpaceId(); AcDbBlockTableRecord* pBtr = NULL; acdbOpenObject( pBtr, IdSpace, AcDb::kForRead ); if( pBtr == NULL ) return FALSE; pBtr->close(); AcDbBlockTableRecordIterator* pIte = NULL; pBtr->newIterator( pIte ); if( pIte == NULL ) return FALSE; //遍历当前所有对象 for ( pIte->start(); !pIte->done(); pIte->step() ) { AcDbObjectId Id; pIte->getEntityId( Id ); } return FALSE; }
void setInsertLayer() { // Iterate through Model Space to find every instance of the EMPLOYEE block // When found, change its layer to "USER" Acad::ErrorStatus es; AcDbBlockTable* pBlockTbl; AcDbBlockTableRecord* pMS; if ((es = acdbCurDwg()->getBlockTable(pBlockTbl, AcDb::kForRead)) == Acad::eOk) { //Get the Model Space record and open it for read. if ((es = pBlockTbl->getAt(ACDB_MODEL_SPACE, pMS, AcDb::kForWrite)) != Acad::eOk) { acrx_abort("\nCouldn't get Model Space! Drawing corrupt.\n"); } pBlockTbl->close(); } // declare the appropriate iterator // get the iterator from the object to be iterated through // in this case, the Model Space block table record will provide the iterator // start at the beginning of the record and skip deleted entities AcDbBlockTableRecordIterator* pBtrIter; if ((es = pMS->newIterator(pBtrIter)) != Acad::eOk) { acutPrintf("\nCouldn't create Model Space iterator: %s", acadErrorStatusText(es)); return; } char* blockName; AcDbEntity* pEnt; AcDbBlockTableRecord* pCurEntBlock; AcDbObjectId blockId; for (pBtrIter->start(); !pBtrIter->done(); pBtrIter->step()) { // first open each entity for read, just to check its class // if it's what we want, we can upgrade open later // Don't bother with erased entities if ((es = pBtrIter->getEntity(pEnt, AcDb::kForRead)) != Acad::eOk) { acutPrintf("\nCouldn't open entity: %s", acadErrorStatusText(es)); continue; } // check isf the entity is an instance of type AcDbBlockReference if (pEnt->isA() != AcDbBlockReference::desc()) { pEnt->close(); continue; } // get the insert's block table record and compare its name // to make sure we've got the right block. If so, set the layer blockId = (AcDbBlockReference::cast(pEnt))->blockTableRecord(); if (acdbOpenObject((AcDbObject*&)pCurEntBlock, blockId, AcDb::kForRead) == Acad::eOk) { pCurEntBlock->getName(blockName); if (strcmp(blockName, "EMPLOYEE") == 0) { if (pEnt->upgradeOpen() == Acad::eOk) // setLayer also has an overload that takes a layer ID // but to avoid global variables we specify the layer name pEnt->setLayer("USER"); } pCurEntBlock->close(); acdbFree ( blockName ); } pEnt->close(); } // delete, rather than close, the iterator object delete pBtrIter; pMS->close(); return; }
Acad::ErrorStatus createBlockRecord(/*[in]*/const char* name) { AcDbCircle* pFace = NULL; AcDbCircle* pLeftEye = NULL; AcDbCircle* pRightEye = NULL; AcDbArc* pMouth = NULL; AcDbBlockTable* pBlockTable = NULL; AcDbBlockTableRecord* pBlockTableRecord = NULL; try { // First, check if a block of the same name already exists // by verifying in the current database block table. // // Open the block table for read // ARXOK(acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead)); if (pBlockTable->has(name) == Adesk::kTrue) { pBlockTable->close(); return Acad::eDuplicateKey; } // Now we know the block does not exist, so we create it // using the name passed in. // pBlockTableRecord = new AcDbBlockTableRecord(); if (!pBlockTableRecord) throw Acad::eOutOfMemory; pBlockTableRecord->setName(name); // To keep it simple, we use the origin for the insertion point // pBlockTableRecord->setOrigin(AcGePoint3d::kOrigin); // Open the block table for write // since we are adding a new block definition // ARXOK(pBlockTable->upgradeOpen()); // Add the new block table record to the block table. // For now, the block table record is empty. // ARXOK(pBlockTable->add(pBlockTableRecord)); pBlockTable->close(); pBlockTable = NULL; // Now the block table record is in the database, but is empty // (has no sub-entity). // Note that after having been added to the database, an object or an entity // is implicitely opened for write. // // So we create the sub entities to append to the block // which will represent a "happy face": // the block should consist of a round yellow face (circle) // two blue eyes (circles) and a red mouth (arc) // pFace = new AcDbCircle(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, 1.0); pLeftEye = new AcDbCircle(AcGePoint3d(0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1); pRightEye = new AcDbCircle(AcGePoint3d(-0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1); pMouth = new AcDbArc(AcGePoint3d(0, 0.5, 0), 1.0, PI + (PI * 0.3), PI + (PI * 0.7)); if (!pFace || !pLeftEye || !pRightEye || !pMouth) { delete pFace; delete pLeftEye; delete pRightEye; delete pMouth; throw Acad::eOutOfMemory; } // Set the color property. // pFace->setColorIndex(2); pLeftEye->setColorIndex(5); pRightEye->setColorIndex(5); pMouth->setColorIndex(1); ARXOK(pBlockTableRecord->appendAcDbEntity(pFace)); ARXOK(pBlockTableRecord->appendAcDbEntity(pLeftEye)); ARXOK(pBlockTableRecord->appendAcDbEntity(pRightEye)); ARXOK(pBlockTableRecord->appendAcDbEntity(pMouth)); pFace->close(); pLeftEye->close(); pRightEye->close(); pMouth->close(); pBlockTableRecord->close(); return Acad::eOk; } catch(const Acad::ErrorStatus es) { if(pBlockTable) pBlockTable->close(); if(pBlockTableRecord) // if the id is NULL, it means that the object // is not in the database and that we can sefely delete it if(pBlockTableRecord->objectId() == AcDbObjectId::kNull) delete pBlockTableRecord; else { pBlockTableRecord->erase(); pBlockTableRecord->close(); } if(pFace) if(pFace->objectId() == AcDbObjectId::kNull) delete pFace; else pFace->close(); if(pLeftEye) if(pLeftEye->objectId() == AcDbObjectId::kNull) delete pLeftEye; else pLeftEye->close(); if(pRightEye) if(pRightEye->objectId() == AcDbObjectId::kNull) delete pRightEye; else pRightEye->close(); if(pMouth) if(pMouth->objectId() == AcDbObjectId::kNull) delete pMouth; else pMouth->close(); return es; } }
//--------------------------------------------------------------------------------------- // // 功能: 路线绘制回调函数 // // 输入参数: // AeccDisplayOrientation &viewMode // IAeccAlignment *pAlign // IAcadBlock *pAnonymousBlock // // 返回值:bool // // 作 者: // // 日期: 2007/08 // // 修改记录:无 // //--------------------------------------------------------------------------------------- bool customAlignmentDraw(const AeccDisplayOrientation &viewMode, IAeccAlignment *pAlign, IAcadBlock *pAnonymousBlock ) { AcDbBlockTableRecord* blkRec; CString strName; CComBSTR bstrName; pAnonymousBlock->get_Name( &bstrName); strName = bstrName; AcDbBlockTable* blkTbl; AcDbDatabase* pDb = acdbCurDwg(); Acad::ErrorStatus es = pDb->getSymbolTable(blkTbl, AcDb::kForRead); if (es != Acad::eOk){ return false; } //// open named block es = blkTbl->getAt(strName, blkRec, AcDb::kForWrite); acutPrintf(_T("\nget block")); if (es != Acad::eOk) { blkTbl->close(); // doesn't need to be open anymore return false; } blkTbl->close(); // doesn't need to be open anymore CComQIPtr <IAeccAlignmentEntities> pAlignEntities; CComQIPtr <IAeccAlignmentEntity> pAlignEnt; CComQIPtr<IAeccAlignmentArc> pAlignArc; long iCount; pAlign->get_Entities(&pAlignEntities); if (pAlignEntities != NULL) { pAlignEntities->get_Count(&iCount); for (long i = 0; i < iCount; i++) { pAlignEnt.Release(); pAlignEntities->Item(_variant_t(i), &pAlignEnt); pAlignArc.Release(); pAlignArc = pAlignEnt; if (pAlignArc != NULL) { double radius; pAlignArc->get_Radius(&radius); //acutPrintf(_T("\nRadius: %f", radius)); if (radius < 200) { double x; double y; double dStart; double dEnd; pAlignArc->get_StartingStation(&dStart); pAlignArc->get_EndingStation(&dEnd); for (double delta = dStart; delta < dEnd; delta += 3.0) { pAlign->PointLocation(delta, 0.0, &x, &y); AcGePoint3d pt(x,y,0); AcDbCircle* cir = new AcDbCircle(pt, AcGeVector3d::kZAxis, 5.0); cir->setColorIndex (1, Adesk::kTrue); blkRec->appendAcDbEntity(cir); cir->close(); } } } } } blkRec->close(); return (true) ; }
AcDbDatabase* TWWorkingDatabase::GetWorkingDB() const { if( m_pWorkingDatabase == NULL ) return acdbCurDwg(); return m_pWorkingDatabase; }
Acad::ErrorStatus PDEcone::explodeToSurface(AcDbVoidPtrArray& entitySet) const { assertReadEnabled(); Acad::ErrorStatus es = Acad::eOk; int i; AcGePoint3dArray pArray; AcGeIntArray stdIdx; int actPrecision; getVertices(m_dDividPrecision, pArray, stdIdx, actPrecision); int actPrecision__1 = actPrecision + 1; int actPrecision___2__1 = actPrecision * 2 + 1; AcGeVector3d faceVect = getFaceVect(); AcDbVoidPtrArray curSeg, resRegion; AcDbCircle *pCir = NULL; AcGePoint3d ucs_org = acdbCurDwg()->ucsorg(); AcGeVector3d ucs_x = acdbCurDwg()->ucsxdir(); AcGeVector3d ucs_y = acdbCurDwg()->ucsydir(); AcGeVector3d ucs_z = ucs_x.crossProduct(ucs_y); AcGeMatrix3d ucs_mat; ucs_mat.setToWorldToPlane(-faceVect); //#ifdef _OBJECTARX14_ // acdbSetCurrentUCS(ucs_mat); //#else // acedSetCurrentUCS(ucs_mat); //#endif pCir = new AcDbCircle(m_ptStart, -faceVect, m_dDiameter1 / 2.0); curSeg.append(pCir); es = AcDbRegion::createFromCurves(curSeg, resRegion); if(es != Acad::eOk) { for(i = 0; i < resRegion.length(); ++i) delete (AcRxObject*)resRegion[i]; } else { for(i = 0; i < resRegion.length(); ++i) ((AcDbEntity *)resRegion[i])->setPropertiesFrom(this); entitySet.append(resRegion); } for(i = 0; i < curSeg.length(); ++i) delete (AcRxObject*)curSeg[i]; curSeg.setLogicalLength(0); resRegion.setLogicalLength(0); ucs_mat.setToWorldToPlane(faceVect); //#ifdef _OBJECTARX14_ // acdbSetCurrentUCS(ucs_mat); //#else // acedSetCurrentUCS(ucs_mat); //#endif pCir = new AcDbCircle(m_ptEnd, faceVect, m_dDiameter2 / 2.0); curSeg.append(pCir); es = AcDbRegion::createFromCurves(curSeg, resRegion); if(es != Acad::eOk) { for(i = 0; i < resRegion.length(); ++i) delete (AcRxObject*)resRegion[i]; } else { for(i = 0; i < resRegion.length(); ++i) ((AcDbEntity *)resRegion[i])->setPropertiesFrom(this); entitySet.append(resRegion); } for(i = 0; i < curSeg.length(); ++i) delete (AcRxObject*)curSeg[i]; ucs_mat.setCoordSystem(ucs_org, ucs_x, ucs_y, ucs_z); //#ifdef _OBJECTARX14_ // acdbSetCurrentUCS(ucs_mat); //#else // acedSetCurrentUCS(ucs_mat); //#endif AcDbPolygonMesh *pMesh; pMesh = new AcDbPolygonMesh(AcDb::kSimpleMesh, 2, actPrecision + 1, pArray, Adesk::kFalse, Adesk::kFalse); pMesh->setPropertiesFrom(this); entitySet.append(pMesh); return Acad::eOk; }