Delete a block with attributes

Delete a block with attributes

Anonymous
Not applicable
435 Views
6 Replies
Message 1 of 7

Delete a block with attributes

Anonymous
Not applicable
I want to delete a block containing attributes, the following couple of lines (minus all the stardard peripheral code) will delete the block... if ((blkRef = AcDbBlockReference::cast(pEnt)) != NULL) { pBlkTableRec->getBlockReferenceIds(refEnts); blkRef->erase(); blkRef->close(); } You might ask why Im getting the RefID, because I want to purge the block after erasing so I can reinsert the block from an external file. After the above code executes, the block indeed disappears from the screen, but my code to purge does not seem to work, heres how I did that... AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase(); pDb->purge(refEnts); after this, the block def remains so my subsequent insert is not as expected. Am I correct in assuming that deleting the block did NOT delete its attributes? are there now "orphan" attribute defs with no block? If this is the case, then before deleting the blockref, do I need to iterate through its attributes and delete them first? Lastly, is there an easier way of doing this??? :) Thanks Perry
0 Likes
436 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Why are you going through pDB->purge()? If you don't have any block references to a block table record then just erase the block table record. Are you trying to redefine a block so all your references are updated or are you wanting all references deleted and the block definition itself also purged? - Jorge "perry" wrote in message news:41b73484$1_1@newsprd01... >I want to delete a block containing attributes, the following couple of >lines (minus all the stardard peripheral code) will delete the block... > > if ((blkRef = AcDbBlockReference::cast(pEnt)) != NULL) > { pBlkTableRec->getBlockReferenceIds(refEnts); > blkRef->erase(); > blkRef->close(); > } > > You might ask why Im getting the RefID, because I want to purge the block > after erasing so I can reinsert the block from an external file. > After the above code executes, the block indeed disappears from the > screen, but my code to purge does not seem to work, heres how I did > that... > > AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase(); > pDb->purge(refEnts); > > after this, the block def remains so my subsequent insert is not as > expected. > Am I correct in assuming that deleting the block did NOT delete its > attributes? are there now "orphan" attribute defs with no block? > If this is the case, then before deleting the blockref, do I need to > iterate through its attributes and delete them first? > Lastly, is there an easier way of doing this??? :) > > Thanks > Perry
0 Likes
Message 3 of 7

Anonymous
Not applicable
Jorge Lopez wrote: > Why are you going through pDB->purge()? If you don't have any block > references to a block table record then just erase the block table record. > > Are you trying to redefine a block so all your references are updated or are > you wanting all references deleted and the block definition itself also > purged? > > - Jorge The later Jorge, there should be only one reference, which I want to delete, then I want to delete the block definition so that I can insert a new one without any collisions. Perry
0 Likes
Message 4 of 7

Anonymous
Not applicable
AcDbDatabase::purge() does not purge anything. All it does is determine what objects are safely purgeable. As Jorge has already pointed out, if you know that the BlockTableRecord is not referenced by anything, then open it for write and call its erase() method to erase it. "perry" wrote in message news:41b73484$1_1@newsprd01... >I want to delete a block containing attributes, the following couple of >lines (minus all the stardard peripheral code) will delete the block... > > if ((blkRef = AcDbBlockReference::cast(pEnt)) != NULL) > { pBlkTableRec->getBlockReferenceIds(refEnts); > blkRef->erase(); > blkRef->close(); > } > > You might ask why Im getting the RefID, because I want to purge the block > after erasing so I can reinsert the block from an external file. > After the above code executes, the block indeed disappears from the > screen, but my code to purge does not seem to work, heres how I did > that... > > AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase(); > pDb->purge(refEnts); > > after this, the block def remains so my subsequent insert is not as > expected. > Am I correct in assuming that deleting the block did NOT delete its > attributes? are there now "orphan" attribute defs with no block? > If this is the case, then before deleting the blockref, do I need to > iterate through its attributes and delete them first? > Lastly, is there an easier way of doing this??? :) > > Thanks > Perry
0 Likes
Message 5 of 7

Anonymous
Not applicable
Ok, I figured it out, the purge question is moot. I wasnt sure if I could do something like "pBlkTableRec->erase()" cuz erase is not a member of TableRecord per se, but if you stroll up the heirarchy chart it does eventually inherit the method from AcRxObject. So I decided what the heck, give it a try, the worst that can happen is crashing Acad or my computer bursting into flames and since I hate my computer... Low and behold, it worked, effectively "purging" the block and I didnt have to mess with the attributes either. My only question, does pBlkTableRec->close() still need to be called on erased record?? havent tried commenting out that line yet. Thanks for the input guys! Perry
0 Likes
Message 6 of 7

Anonymous
Not applicable
Yes, close still needs to be called on an erased object. If you don't, then at the very least, undo will have problems trying to open the object to undo the erase. By the way, erase() comes from AcDbObject not AcRxObject. Only objects that are database resident can be erased. "perry" wrote in message news:41b76d19$1_1@newsprd01... > Ok, I figured it out, the purge question is moot. > I wasnt sure if I could do something like "pBlkTableRec->erase()" cuz > erase is not a member of TableRecord per se, but if you stroll up the > heirarchy chart it does eventually inherit the method from AcRxObject. > So I decided what the heck, give it a try, the worst that can happen is > crashing Acad or my computer bursting into flames and since I hate my > computer... > Low and behold, it worked, effectively "purging" the block and I didnt > have to mess with the attributes either. > My only question, does pBlkTableRec->close() still need to be called on > erased record?? havent tried commenting out that line yet. > > Thanks for the input guys! > Perry
0 Likes
Message 7 of 7

Anonymous
Not applicable
Art Cooney wrote: > Yes, close still needs to be called on an erased object. If you don't, then > at the very least, undo will have problems trying to open the object to undo > the erase. > > By the way, erase() comes from AcDbObject not AcRxObject. Only objects that > are database resident can be erased. Thanks Art!
0 Likes