To delete a specified block definition in an external DWG

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.