This is accomplished by creating a new block definition in the current drawing and adding an entity to the block definition, inserting the entity into the current sheet, as in the following example:
CString blockname = _t ("ADF");//this defines the name of the block to be createdAcdbblocktable *Pblktab; Acdbhostapplicationservices ()-workingdatabase ()-getblocktable (Pblktab, zcdb::kforwrite); if(Pblktab->has (Blockname))//determine if the block definition already exists{AfxMessageBox (_t ("The block definition already exists! A new block definition has been created with the name:") + Blockname +M_santennasys); Blockname+=M_santennasys; } Acdbblocktablerecord*PBLKTABRCD; PBLKTABRCD=NewAcdbblocktablerecord (); PBLKTABRCD-SetName (blockname); Acdbobjectid Blockid; Pblktab-Add (Blockid, PBLKTABRCD); Pblktab-Close (); //selection of insertion pointAcgepoint3d Ptinsert; GetPoint (Ptinsert, _t ("Enter the ADF insertion point. ")); //add an entity to the block definitionAcdbblockreference *pblkref =NewAcdbblockreference (Pinsert, Idjiantou);//The previous parameter is the insertion point, and the latter is the entity IDPblkref->setrotation (DAngle);//Set Deflection angleCblockutil::setscalefactor (Pblkref, Dscale); PBLKTABRCD-appendzcdbentity (PBLKREF); Pblkref-Close (); //Insert the block into the current sheetAcdbblockreference *pblktabref =NewAcdbblockreference (Ptinsert, Blockid);//blockid the ID defined for the blockCdwgdatabaseutil::P osttomodelspace (PBLKTABREF);//This function is a generic function that inserts entities into the current model space and does not givePblktabrcd->Close (); Pblktabref->close ();
The above is done by creating a new block definition, adding entities, inserting the basic operation of the block definition, and depending on the specific requirements.
Creates a block definition and adds an entity to the specified location