Inserts a block definition with attributes into the current model space

Source: Internet
Author: User

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

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.