
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can anyone answer the following?
1. Why will this code not enter the for loop? It inserts the block, but leaves the attributes blank. Stepping through, it never enters the loop.
2. Is it necessary to add the block reference to the drawing database prior to getting the attributes? I did this in the hopes that it would solve the attribute access problem, to no avail. Not sure if there is some refresh method I am missing that will require the block to be in the drawing. Not sure why, but other examples seem to add the entities last, and I have been doing the same so far.
3. If/when I can get it to enter the for loop, is it better to get the attribute using the entity() function of the iterator as commented out, or the objectId() as I have currently?
4. Finally, is this the way to even do this? I intend to access the individual attributes of a newly inserted block and fill each of them out with passed in values.
I've stripped out as much code as I could to try and make it more to the point. I can repost if the problem does not lie in what is posted below.
Thanks for any help,
Ralph Gaston
Acad::ErrorStatus insertPointLoad( AcGePoint3d isp, int load) { Acad::ErrorStatus es = Acad::eOk; AcDbBlockTable *pBlkTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead); AcDbBlockTableRecord *pPL = NULL; pBlkTbl->getAt(_T("LOAD"), pPL, AcDb::kForRead); pBlkTbl->close(); pBlkTbl = NULL; AcDbBlockReference *pPLBlkRef = new AcDbBlockReference; pPLBlkRef->setBlockTableRecord(pPL->objectId()); pPL->close(); pPL = NULL; pPLBlkRef->setPosition(isp); AcDbObjectId PLBlkRefId = AcDbObjectId::kNull; PLBlkRefId = addToModelSpace(pPLBlkRef); //fill out the attribute values AcDbObjectIterator *pPLIter; pPLIter = pPLBlkRef->attributeIterator(); AcDbAttribute *pAtt = NULL; for(pPLIter->start(); !pPLIter->done(); pPLIter->step()) { //pAtt = (AcDbAttribute*)pPLIter->entity(); AcDbObjectId pAttId = AcDbObjectId::kNull; pAttId = pPLIter->objectId(); acdbOpenObject(pAtt, pAttId, AcDb::kForWrite); TCHAR *value = NULL; if(!_tcscmp(_T("LIVE"), pAtt->tag())) { _stprintf(value, _T("%d"), load); pAtt->setTextString(value); pAtt->close(); pAtt = NULL; pAtt = NULL; continue; } }//for delete pPLIter; pPLBlkRef->close(); pPLBlkRef = NULL; return es; }
Solved! Go to Solution.