This example implements the deletion of the block definition specified in the external sheet, which is present in the outer sheet of the current model space without the block reference defined by the block.
The code is as follows:
voidCblockutil::D eleteblockdefformotherdwg (ConstTchar* FileName,Consttchar*blkdefname) { //Open graphics with the _sh_denyno parameter (read-only open), allowing other users to read and write to the fileacdbdatabase* PSOURCEDWG =Newacdbdatabase (Adesk::kfalse); Acad::errorstatus es= psourcedwg->Readdwgfile (fileName); if(es! =Acad::eok) { Deletepsourcedwg; PSOURCEDWG=NULL; acutprintf (TEXT ("\ n Read DWG graphics error, graphics name:%s"), fileName); return; } //Open the Block table for the external graphics database to find the Block table records for the given nameacdbblocktable* pblktable =NULL; Es= psourcedwg->getblocktable (pblktable, acdb::kforwrite); Acdbblocktablerecord*PBLKTABRCD; CString strblkdef (blkdefname); if(pblktable->Has (strblkdef)) {pblktable-getAt (Blkdefname, PBLKTABRCD, zcdb::kforwrite); Es= pblktabrcd->Erase (); } Else{acutprintf (_t ("\ nthe block table does not exist in the current file! ")); Pblktable-Close (); Deletepsourcedwg; PSOURCEDWG=NULL; return; } pblktable-Close (); PBLKTABRCD-Close (); //Save the changed database, there must be no less this sentenceEs=psourcedwg->SaveAs (fileName); Deletepsourcedwg; PSOURCEDWG=NULL;}
In the above we use the SaveAs () to save the changed database, sometimes you can use Save () to save the changes, in this case, the use of Save () error, the specific reason is not clear, more try on later on, is one of the two.
If you want to delete the block definition in the current drawing is much simpler, we do not need to save the database changes, the code is as follows:
Acdbblocktable *Pblktab; Acdbhostapplicationservices ()-workingdatabase ()-getblocktable (Pblktab, zcdb::kforwrite); CString strblk= _t (" as"); Acdbblocktablerecord*PBLKTABRCD; if(pblktab->Has (STRBLK)) {Pblktab-getAt (strblk, PBLKTABRCD, zcdb::kforwrite); PBLKTABRCD-Erase (); } Else { return; } Pblktab-Close (); PBLKTABRCD->close ();
To delete a specified block definition in an external DWG