Where Blockname is the name of the inserted block table, ptinsert the insertion point specified for the block table
void Insertblktospace (CString blockname, Acgepoint3d Ptinsert)
{
Get the block table for the current database
Acdbblocktable *pblktab;
Acdbhostapplicationservices ()->workingdatabase ()
->getblocktable (Pblktab, zcdb::kforwrite);
Determine if the inserted block definition exists
if (!pblktab->has (blockname))
{
acutprintf (_t ("\ n" \ nthe current sheet does not contain this block table!) "));
Pblktab->close ();
Return
}
Get user-specified block table records
Acdbobjectid Blkdefid;
Pblktab->getat (Blockname, Blkdefid);
Create a block Reference object
Acdbblockreference *pblkref = new Acdbblockreference (Ptinsert, Blkdefid);
Inserting a block reference into model space
Acdbblocktablerecord *PBLKTABRCD;
Pblktab->getat (Acdb_model_space, PBLKTABRCD, zcdb::kforwrite);
Pblktab->close ();
Acdbobjectid objId;
Pblktabrcd->appendzcdbentity (ObjId, pblkref);
Determines whether the specified block table record contains a property
Acdbblocktablerecord *PBLKDEFRCD;
Acdbopenobject (PBLKDEFRCD, Blkdefid, Zcdb::kforread);
if (Pblkdefrcd->hasattributedefinitions ())
{
Create a walker to traverse all the properties
Acdbblocktablerecorditerator *pitr;
Pblkdefrcd->newiterator (PITR);
Acdbentity *pent;
Traversing block definition Properties
For (Pitr->start ();!pitr->done (); Pitr->step ())
{
Pitr->getentity (pent, zcdb::kforwrite);
Check whether the attribute definition
Acdbattributedefinition *pattdef;
Pattdef = Acdbattributedefinition::cast (pent);
if (pattdef! = NULL)
{
Acdbattribute *patt = new Acdbattribute ();
Get the object characteristics of a Property object from a property definition
Patt->setpropertiesfrom (PATTDEF);
To set other characteristics of a Property object
Patt->setinvisible (Pattdef->isinvisible ());//property is not visible
Set the Property object insertion point to do the corresponding displacement action based on the insertion point of the block reference
Acgepoint3d basept = Pattdef->position ();
Basept + = Pblkref->position (). Asvector ();
Patt->setposition (basept);
Patt->setheight (Pattdef->height ());//Set high
Patt->setrotation (Pattdef->rotation ());//Set Rotation angle
Gets the tag, prompt, and teststring of the Property object
TCHAR *str;
str = Pattdef->tag ();
Patt->settag (str);
Free (str);
Patt->setfieldlength (Pattdef->fieldlength ());
str = pattdef->textstring ();
Patt->settextstring (str);
Free (str);
Append a Property object to a block reference
Pblkref->appendattribute (PATT);
Patt->close ();
}
Pent->close ();
}
Delete pItr;
}
Close the database
Pblkref->close ();
Pblkdefrcd->close ();
Pblktabrcd->close ();
}
Inserts a block definition with attributes into the current model space