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; }
void asdktest1 () { //----- Select the entities ads_name ss, en ; if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM ) return ; //----- Append entity IDs to the collector long n ; AcDbObjectId id ; AsdkHlrCollector collector ; collector.setDeleteState (true) ; acedSSLength (ss, &n) ; for ( int i =0 ; i < n ; i++ ) { acedSSName (ss, i, en) ; acdbGetObjectId (id, en) ; collector.addEntity (id) ; } acedSSFree (ss) ; //----- Get current viewport settings struct resbuf rb; acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb); ads_point dirPt; acdbUcs2Wcs (rb.resval.rpoint, dirPt, Adesk::kTrue) ; acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb); ads_point tarPt; acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ; //----- Ask if non-visible edges should be created int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ; int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ; int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ; int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ; //----- Process hidden line removal AsdkHlrEngine hlr ( asPnt3d (tarPt), asVec3d (dirPt), kEntity | kBlock | kSubentity | kProgress | (honorInt == IDYES ? kHonorInternals : 0) | (hidLines == IDYES ? kShowAll : 0) | (meshSils == IDYES ? kMeshSilhouettes : 0) | (unit == IDYES ? kUnite : 0) ) ; hlr.setAcisConversionProgressCallBack (progress1) ; hlr.setAhlProgressCallBack (progress2) ; hlr.setAcadConversionProgressCallBack (progress3) ; acedSetStatusBarProgressMeter (ACRX_T("HLR running: "), 0, 300) ; hlr.run (collector) ; acedRestoreStatusBar () ; //----- Assign color to the resulting entities //----- red for visible edges //----- blue for non-visible edges //----- yellow for internal edges n =collector.mOutputData.logicalLength () ; for (int i =0 ; i < n ; i++ ) { AsdkHlrData *p =collector.mOutputData [i] ; AcDbEntity *pEnt =p->getResultEntity () ; AsdkHlrData::Visibility vis =p->getVisibility () ; if ( vis == AsdkHlrData::kVisible ) { pEnt->setColorIndex (1) ; //----- Read } else if ( vis == AsdkHlrData::kInternallyHidden ) { if ( p->getHlrVisibility () == AsdkHlrData::kVisible ) pEnt->setColorIndex (2) ; //----- Yellow else pEnt->setColorIndex (3) ; //----- Green } else { pEnt->setColorIndex (5) ; //----- Blue } if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) { acutPrintf (_T("Failed to add entity to current space.\n")) ; break ; } if ( acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead) != Acad::eOk ) { acutPrintf (_T("Failed to open last added outputed curve.\n")) ; break ; } //----- Entity originator path for block reference entities AcDbObjectIdArray ids =p->getObjectIds () ; if ( ids.logicalLength () > 0 ) { acutPrintf (ACRX_T("\n%lx, "), pEnt->objectId ().asOldId ()) ; if ( p->getSubentId ().type () != AcDb::kNullSubentType ) acutPrintf (ACRX_T("[%ld, %ld], "), p->getSubentId ().type (), p->getSubentId ().index ()) ; for ( int j =0 ; j < ids.logicalLength () ; j++ ) acutPrintf (ACRX_T("%lx, "), ids.at (j).asOldId ()) ; AcDbObjectId id =ids.last () ; if ( !id.isNull () ) { AcDbEntity *ent =NULL ; acdbOpenAcDbEntity (ent, id, AcDb::kForRead) ; id =ent->linetypeId () ; ent->close () ; if ( pEnt->upgradeOpen () == Acad::eOk ) pEnt->setLinetype (id) ; } } pEnt->close () ; } }